Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 2 | * Copyright (C) 2001-2004 by David Brownell |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software Foundation, |
| 16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | */ |
| 18 | |
| 19 | /* this file is part of ehci-hcd.c */ |
| 20 | |
| 21 | /*-------------------------------------------------------------------------*/ |
| 22 | |
| 23 | /* |
| 24 | * EHCI Root Hub ... the nonsharable stuff |
| 25 | * |
| 26 | * Registers don't need cpu_to_le32, that happens transparently |
| 27 | */ |
| 28 | |
| 29 | /*-------------------------------------------------------------------------*/ |
| 30 | |
| 31 | #ifdef CONFIG_PM |
| 32 | |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 33 | static int ehci_bus_suspend (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 36 | int port; |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 37 | int mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | if (time_before (jiffies, ehci->next_statechange)) |
| 40 | msleep(5); |
| 41 | |
| 42 | port = HCS_N_PORTS (ehci->hcs_params); |
| 43 | spin_lock_irq (&ehci->lock); |
| 44 | |
| 45 | /* stop schedules, clean any completed work */ |
| 46 | if (HC_IS_RUNNING(hcd->state)) { |
| 47 | ehci_quiesce (ehci); |
| 48 | hcd->state = HC_STATE_QUIESCING; |
| 49 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 50 | ehci->command = ehci_readl(ehci, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | if (ehci->reclaim) |
Greg Kroah-Hartman | 64f8979 | 2006-10-17 13:57:18 -0700 | [diff] [blame] | 52 | ehci->reclaim_ready = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 53 | ehci_work(ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 55 | /* Unlike other USB host controller types, EHCI doesn't have |
| 56 | * any notion of "global" or bus-wide suspend. The driver has |
| 57 | * to manually suspend all the active unsuspended ports, and |
| 58 | * then manually resume them in the bus_resume() routine. |
| 59 | */ |
| 60 | ehci->bus_suspended = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | while (port--) { |
| 62 | u32 __iomem *reg = &ehci->regs->port_status [port]; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 63 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | u32 t2 = t1; |
| 65 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 66 | /* keep track of which ports we suspend */ |
| 67 | if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) && |
| 68 | !(t1 & PORT_SUSPEND)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | t2 |= PORT_SUSPEND; |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 70 | set_bit(port, &ehci->bus_suspended); |
| 71 | } |
| 72 | |
| 73 | /* enable remote wakeup on all ports */ |
David Brownell | 2c1c3c4 | 2005-11-07 15:24:46 -0800 | [diff] [blame] | 74 | if (device_may_wakeup(&hcd->self.root_hub->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | t2 |= PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E; |
| 76 | else |
| 77 | t2 &= ~(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E); |
| 78 | |
| 79 | if (t1 != t2) { |
| 80 | ehci_vdbg (ehci, "port %d, %08x -> %08x\n", |
| 81 | port + 1, t1, t2); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 82 | ehci_writel(ehci, t2, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | /* turn off now-idle HC */ |
David Brownell | 4756ae5 | 2005-05-09 17:23:51 -0700 | [diff] [blame] | 87 | del_timer_sync (&ehci->watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | ehci_halt (ehci); |
| 89 | hcd->state = HC_STATE_SUSPENDED; |
| 90 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 91 | /* allow remote wakeup */ |
| 92 | mask = INTR_MASK; |
| 93 | if (!device_may_wakeup(&hcd->self.root_hub->dev)) |
| 94 | mask &= ~STS_PCD; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 95 | ehci_writel(ehci, mask, &ehci->regs->intr_enable); |
| 96 | ehci_readl(ehci, &ehci->regs->intr_enable); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | ehci->next_statechange = jiffies + msecs_to_jiffies(10); |
| 99 | spin_unlock_irq (&ehci->lock); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /* caller has locked the root hub, and should reset/reinit on error */ |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 105 | static int ehci_bus_resume (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 108 | u32 temp; |
| 109 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | if (time_before (jiffies, ehci->next_statechange)) |
| 112 | msleep(5); |
| 113 | spin_lock_irq (&ehci->lock); |
| 114 | |
David Brownell | f03c17f | 2005-11-23 15:45:28 -0800 | [diff] [blame] | 115 | /* Ideally and we've got a real resume here, and no port's power |
| 116 | * was lost. (For PCI, that means Vaux was maintained.) But we |
| 117 | * could instead be restoring a swsusp snapshot -- so that BIOS was |
| 118 | * the last user of the controller, not reset/pm hardware keeping |
| 119 | * state we gave to it. |
| 120 | */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 121 | temp = ehci_readl(ehci, &ehci->regs->intr_enable); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 122 | ehci_dbg(ehci, "resume root hub%s\n", temp ? "" : " after power loss"); |
David Brownell | f03c17f | 2005-11-23 15:45:28 -0800 | [diff] [blame] | 123 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 124 | /* at least some APM implementations will try to deliver |
| 125 | * IRQs right away, so delay them until we're ready. |
| 126 | */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 127 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 128 | |
| 129 | /* re-init operational registers */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 130 | ehci_writel(ehci, 0, &ehci->regs->segment); |
| 131 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); |
| 132 | ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* restore CMD_RUN, framelist size, and irq threshold */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 135 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 137 | /* manually resume the ports we suspended during bus_suspend() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | i = HCS_N_PORTS (ehci->hcs_params); |
| 139 | while (i--) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 140 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 141 | temp &= ~(PORT_RWC_BITS |
| 142 | | PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 143 | if (test_bit(i, &ehci->bus_suspended) && |
| 144 | (temp & PORT_SUSPEND)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); |
| 146 | temp |= PORT_RESUME; |
| 147 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 148 | ehci_writel(ehci, temp, &ehci->regs->port_status [i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | i = HCS_N_PORTS (ehci->hcs_params); |
| 151 | mdelay (20); |
| 152 | while (i--) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 153 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 154 | if (test_bit(i, &ehci->bus_suspended) && |
| 155 | (temp & PORT_SUSPEND)) { |
| 156 | temp &= ~(PORT_RWC_BITS | PORT_RESUME); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 157 | ehci_writel(ehci, temp, &ehci->regs->port_status [i]); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 158 | ehci_vdbg (ehci, "resumed port %d\n", i + 1); |
| 159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 161 | (void) ehci_readl(ehci, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | /* maybe re-activate the schedule(s) */ |
| 164 | temp = 0; |
| 165 | if (ehci->async->qh_next.qh) |
| 166 | temp |= CMD_ASE; |
| 167 | if (ehci->periodic_sched) |
| 168 | temp |= CMD_PSE; |
| 169 | if (temp) { |
| 170 | ehci->command |= temp; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 171 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | ehci->next_statechange = jiffies + msecs_to_jiffies(5); |
| 175 | hcd->state = HC_STATE_RUNNING; |
| 176 | |
| 177 | /* Now we can safely re-enable irqs */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 178 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | spin_unlock_irq (&ehci->lock); |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | #else |
| 185 | |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 186 | #define ehci_bus_suspend NULL |
| 187 | #define ehci_bus_resume NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | #endif /* CONFIG_PM */ |
| 190 | |
| 191 | /*-------------------------------------------------------------------------*/ |
| 192 | |
| 193 | static int check_reset_complete ( |
| 194 | struct ehci_hcd *ehci, |
| 195 | int index, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 196 | u32 __iomem *status_reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | int port_status |
| 198 | ) { |
| 199 | if (!(port_status & PORT_CONNECT)) { |
| 200 | ehci->reset_done [index] = 0; |
| 201 | return port_status; |
| 202 | } |
| 203 | |
| 204 | /* if reset finished and it's still not enabled -- handoff */ |
| 205 | if (!(port_status & PORT_PE)) { |
| 206 | |
| 207 | /* with integrated TT, there's nobody to hand it to! */ |
| 208 | if (ehci_is_TDI(ehci)) { |
| 209 | ehci_dbg (ehci, |
| 210 | "Failed to enable port %d on root hub TT\n", |
| 211 | index+1); |
| 212 | return port_status; |
| 213 | } |
| 214 | |
| 215 | ehci_dbg (ehci, "port %d full speed --> companion\n", |
| 216 | index + 1); |
| 217 | |
| 218 | // what happens if HCS_N_CC(params) == 0 ? |
| 219 | port_status |= PORT_OWNER; |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 220 | port_status &= ~PORT_RWC_BITS; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 221 | ehci_writel(ehci, port_status, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | } else |
| 224 | ehci_dbg (ehci, "port %d high speed\n", index + 1); |
| 225 | |
| 226 | return port_status; |
| 227 | } |
| 228 | |
| 229 | /*-------------------------------------------------------------------------*/ |
| 230 | |
| 231 | |
| 232 | /* build "status change" packet (one or two bytes) from HC registers */ |
| 233 | |
| 234 | static int |
| 235 | ehci_hub_status_data (struct usb_hcd *hcd, char *buf) |
| 236 | { |
| 237 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 238 | u32 temp, status = 0; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 239 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | int ports, i, retval = 1; |
| 241 | unsigned long flags; |
| 242 | |
| 243 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 244 | if (!HC_IS_RUNNING(hcd->state)) |
| 245 | return 0; |
| 246 | |
| 247 | /* init status to no-changes */ |
| 248 | buf [0] = 0; |
| 249 | ports = HCS_N_PORTS (ehci->hcs_params); |
| 250 | if (ports > 7) { |
| 251 | buf [1] = 0; |
| 252 | retval++; |
| 253 | } |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 254 | |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 255 | /* Some boards (mostly VIA?) report bogus overcurrent indications, |
| 256 | * causing massive log spam unless we completely ignore them. It |
| 257 | * may be relevant that VIA VT8235 controlers, where PORT_POWER is |
| 258 | * always set, seem to clear PORT_OCC and PORT_CSC when writing to |
| 259 | * PORT_POWER; that's surprising, but maybe within-spec. |
| 260 | */ |
| 261 | if (!ignore_oc) |
| 262 | mask = PORT_CSC | PORT_PEC | PORT_OCC; |
| 263 | else |
| 264 | mask = PORT_CSC | PORT_PEC; |
| 265 | // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | /* no hub change reports (bit 0) for now (power, ...) */ |
| 268 | |
| 269 | /* port N changes (bit N)? */ |
| 270 | spin_lock_irqsave (&ehci->lock, flags); |
| 271 | for (i = 0; i < ports; i++) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 272 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame^] | 273 | |
| 274 | /* |
| 275 | * Return status information even for ports with OWNER set. |
| 276 | * Otherwise khubd wouldn't see the disconnect event when a |
| 277 | * high-speed device is switched over to the companion |
| 278 | * controller by the user. |
| 279 | */ |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (!(temp & PORT_CONNECT)) |
| 282 | ehci->reset_done [i] = 0; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 283 | if ((temp & mask) != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | || ((temp & PORT_RESUME) != 0 |
| 285 | && time_after (jiffies, |
| 286 | ehci->reset_done [i]))) { |
| 287 | if (i < 7) |
| 288 | buf [0] |= 1 << (i + 1); |
| 289 | else |
| 290 | buf [1] |= 1 << (i - 7); |
| 291 | status = STS_PCD; |
| 292 | } |
| 293 | } |
| 294 | /* FIXME autosuspend idle root hubs */ |
| 295 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 296 | return status ? retval : 0; |
| 297 | } |
| 298 | |
| 299 | /*-------------------------------------------------------------------------*/ |
| 300 | |
| 301 | static void |
| 302 | ehci_hub_descriptor ( |
| 303 | struct ehci_hcd *ehci, |
| 304 | struct usb_hub_descriptor *desc |
| 305 | ) { |
| 306 | int ports = HCS_N_PORTS (ehci->hcs_params); |
| 307 | u16 temp; |
| 308 | |
| 309 | desc->bDescriptorType = 0x29; |
| 310 | desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */ |
| 311 | desc->bHubContrCurrent = 0; |
| 312 | |
| 313 | desc->bNbrPorts = ports; |
| 314 | temp = 1 + (ports / 8); |
| 315 | desc->bDescLength = 7 + 2 * temp; |
| 316 | |
| 317 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
| 318 | memset (&desc->bitmap [0], 0, temp); |
| 319 | memset (&desc->bitmap [temp], 0xff, temp); |
| 320 | |
| 321 | temp = 0x0008; /* per-port overcurrent reporting */ |
| 322 | if (HCS_PPC (ehci->hcs_params)) |
| 323 | temp |= 0x0001; /* per-port power control */ |
David Brownell | 56c1e26 | 2005-04-09 09:00:29 -0700 | [diff] [blame] | 324 | else |
| 325 | temp |= 0x0002; /* no power switching */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | #if 0 |
| 327 | // re-enable when we support USB_PORT_FEAT_INDICATOR below. |
| 328 | if (HCS_INDICATOR (ehci->hcs_params)) |
| 329 | temp |= 0x0080; /* per-port indicators (LEDs) */ |
| 330 | #endif |
| 331 | desc->wHubCharacteristics = (__force __u16)cpu_to_le16 (temp); |
| 332 | } |
| 333 | |
| 334 | /*-------------------------------------------------------------------------*/ |
| 335 | |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 336 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | static int ehci_hub_control ( |
| 339 | struct usb_hcd *hcd, |
| 340 | u16 typeReq, |
| 341 | u16 wValue, |
| 342 | u16 wIndex, |
| 343 | char *buf, |
| 344 | u16 wLength |
| 345 | ) { |
| 346 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 347 | int ports = HCS_N_PORTS (ehci->hcs_params); |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 348 | u32 __iomem *status_reg = &ehci->regs->port_status[wIndex - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | u32 temp, status; |
| 350 | unsigned long flags; |
| 351 | int retval = 0; |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 352 | unsigned selector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. |
| 356 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. |
| 357 | * (track current state ourselves) ... blink for diagnostics, |
| 358 | * power, "this is the one", etc. EHCI spec supports this. |
| 359 | */ |
| 360 | |
| 361 | spin_lock_irqsave (&ehci->lock, flags); |
| 362 | switch (typeReq) { |
| 363 | case ClearHubFeature: |
| 364 | switch (wValue) { |
| 365 | case C_HUB_LOCAL_POWER: |
| 366 | case C_HUB_OVER_CURRENT: |
| 367 | /* no hub-wide feature/status flags */ |
| 368 | break; |
| 369 | default: |
| 370 | goto error; |
| 371 | } |
| 372 | break; |
| 373 | case ClearPortFeature: |
| 374 | if (!wIndex || wIndex > ports) |
| 375 | goto error; |
| 376 | wIndex--; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 377 | temp = ehci_readl(ehci, status_reg); |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame^] | 378 | |
| 379 | /* |
| 380 | * Even if OWNER is set, so the port is owned by the |
| 381 | * companion controller, khubd needs to be able to clear |
| 382 | * the port-change status bits (especially |
| 383 | * USB_PORT_FEAT_C_CONNECTION). |
| 384 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | switch (wValue) { |
| 387 | case USB_PORT_FEAT_ENABLE: |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 388 | ehci_writel(ehci, temp & ~PORT_PE, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | break; |
| 390 | case USB_PORT_FEAT_C_ENABLE: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 391 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 392 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | break; |
| 394 | case USB_PORT_FEAT_SUSPEND: |
| 395 | if (temp & PORT_RESET) |
| 396 | goto error; |
David Brownell | f8aeb3b | 2006-01-20 13:55:14 -0800 | [diff] [blame] | 397 | if (ehci->no_selective_suspend) |
| 398 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (temp & PORT_SUSPEND) { |
| 400 | if ((temp & PORT_PE) == 0) |
| 401 | goto error; |
| 402 | /* resume signaling for 20 msec */ |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 403 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 404 | ehci_writel(ehci, temp | PORT_RESUME, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 405 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | ehci->reset_done [wIndex] = jiffies |
| 407 | + msecs_to_jiffies (20); |
| 408 | } |
| 409 | break; |
| 410 | case USB_PORT_FEAT_C_SUSPEND: |
| 411 | /* we auto-clear this feature */ |
| 412 | break; |
| 413 | case USB_PORT_FEAT_POWER: |
| 414 | if (HCS_PPC (ehci->hcs_params)) |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 415 | ehci_writel(ehci, |
| 416 | temp & ~(PORT_RWC_BITS | PORT_POWER), |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 417 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | break; |
| 419 | case USB_PORT_FEAT_C_CONNECTION: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 420 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 421 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | break; |
| 423 | case USB_PORT_FEAT_C_OVER_CURRENT: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 424 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 425 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | break; |
| 427 | case USB_PORT_FEAT_C_RESET: |
| 428 | /* GetPortStatus clears reset */ |
| 429 | break; |
| 430 | default: |
| 431 | goto error; |
| 432 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 433 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | break; |
| 435 | case GetHubDescriptor: |
| 436 | ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *) |
| 437 | buf); |
| 438 | break; |
| 439 | case GetHubStatus: |
| 440 | /* no hub-wide feature/status flags */ |
| 441 | memset (buf, 0, 4); |
| 442 | //cpu_to_le32s ((u32 *) buf); |
| 443 | break; |
| 444 | case GetPortStatus: |
| 445 | if (!wIndex || wIndex > ports) |
| 446 | goto error; |
| 447 | wIndex--; |
| 448 | status = 0; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 449 | temp = ehci_readl(ehci, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | // wPortChange bits |
| 452 | if (temp & PORT_CSC) |
| 453 | status |= 1 << USB_PORT_FEAT_C_CONNECTION; |
| 454 | if (temp & PORT_PEC) |
| 455 | status |= 1 << USB_PORT_FEAT_C_ENABLE; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 456 | if ((temp & PORT_OCC) && !ignore_oc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; |
| 458 | |
| 459 | /* whoever resumes must GetPortStatus to complete it!! */ |
| 460 | if ((temp & PORT_RESUME) |
| 461 | && time_after (jiffies, |
| 462 | ehci->reset_done [wIndex])) { |
| 463 | status |= 1 << USB_PORT_FEAT_C_SUSPEND; |
| 464 | ehci->reset_done [wIndex] = 0; |
| 465 | |
| 466 | /* stop resume signaling */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 467 | temp = ehci_readl(ehci, status_reg); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 468 | ehci_writel(ehci, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 469 | temp & ~(PORT_RWC_BITS | PORT_RESUME), |
| 470 | status_reg); |
| 471 | retval = handshake(ehci, status_reg, |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 472 | PORT_RESUME, 0, 2000 /* 2msec */); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | if (retval != 0) { |
| 474 | ehci_err (ehci, "port %d resume error %d\n", |
| 475 | wIndex + 1, retval); |
| 476 | goto error; |
| 477 | } |
| 478 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); |
| 479 | } |
| 480 | |
| 481 | /* whoever resets must GetPortStatus to complete it!! */ |
| 482 | if ((temp & PORT_RESET) |
| 483 | && time_after (jiffies, |
| 484 | ehci->reset_done [wIndex])) { |
| 485 | status |= 1 << USB_PORT_FEAT_C_RESET; |
| 486 | ehci->reset_done [wIndex] = 0; |
| 487 | |
| 488 | /* force reset to complete */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 489 | ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET), |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 490 | status_reg); |
David Brownell | c22fa3a | 2005-06-13 07:15:28 -0700 | [diff] [blame] | 491 | /* REVISIT: some hardware needs 550+ usec to clear |
| 492 | * this bit; seems too long to spin routinely... |
| 493 | */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 494 | retval = handshake(ehci, status_reg, |
David Brownell | c22fa3a | 2005-06-13 07:15:28 -0700 | [diff] [blame] | 495 | PORT_RESET, 0, 750); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | if (retval != 0) { |
| 497 | ehci_err (ehci, "port %d reset error %d\n", |
| 498 | wIndex + 1, retval); |
| 499 | goto error; |
| 500 | } |
| 501 | |
| 502 | /* see what we found out */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 503 | temp = check_reset_complete (ehci, wIndex, status_reg, |
| 504 | ehci_readl(ehci, status_reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame^] | 507 | /* |
| 508 | * Even if OWNER is set, there's no harm letting khubd |
| 509 | * see the wPortStatus values (they should all be 0 except |
| 510 | * for PORT_POWER anyway). |
| 511 | */ |
| 512 | |
| 513 | if (temp & PORT_CONNECT) { |
| 514 | status |= 1 << USB_PORT_FEAT_CONNECTION; |
| 515 | // status may be from integrated TT |
| 516 | status |= ehci_port_speed(ehci, temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame^] | 518 | if (temp & PORT_PE) |
| 519 | status |= 1 << USB_PORT_FEAT_ENABLE; |
| 520 | if (temp & (PORT_SUSPEND|PORT_RESUME)) |
| 521 | status |= 1 << USB_PORT_FEAT_SUSPEND; |
| 522 | if (temp & PORT_OC) |
| 523 | status |= 1 << USB_PORT_FEAT_OVER_CURRENT; |
| 524 | if (temp & PORT_RESET) |
| 525 | status |= 1 << USB_PORT_FEAT_RESET; |
| 526 | if (temp & PORT_POWER) |
| 527 | status |= 1 << USB_PORT_FEAT_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | #ifndef EHCI_VERBOSE_DEBUG |
| 530 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
| 531 | #endif |
| 532 | dbg_port (ehci, "GetStatus", wIndex + 1, temp); |
| 533 | // we "know" this alignment is good, caller used kmalloc()... |
| 534 | *((__le32 *) buf) = cpu_to_le32 (status); |
| 535 | break; |
| 536 | case SetHubFeature: |
| 537 | switch (wValue) { |
| 538 | case C_HUB_LOCAL_POWER: |
| 539 | case C_HUB_OVER_CURRENT: |
| 540 | /* no hub-wide feature/status flags */ |
| 541 | break; |
| 542 | default: |
| 543 | goto error; |
| 544 | } |
| 545 | break; |
| 546 | case SetPortFeature: |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 547 | selector = wIndex >> 8; |
| 548 | wIndex &= 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (!wIndex || wIndex > ports) |
| 550 | goto error; |
| 551 | wIndex--; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 552 | temp = ehci_readl(ehci, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | if (temp & PORT_OWNER) |
| 554 | break; |
| 555 | |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 556 | temp &= ~PORT_RWC_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | switch (wValue) { |
| 558 | case USB_PORT_FEAT_SUSPEND: |
David Brownell | f8aeb3b | 2006-01-20 13:55:14 -0800 | [diff] [blame] | 559 | if (ehci->no_selective_suspend) |
| 560 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | if ((temp & PORT_PE) == 0 |
| 562 | || (temp & PORT_RESET) != 0) |
| 563 | goto error; |
David Brownell | 2c1c3c4 | 2005-11-07 15:24:46 -0800 | [diff] [blame] | 564 | if (device_may_wakeup(&hcd->self.root_hub->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | temp |= PORT_WAKE_BITS; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 566 | ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | break; |
| 568 | case USB_PORT_FEAT_POWER: |
| 569 | if (HCS_PPC (ehci->hcs_params)) |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 570 | ehci_writel(ehci, temp | PORT_POWER, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 571 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | break; |
| 573 | case USB_PORT_FEAT_RESET: |
| 574 | if (temp & PORT_RESUME) |
| 575 | goto error; |
| 576 | /* line status bits may report this as low speed, |
| 577 | * which can be fine if this root hub has a |
| 578 | * transaction translator built in. |
| 579 | */ |
| 580 | if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT |
| 581 | && !ehci_is_TDI(ehci) |
| 582 | && PORT_USB11 (temp)) { |
| 583 | ehci_dbg (ehci, |
| 584 | "port %d low speed --> companion\n", |
| 585 | wIndex + 1); |
| 586 | temp |= PORT_OWNER; |
| 587 | } else { |
| 588 | ehci_vdbg (ehci, "port %d reset\n", wIndex + 1); |
| 589 | temp |= PORT_RESET; |
| 590 | temp &= ~PORT_PE; |
| 591 | |
| 592 | /* |
| 593 | * caller must wait, then call GetPortStatus |
| 594 | * usb 2.0 spec says 50 ms resets on root |
| 595 | */ |
| 596 | ehci->reset_done [wIndex] = jiffies |
| 597 | + msecs_to_jiffies (50); |
| 598 | } |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 599 | ehci_writel(ehci, temp, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | break; |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 601 | |
| 602 | /* For downstream facing ports (these): one hub port is put |
| 603 | * into test mode according to USB2 11.24.2.13, then the hub |
| 604 | * must be reset (which for root hub now means rmmod+modprobe, |
| 605 | * or else system reboot). See EHCI 2.3.9 and 4.14 for info |
| 606 | * about the EHCI-specific stuff. |
| 607 | */ |
| 608 | case USB_PORT_FEAT_TEST: |
| 609 | if (!selector || selector > 5) |
| 610 | goto error; |
| 611 | ehci_quiesce(ehci); |
| 612 | ehci_halt(ehci); |
| 613 | temp |= selector << 16; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 614 | ehci_writel(ehci, temp, status_reg); |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 615 | break; |
| 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | default: |
| 618 | goto error; |
| 619 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 620 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | default: |
| 624 | error: |
| 625 | /* "stall" on error */ |
| 626 | retval = -EPIPE; |
| 627 | } |
| 628 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 629 | return retval; |
| 630 | } |