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