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 | |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame^] | 193 | /* Display the ports dedicated to the companion controller */ |
| 194 | static ssize_t show_companion(struct class_device *class_dev, char *buf) |
| 195 | { |
| 196 | struct ehci_hcd *ehci; |
| 197 | int nports, index, n; |
| 198 | int count = PAGE_SIZE; |
| 199 | char *ptr = buf; |
| 200 | |
| 201 | ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev))); |
| 202 | nports = HCS_N_PORTS(ehci->hcs_params); |
| 203 | |
| 204 | for (index = 0; index < nports; ++index) { |
| 205 | if (test_bit(index, &ehci->companion_ports)) { |
| 206 | n = scnprintf(ptr, count, "%d\n", index + 1); |
| 207 | ptr += n; |
| 208 | count -= n; |
| 209 | } |
| 210 | } |
| 211 | return ptr - buf; |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Dedicate or undedicate a port to the companion controller. |
| 216 | * Syntax is "[-]portnum", where a leading '-' sign means |
| 217 | * return control of the port to the EHCI controller. |
| 218 | */ |
| 219 | static ssize_t store_companion(struct class_device *class_dev, |
| 220 | const char *buf, size_t count) |
| 221 | { |
| 222 | struct ehci_hcd *ehci; |
| 223 | int portnum, new_owner, try; |
| 224 | u32 __iomem *status_reg; |
| 225 | u32 port_status; |
| 226 | |
| 227 | ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev))); |
| 228 | new_owner = PORT_OWNER; /* Owned by companion */ |
| 229 | if (sscanf(buf, "%d", &portnum) != 1) |
| 230 | return -EINVAL; |
| 231 | if (portnum < 0) { |
| 232 | portnum = - portnum; |
| 233 | new_owner = 0; /* Owned by EHCI */ |
| 234 | } |
| 235 | if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params)) |
| 236 | return -ENOENT; |
| 237 | status_reg = &ehci->regs->port_status[--portnum]; |
| 238 | if (new_owner) |
| 239 | set_bit(portnum, &ehci->companion_ports); |
| 240 | else |
| 241 | clear_bit(portnum, &ehci->companion_ports); |
| 242 | |
| 243 | /* |
| 244 | * The controller won't set the OWNER bit if the port is |
| 245 | * enabled, so this loop will sometimes require at least two |
| 246 | * iterations: one to disable the port and one to set OWNER. |
| 247 | */ |
| 248 | |
| 249 | for (try = 4; try > 0; --try) { |
| 250 | spin_lock_irq(&ehci->lock); |
| 251 | port_status = ehci_readl(ehci, status_reg); |
| 252 | if ((port_status & PORT_OWNER) == new_owner |
| 253 | || (port_status & (PORT_OWNER | PORT_CONNECT)) |
| 254 | == 0) |
| 255 | try = 0; |
| 256 | else { |
| 257 | port_status ^= PORT_OWNER; |
| 258 | port_status &= ~(PORT_PE | PORT_RWC_BITS); |
| 259 | ehci_writel(ehci, port_status, status_reg); |
| 260 | } |
| 261 | spin_unlock_irq(&ehci->lock); |
| 262 | if (try > 1) |
| 263 | msleep(5); |
| 264 | } |
| 265 | return count; |
| 266 | } |
| 267 | static CLASS_DEVICE_ATTR(companion, 0644, show_companion, store_companion); |
| 268 | |
| 269 | static inline void create_companion_file(struct ehci_hcd *ehci) |
| 270 | { |
| 271 | int i; |
| 272 | |
| 273 | /* with integrated TT there is no companion! */ |
| 274 | if (!ehci_is_TDI(ehci)) |
| 275 | i = class_device_create_file(ehci_to_hcd(ehci)->self.class_dev, |
| 276 | &class_device_attr_companion); |
| 277 | } |
| 278 | |
| 279 | static inline void remove_companion_file(struct ehci_hcd *ehci) |
| 280 | { |
| 281 | /* with integrated TT there is no companion! */ |
| 282 | if (!ehci_is_TDI(ehci)) |
| 283 | class_device_remove_file(ehci_to_hcd(ehci)->self.class_dev, |
| 284 | &class_device_attr_companion); |
| 285 | } |
| 286 | |
| 287 | |
| 288 | /*-------------------------------------------------------------------------*/ |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | static int check_reset_complete ( |
| 291 | struct ehci_hcd *ehci, |
| 292 | int index, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 293 | u32 __iomem *status_reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | int port_status |
| 295 | ) { |
| 296 | if (!(port_status & PORT_CONNECT)) { |
| 297 | ehci->reset_done [index] = 0; |
| 298 | return port_status; |
| 299 | } |
| 300 | |
| 301 | /* if reset finished and it's still not enabled -- handoff */ |
| 302 | if (!(port_status & PORT_PE)) { |
| 303 | |
| 304 | /* with integrated TT, there's nobody to hand it to! */ |
| 305 | if (ehci_is_TDI(ehci)) { |
| 306 | ehci_dbg (ehci, |
| 307 | "Failed to enable port %d on root hub TT\n", |
| 308 | index+1); |
| 309 | return port_status; |
| 310 | } |
| 311 | |
| 312 | ehci_dbg (ehci, "port %d full speed --> companion\n", |
| 313 | index + 1); |
| 314 | |
| 315 | // what happens if HCS_N_CC(params) == 0 ? |
| 316 | port_status |= PORT_OWNER; |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 317 | port_status &= ~PORT_RWC_BITS; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 318 | ehci_writel(ehci, port_status, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | } else |
| 321 | ehci_dbg (ehci, "port %d high speed\n", index + 1); |
| 322 | |
| 323 | return port_status; |
| 324 | } |
| 325 | |
| 326 | /*-------------------------------------------------------------------------*/ |
| 327 | |
| 328 | |
| 329 | /* build "status change" packet (one or two bytes) from HC registers */ |
| 330 | |
| 331 | static int |
| 332 | ehci_hub_status_data (struct usb_hcd *hcd, char *buf) |
| 333 | { |
| 334 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 335 | u32 temp, status = 0; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 336 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int ports, i, retval = 1; |
| 338 | unsigned long flags; |
| 339 | |
| 340 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 341 | if (!HC_IS_RUNNING(hcd->state)) |
| 342 | return 0; |
| 343 | |
| 344 | /* init status to no-changes */ |
| 345 | buf [0] = 0; |
| 346 | ports = HCS_N_PORTS (ehci->hcs_params); |
| 347 | if (ports > 7) { |
| 348 | buf [1] = 0; |
| 349 | retval++; |
| 350 | } |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 351 | |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 352 | /* Some boards (mostly VIA?) report bogus overcurrent indications, |
| 353 | * causing massive log spam unless we completely ignore them. It |
| 354 | * may be relevant that VIA VT8235 controlers, where PORT_POWER is |
| 355 | * always set, seem to clear PORT_OCC and PORT_CSC when writing to |
| 356 | * PORT_POWER; that's surprising, but maybe within-spec. |
| 357 | */ |
| 358 | if (!ignore_oc) |
| 359 | mask = PORT_CSC | PORT_PEC | PORT_OCC; |
| 360 | else |
| 361 | mask = PORT_CSC | PORT_PEC; |
| 362 | // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | /* no hub change reports (bit 0) for now (power, ...) */ |
| 365 | |
| 366 | /* port N changes (bit N)? */ |
| 367 | spin_lock_irqsave (&ehci->lock, flags); |
| 368 | for (i = 0; i < ports; i++) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 369 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 370 | |
| 371 | /* |
| 372 | * Return status information even for ports with OWNER set. |
| 373 | * Otherwise khubd wouldn't see the disconnect event when a |
| 374 | * high-speed device is switched over to the companion |
| 375 | * controller by the user. |
| 376 | */ |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | if (!(temp & PORT_CONNECT)) |
| 379 | ehci->reset_done [i] = 0; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 380 | if ((temp & mask) != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | || ((temp & PORT_RESUME) != 0 |
| 382 | && time_after (jiffies, |
| 383 | ehci->reset_done [i]))) { |
| 384 | if (i < 7) |
| 385 | buf [0] |= 1 << (i + 1); |
| 386 | else |
| 387 | buf [1] |= 1 << (i - 7); |
| 388 | status = STS_PCD; |
| 389 | } |
| 390 | } |
| 391 | /* FIXME autosuspend idle root hubs */ |
| 392 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 393 | return status ? retval : 0; |
| 394 | } |
| 395 | |
| 396 | /*-------------------------------------------------------------------------*/ |
| 397 | |
| 398 | static void |
| 399 | ehci_hub_descriptor ( |
| 400 | struct ehci_hcd *ehci, |
| 401 | struct usb_hub_descriptor *desc |
| 402 | ) { |
| 403 | int ports = HCS_N_PORTS (ehci->hcs_params); |
| 404 | u16 temp; |
| 405 | |
| 406 | desc->bDescriptorType = 0x29; |
| 407 | desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */ |
| 408 | desc->bHubContrCurrent = 0; |
| 409 | |
| 410 | desc->bNbrPorts = ports; |
| 411 | temp = 1 + (ports / 8); |
| 412 | desc->bDescLength = 7 + 2 * temp; |
| 413 | |
| 414 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
| 415 | memset (&desc->bitmap [0], 0, temp); |
| 416 | memset (&desc->bitmap [temp], 0xff, temp); |
| 417 | |
| 418 | temp = 0x0008; /* per-port overcurrent reporting */ |
| 419 | if (HCS_PPC (ehci->hcs_params)) |
| 420 | temp |= 0x0001; /* per-port power control */ |
David Brownell | 56c1e26 | 2005-04-09 09:00:29 -0700 | [diff] [blame] | 421 | else |
| 422 | temp |= 0x0002; /* no power switching */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | #if 0 |
| 424 | // re-enable when we support USB_PORT_FEAT_INDICATOR below. |
| 425 | if (HCS_INDICATOR (ehci->hcs_params)) |
| 426 | temp |= 0x0080; /* per-port indicators (LEDs) */ |
| 427 | #endif |
| 428 | desc->wHubCharacteristics = (__force __u16)cpu_to_le16 (temp); |
| 429 | } |
| 430 | |
| 431 | /*-------------------------------------------------------------------------*/ |
| 432 | |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 433 | #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] | 434 | |
| 435 | static int ehci_hub_control ( |
| 436 | struct usb_hcd *hcd, |
| 437 | u16 typeReq, |
| 438 | u16 wValue, |
| 439 | u16 wIndex, |
| 440 | char *buf, |
| 441 | u16 wLength |
| 442 | ) { |
| 443 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 444 | int ports = HCS_N_PORTS (ehci->hcs_params); |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 445 | u32 __iomem *status_reg = &ehci->regs->port_status[wIndex - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | u32 temp, status; |
| 447 | unsigned long flags; |
| 448 | int retval = 0; |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 449 | unsigned selector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | /* |
| 452 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. |
| 453 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. |
| 454 | * (track current state ourselves) ... blink for diagnostics, |
| 455 | * power, "this is the one", etc. EHCI spec supports this. |
| 456 | */ |
| 457 | |
| 458 | spin_lock_irqsave (&ehci->lock, flags); |
| 459 | switch (typeReq) { |
| 460 | case ClearHubFeature: |
| 461 | switch (wValue) { |
| 462 | case C_HUB_LOCAL_POWER: |
| 463 | case C_HUB_OVER_CURRENT: |
| 464 | /* no hub-wide feature/status flags */ |
| 465 | break; |
| 466 | default: |
| 467 | goto error; |
| 468 | } |
| 469 | break; |
| 470 | case ClearPortFeature: |
| 471 | if (!wIndex || wIndex > ports) |
| 472 | goto error; |
| 473 | wIndex--; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 474 | temp = ehci_readl(ehci, status_reg); |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 475 | |
| 476 | /* |
| 477 | * Even if OWNER is set, so the port is owned by the |
| 478 | * companion controller, khubd needs to be able to clear |
| 479 | * the port-change status bits (especially |
| 480 | * USB_PORT_FEAT_C_CONNECTION). |
| 481 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | switch (wValue) { |
| 484 | case USB_PORT_FEAT_ENABLE: |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 485 | ehci_writel(ehci, temp & ~PORT_PE, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | break; |
| 487 | case USB_PORT_FEAT_C_ENABLE: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 488 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 489 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | break; |
| 491 | case USB_PORT_FEAT_SUSPEND: |
| 492 | if (temp & PORT_RESET) |
| 493 | goto error; |
David Brownell | f8aeb3b | 2006-01-20 13:55:14 -0800 | [diff] [blame] | 494 | if (ehci->no_selective_suspend) |
| 495 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | if (temp & PORT_SUSPEND) { |
| 497 | if ((temp & PORT_PE) == 0) |
| 498 | goto error; |
| 499 | /* resume signaling for 20 msec */ |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 500 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 501 | ehci_writel(ehci, temp | PORT_RESUME, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 502 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | ehci->reset_done [wIndex] = jiffies |
| 504 | + msecs_to_jiffies (20); |
| 505 | } |
| 506 | break; |
| 507 | case USB_PORT_FEAT_C_SUSPEND: |
| 508 | /* we auto-clear this feature */ |
| 509 | break; |
| 510 | case USB_PORT_FEAT_POWER: |
| 511 | if (HCS_PPC (ehci->hcs_params)) |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 512 | ehci_writel(ehci, |
| 513 | temp & ~(PORT_RWC_BITS | PORT_POWER), |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 514 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | break; |
| 516 | case USB_PORT_FEAT_C_CONNECTION: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 517 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 518 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | break; |
| 520 | case USB_PORT_FEAT_C_OVER_CURRENT: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 521 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 522 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | break; |
| 524 | case USB_PORT_FEAT_C_RESET: |
| 525 | /* GetPortStatus clears reset */ |
| 526 | break; |
| 527 | default: |
| 528 | goto error; |
| 529 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 530 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | break; |
| 532 | case GetHubDescriptor: |
| 533 | ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *) |
| 534 | buf); |
| 535 | break; |
| 536 | case GetHubStatus: |
| 537 | /* no hub-wide feature/status flags */ |
| 538 | memset (buf, 0, 4); |
| 539 | //cpu_to_le32s ((u32 *) buf); |
| 540 | break; |
| 541 | case GetPortStatus: |
| 542 | if (!wIndex || wIndex > ports) |
| 543 | goto error; |
| 544 | wIndex--; |
| 545 | status = 0; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 546 | temp = ehci_readl(ehci, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | // wPortChange bits |
| 549 | if (temp & PORT_CSC) |
| 550 | status |= 1 << USB_PORT_FEAT_C_CONNECTION; |
| 551 | if (temp & PORT_PEC) |
| 552 | status |= 1 << USB_PORT_FEAT_C_ENABLE; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 553 | if ((temp & PORT_OCC) && !ignore_oc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; |
| 555 | |
| 556 | /* whoever resumes must GetPortStatus to complete it!! */ |
| 557 | if ((temp & PORT_RESUME) |
| 558 | && time_after (jiffies, |
| 559 | ehci->reset_done [wIndex])) { |
| 560 | status |= 1 << USB_PORT_FEAT_C_SUSPEND; |
| 561 | ehci->reset_done [wIndex] = 0; |
| 562 | |
| 563 | /* stop resume signaling */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 564 | temp = ehci_readl(ehci, status_reg); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 565 | ehci_writel(ehci, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 566 | temp & ~(PORT_RWC_BITS | PORT_RESUME), |
| 567 | status_reg); |
| 568 | retval = handshake(ehci, status_reg, |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 569 | PORT_RESUME, 0, 2000 /* 2msec */); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | if (retval != 0) { |
| 571 | ehci_err (ehci, "port %d resume error %d\n", |
| 572 | wIndex + 1, retval); |
| 573 | goto error; |
| 574 | } |
| 575 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); |
| 576 | } |
| 577 | |
| 578 | /* whoever resets must GetPortStatus to complete it!! */ |
| 579 | if ((temp & PORT_RESET) |
| 580 | && time_after (jiffies, |
| 581 | ehci->reset_done [wIndex])) { |
| 582 | status |= 1 << USB_PORT_FEAT_C_RESET; |
| 583 | ehci->reset_done [wIndex] = 0; |
| 584 | |
| 585 | /* force reset to complete */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 586 | ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET), |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 587 | status_reg); |
David Brownell | c22fa3a | 2005-06-13 07:15:28 -0700 | [diff] [blame] | 588 | /* REVISIT: some hardware needs 550+ usec to clear |
| 589 | * this bit; seems too long to spin routinely... |
| 590 | */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 591 | retval = handshake(ehci, status_reg, |
David Brownell | c22fa3a | 2005-06-13 07:15:28 -0700 | [diff] [blame] | 592 | PORT_RESET, 0, 750); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (retval != 0) { |
| 594 | ehci_err (ehci, "port %d reset error %d\n", |
| 595 | wIndex + 1, retval); |
| 596 | goto error; |
| 597 | } |
| 598 | |
| 599 | /* see what we found out */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 600 | temp = check_reset_complete (ehci, wIndex, status_reg, |
| 601 | ehci_readl(ehci, status_reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame^] | 604 | /* transfer dedicated ports to the companion hc */ |
| 605 | if ((temp & PORT_CONNECT) && |
| 606 | test_bit(wIndex, &ehci->companion_ports)) { |
| 607 | temp &= ~PORT_RWC_BITS; |
| 608 | temp |= PORT_OWNER; |
| 609 | ehci_writel(ehci, temp, status_reg); |
| 610 | ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1); |
| 611 | temp = ehci_readl(ehci, status_reg); |
| 612 | } |
| 613 | |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 614 | /* |
| 615 | * Even if OWNER is set, there's no harm letting khubd |
| 616 | * see the wPortStatus values (they should all be 0 except |
| 617 | * for PORT_POWER anyway). |
| 618 | */ |
| 619 | |
| 620 | if (temp & PORT_CONNECT) { |
| 621 | status |= 1 << USB_PORT_FEAT_CONNECTION; |
| 622 | // status may be from integrated TT |
| 623 | status |= ehci_port_speed(ehci, temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 625 | if (temp & PORT_PE) |
| 626 | status |= 1 << USB_PORT_FEAT_ENABLE; |
| 627 | if (temp & (PORT_SUSPEND|PORT_RESUME)) |
| 628 | status |= 1 << USB_PORT_FEAT_SUSPEND; |
| 629 | if (temp & PORT_OC) |
| 630 | status |= 1 << USB_PORT_FEAT_OVER_CURRENT; |
| 631 | if (temp & PORT_RESET) |
| 632 | status |= 1 << USB_PORT_FEAT_RESET; |
| 633 | if (temp & PORT_POWER) |
| 634 | status |= 1 << USB_PORT_FEAT_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | #ifndef EHCI_VERBOSE_DEBUG |
| 637 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
| 638 | #endif |
| 639 | dbg_port (ehci, "GetStatus", wIndex + 1, temp); |
| 640 | // we "know" this alignment is good, caller used kmalloc()... |
| 641 | *((__le32 *) buf) = cpu_to_le32 (status); |
| 642 | break; |
| 643 | case SetHubFeature: |
| 644 | switch (wValue) { |
| 645 | case C_HUB_LOCAL_POWER: |
| 646 | case C_HUB_OVER_CURRENT: |
| 647 | /* no hub-wide feature/status flags */ |
| 648 | break; |
| 649 | default: |
| 650 | goto error; |
| 651 | } |
| 652 | break; |
| 653 | case SetPortFeature: |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 654 | selector = wIndex >> 8; |
| 655 | wIndex &= 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | if (!wIndex || wIndex > ports) |
| 657 | goto error; |
| 658 | wIndex--; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 659 | temp = ehci_readl(ehci, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | if (temp & PORT_OWNER) |
| 661 | break; |
| 662 | |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 663 | temp &= ~PORT_RWC_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | switch (wValue) { |
| 665 | case USB_PORT_FEAT_SUSPEND: |
David Brownell | f8aeb3b | 2006-01-20 13:55:14 -0800 | [diff] [blame] | 666 | if (ehci->no_selective_suspend) |
| 667 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | if ((temp & PORT_PE) == 0 |
| 669 | || (temp & PORT_RESET) != 0) |
| 670 | goto error; |
David Brownell | 2c1c3c4 | 2005-11-07 15:24:46 -0800 | [diff] [blame] | 671 | if (device_may_wakeup(&hcd->self.root_hub->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | temp |= PORT_WAKE_BITS; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 673 | ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | break; |
| 675 | case USB_PORT_FEAT_POWER: |
| 676 | if (HCS_PPC (ehci->hcs_params)) |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 677 | ehci_writel(ehci, temp | PORT_POWER, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 678 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | break; |
| 680 | case USB_PORT_FEAT_RESET: |
| 681 | if (temp & PORT_RESUME) |
| 682 | goto error; |
| 683 | /* line status bits may report this as low speed, |
| 684 | * which can be fine if this root hub has a |
| 685 | * transaction translator built in. |
| 686 | */ |
| 687 | if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT |
| 688 | && !ehci_is_TDI(ehci) |
| 689 | && PORT_USB11 (temp)) { |
| 690 | ehci_dbg (ehci, |
| 691 | "port %d low speed --> companion\n", |
| 692 | wIndex + 1); |
| 693 | temp |= PORT_OWNER; |
| 694 | } else { |
| 695 | ehci_vdbg (ehci, "port %d reset\n", wIndex + 1); |
| 696 | temp |= PORT_RESET; |
| 697 | temp &= ~PORT_PE; |
| 698 | |
| 699 | /* |
| 700 | * caller must wait, then call GetPortStatus |
| 701 | * usb 2.0 spec says 50 ms resets on root |
| 702 | */ |
| 703 | ehci->reset_done [wIndex] = jiffies |
| 704 | + msecs_to_jiffies (50); |
| 705 | } |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 706 | ehci_writel(ehci, temp, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | break; |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 708 | |
| 709 | /* For downstream facing ports (these): one hub port is put |
| 710 | * into test mode according to USB2 11.24.2.13, then the hub |
| 711 | * must be reset (which for root hub now means rmmod+modprobe, |
| 712 | * or else system reboot). See EHCI 2.3.9 and 4.14 for info |
| 713 | * about the EHCI-specific stuff. |
| 714 | */ |
| 715 | case USB_PORT_FEAT_TEST: |
| 716 | if (!selector || selector > 5) |
| 717 | goto error; |
| 718 | ehci_quiesce(ehci); |
| 719 | ehci_halt(ehci); |
| 720 | temp |= selector << 16; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 721 | ehci_writel(ehci, temp, status_reg); |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 722 | break; |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | default: |
| 725 | goto error; |
| 726 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 727 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | default: |
| 731 | error: |
| 732 | /* "stall" on error */ |
| 733 | retval = -EPIPE; |
| 734 | } |
| 735 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 736 | return retval; |
| 737 | } |