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