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