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 | 58a97ff | 2008-04-14 12:17:10 -0400 | [diff] [blame] | 31 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
| 32 | |
Alan Stern | aff6d18 | 2008-04-18 11:11:26 -0400 | [diff] [blame] | 33 | #ifdef CONFIG_PM |
| 34 | |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 35 | static int ehci_hub_control( |
| 36 | struct usb_hcd *hcd, |
| 37 | u16 typeReq, |
| 38 | u16 wValue, |
| 39 | u16 wIndex, |
| 40 | char *buf, |
| 41 | u16 wLength |
| 42 | ); |
| 43 | |
| 44 | /* After a power loss, ports that were owned by the companion must be |
| 45 | * reset so that the companion can still own them. |
| 46 | */ |
| 47 | static void ehci_handover_companion_ports(struct ehci_hcd *ehci) |
| 48 | { |
| 49 | u32 __iomem *reg; |
| 50 | u32 status; |
| 51 | int port; |
| 52 | __le32 buf; |
| 53 | struct usb_hcd *hcd = ehci_to_hcd(ehci); |
| 54 | |
| 55 | if (!ehci->owned_ports) |
| 56 | return; |
| 57 | |
| 58 | /* Give the connections some time to appear */ |
| 59 | msleep(20); |
| 60 | |
| 61 | port = HCS_N_PORTS(ehci->hcs_params); |
| 62 | while (port--) { |
| 63 | if (test_bit(port, &ehci->owned_ports)) { |
| 64 | reg = &ehci->regs->port_status[port]; |
Alan Stern | 3c519b8 | 2007-05-04 11:55:31 -0400 | [diff] [blame] | 65 | status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 66 | |
| 67 | /* Port already owned by companion? */ |
| 68 | if (status & PORT_OWNER) |
| 69 | clear_bit(port, &ehci->owned_ports); |
Alan Stern | 3c519b8 | 2007-05-04 11:55:31 -0400 | [diff] [blame] | 70 | else if (test_bit(port, &ehci->companion_ports)) |
| 71 | ehci_writel(ehci, status & ~PORT_PE, reg); |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 72 | else |
| 73 | ehci_hub_control(hcd, SetPortFeature, |
| 74 | USB_PORT_FEAT_RESET, port + 1, |
| 75 | NULL, 0); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (!ehci->owned_ports) |
| 80 | return; |
| 81 | msleep(90); /* Wait for resets to complete */ |
| 82 | |
| 83 | port = HCS_N_PORTS(ehci->hcs_params); |
| 84 | while (port--) { |
| 85 | if (test_bit(port, &ehci->owned_ports)) { |
| 86 | ehci_hub_control(hcd, GetPortStatus, |
| 87 | 0, port + 1, |
| 88 | (char *) &buf, sizeof(buf)); |
| 89 | |
| 90 | /* The companion should now own the port, |
| 91 | * but if something went wrong the port must not |
| 92 | * remain enabled. |
| 93 | */ |
| 94 | reg = &ehci->regs->port_status[port]; |
| 95 | status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
| 96 | if (status & PORT_OWNER) |
| 97 | ehci_writel(ehci, status | PORT_CSC, reg); |
| 98 | else { |
| 99 | ehci_dbg(ehci, "failed handover port %d: %x\n", |
| 100 | port + 1, status); |
| 101 | ehci_writel(ehci, status & ~PORT_PE, reg); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | ehci->owned_ports = 0; |
| 107 | } |
| 108 | |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 109 | static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, |
Alan Stern | 4147200 | 2010-06-25 14:02:14 -0400 | [diff] [blame^] | 110 | bool suspending, bool do_wakeup) |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 111 | { |
| 112 | int port; |
| 113 | u32 temp; |
| 114 | |
| 115 | /* If remote wakeup is enabled for the root hub but disabled |
| 116 | * for the controller, we must adjust all the port wakeup flags |
| 117 | * when the controller is suspended or resumed. In all other |
| 118 | * cases they don't need to be changed. |
| 119 | */ |
Alan Stern | 4147200 | 2010-06-25 14:02:14 -0400 | [diff] [blame^] | 120 | if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup) |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 121 | return; |
| 122 | |
| 123 | /* clear phy low-power mode before changing wakeup flags */ |
| 124 | if (ehci->has_hostpc) { |
| 125 | port = HCS_N_PORTS(ehci->hcs_params); |
| 126 | while (port--) { |
| 127 | u32 __iomem *hostpc_reg; |
| 128 | |
| 129 | hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs |
| 130 | + HOSTPC0 + 4 * port); |
| 131 | temp = ehci_readl(ehci, hostpc_reg); |
| 132 | ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg); |
| 133 | } |
| 134 | msleep(5); |
| 135 | } |
| 136 | |
| 137 | port = HCS_N_PORTS(ehci->hcs_params); |
| 138 | while (port--) { |
| 139 | u32 __iomem *reg = &ehci->regs->port_status[port]; |
| 140 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
| 141 | u32 t2 = t1 & ~PORT_WAKE_BITS; |
| 142 | |
| 143 | /* If we are suspending the controller, clear the flags. |
| 144 | * If we are resuming the controller, set the wakeup flags. |
| 145 | */ |
| 146 | if (!suspending) { |
| 147 | if (t1 & PORT_CONNECT) |
| 148 | t2 |= PORT_WKOC_E | PORT_WKDISC_E; |
| 149 | else |
| 150 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; |
| 151 | } |
| 152 | ehci_vdbg(ehci, "port %d, %08x -> %08x\n", |
| 153 | port + 1, t1, t2); |
| 154 | ehci_writel(ehci, t2, reg); |
| 155 | } |
| 156 | |
| 157 | /* enter phy low-power mode again */ |
| 158 | if (ehci->has_hostpc) { |
| 159 | port = HCS_N_PORTS(ehci->hcs_params); |
| 160 | while (port--) { |
| 161 | u32 __iomem *hostpc_reg; |
| 162 | |
| 163 | hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs |
| 164 | + HOSTPC0 + 4 * port); |
| 165 | temp = ehci_readl(ehci, hostpc_reg); |
| 166 | ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 171 | static int ehci_bus_suspend (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 174 | int port; |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 175 | int mask; |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 176 | int changed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Alan Stern | 8c774fe | 2007-02-01 16:09:59 -0500 | [diff] [blame] | 178 | ehci_dbg(ehci, "suspend root hub\n"); |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | if (time_before (jiffies, ehci->next_statechange)) |
| 181 | msleep(5); |
Alan Stern | f8fa757 | 2008-01-10 16:43:15 -0500 | [diff] [blame] | 182 | del_timer_sync(&ehci->watchdog); |
| 183 | del_timer_sync(&ehci->iaa_watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | spin_lock_irq (&ehci->lock); |
| 186 | |
Alan Stern | cec3a53 | 2010-01-08 11:18:20 -0500 | [diff] [blame] | 187 | /* Once the controller is stopped, port resumes that are already |
| 188 | * in progress won't complete. Hence if remote wakeup is enabled |
| 189 | * for the root hub and any ports are in the middle of a resume or |
| 190 | * remote wakeup, we must fail the suspend. |
| 191 | */ |
| 192 | if (hcd->self.root_hub->do_remote_wakeup) { |
| 193 | port = HCS_N_PORTS(ehci->hcs_params); |
| 194 | while (port--) { |
| 195 | if (ehci->reset_done[port] != 0) { |
| 196 | spin_unlock_irq(&ehci->lock); |
| 197 | ehci_dbg(ehci, "suspend failed because " |
| 198 | "port %d is resuming\n", |
| 199 | port + 1); |
| 200 | return -EBUSY; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* stop schedules, clean any completed work */ |
| 206 | if (HC_IS_RUNNING(hcd->state)) { |
| 207 | ehci_quiesce (ehci); |
| 208 | hcd->state = HC_STATE_QUIESCING; |
| 209 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 210 | ehci->command = ehci_readl(ehci, &ehci->regs->command); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 211 | ehci_work(ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 213 | /* Unlike other USB host controller types, EHCI doesn't have |
| 214 | * any notion of "global" or bus-wide suspend. The driver has |
| 215 | * to manually suspend all the active unsuspended ports, and |
| 216 | * then manually resume them in the bus_resume() routine. |
| 217 | */ |
| 218 | ehci->bus_suspended = 0; |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 219 | ehci->owned_ports = 0; |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 220 | changed = 0; |
Alan Stern | cec3a53 | 2010-01-08 11:18:20 -0500 | [diff] [blame] | 221 | port = HCS_N_PORTS(ehci->hcs_params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | while (port--) { |
| 223 | u32 __iomem *reg = &ehci->regs->port_status [port]; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 224 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 225 | u32 t2 = t1 & ~PORT_WAKE_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 227 | /* keep track of which ports we suspend */ |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 228 | if (t1 & PORT_OWNER) |
| 229 | set_bit(port, &ehci->owned_ports); |
| 230 | else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | t2 |= PORT_SUSPEND; |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 232 | set_bit(port, &ehci->bus_suspended); |
| 233 | } |
| 234 | |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 235 | /* enable remote wakeup on all ports, if told to do so */ |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 236 | if (hcd->self.root_hub->do_remote_wakeup) { |
| 237 | /* only enable appropriate wake bits, otherwise the |
| 238 | * hardware can not go phy low power mode. If a race |
| 239 | * condition happens here(connection change during bits |
| 240 | * set), the port change detection will finally fix it. |
| 241 | */ |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 242 | if (t1 & PORT_CONNECT) |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 243 | t2 |= PORT_WKOC_E | PORT_WKDISC_E; |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 244 | else |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 245 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | if (t1 != t2) { |
| 249 | ehci_vdbg (ehci, "port %d, %08x -> %08x\n", |
| 250 | port + 1, t1, t2); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 251 | ehci_writel(ehci, t2, reg); |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 252 | changed = 1; |
| 253 | } |
| 254 | } |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 255 | |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 256 | if (changed && ehci->has_hostpc) { |
| 257 | spin_unlock_irq(&ehci->lock); |
| 258 | msleep(5); /* 5 ms for HCD to enter low-power mode */ |
| 259 | spin_lock_irq(&ehci->lock); |
| 260 | |
| 261 | port = HCS_N_PORTS(ehci->hcs_params); |
| 262 | while (port--) { |
| 263 | u32 __iomem *hostpc_reg; |
| 264 | u32 t3; |
| 265 | |
| 266 | hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs |
| 267 | + HOSTPC0 + 4 * port); |
| 268 | t3 = ehci_readl(ehci, hostpc_reg); |
| 269 | ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); |
| 270 | t3 = ehci_readl(ehci, hostpc_reg); |
| 271 | ehci_dbg(ehci, "Port %d phy low-power mode %s\n", |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 272 | port, (t3 & HOSTPC_PHCD) ? |
| 273 | "succeeded" : "failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Alan Stern | cd930c9 | 2008-01-10 11:14:53 -0500 | [diff] [blame] | 277 | /* Apparently some devices need a >= 1-uframe delay here */ |
| 278 | if (ehci->bus_suspended) |
| 279 | udelay(150); |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* turn off now-idle HC */ |
| 282 | ehci_halt (ehci); |
| 283 | hcd->state = HC_STATE_SUSPENDED; |
| 284 | |
David Brownell | cdc647a | 2008-04-02 13:40:20 -0700 | [diff] [blame] | 285 | if (ehci->reclaim) |
| 286 | end_unlink_async(ehci); |
| 287 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 288 | /* allow remote wakeup */ |
| 289 | mask = INTR_MASK; |
Alan Stern | 58a97ff | 2008-04-14 12:17:10 -0400 | [diff] [blame] | 290 | if (!hcd->self.root_hub->do_remote_wakeup) |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 291 | mask &= ~STS_PCD; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 292 | ehci_writel(ehci, mask, &ehci->regs->intr_enable); |
| 293 | ehci_readl(ehci, &ehci->regs->intr_enable); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | ehci->next_statechange = jiffies + msecs_to_jiffies(10); |
| 296 | spin_unlock_irq (&ehci->lock); |
Jon Hunter | 015798b | 2009-08-12 11:57:59 -0400 | [diff] [blame] | 297 | |
| 298 | /* ehci_work() may have re-enabled the watchdog timer, which we do not |
| 299 | * want, and so we must delete any pending watchdog timer events. |
| 300 | */ |
| 301 | del_timer_sync(&ehci->watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | /* caller has locked the root hub, and should reset/reinit on error */ |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 307 | static int ehci_bus_resume (struct usb_hcd *hcd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 310 | u32 temp; |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 311 | u32 power_okay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | int i; |
Vikram Pandita | 3a4e72c | 2008-10-24 23:41:30 +0530 | [diff] [blame] | 313 | u8 resume_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | if (time_before (jiffies, ehci->next_statechange)) |
| 316 | msleep(5); |
| 317 | spin_lock_irq (&ehci->lock); |
Alan Stern | 541c7d4 | 2010-06-22 16:39:10 -0400 | [diff] [blame] | 318 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
Alan Stern | cfa59da | 2007-06-21 16:25:35 -0400 | [diff] [blame] | 319 | spin_unlock_irq(&ehci->lock); |
| 320 | return -ESHUTDOWN; |
| 321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Jason Wessel | ad45f1d | 2009-08-20 15:39:58 -0500 | [diff] [blame] | 323 | if (unlikely(ehci->debug)) { |
Jason Wessel | 872d359 | 2009-09-23 18:32:44 -0500 | [diff] [blame] | 324 | if (!dbgp_reset_prep()) |
Jason Wessel | ad45f1d | 2009-08-20 15:39:58 -0500 | [diff] [blame] | 325 | ehci->debug = NULL; |
| 326 | else |
| 327 | dbgp_external_startup(); |
| 328 | } |
| 329 | |
David Brownell | f03c17f | 2005-11-23 15:45:28 -0800 | [diff] [blame] | 330 | /* Ideally and we've got a real resume here, and no port's power |
| 331 | * was lost. (For PCI, that means Vaux was maintained.) But we |
| 332 | * could instead be restoring a swsusp snapshot -- so that BIOS was |
| 333 | * the last user of the controller, not reset/pm hardware keeping |
| 334 | * state we gave to it. |
| 335 | */ |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 336 | power_okay = ehci_readl(ehci, &ehci->regs->intr_enable); |
| 337 | ehci_dbg(ehci, "resume root hub%s\n", |
| 338 | power_okay ? "" : " after power loss"); |
David Brownell | f03c17f | 2005-11-23 15:45:28 -0800 | [diff] [blame] | 339 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 340 | /* at least some APM implementations will try to deliver |
| 341 | * IRQs right away, so delay them until we're ready. |
| 342 | */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 343 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 344 | |
| 345 | /* re-init operational registers */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 346 | ehci_writel(ehci, 0, &ehci->regs->segment); |
| 347 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); |
| 348 | ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | /* restore CMD_RUN, framelist size, and irq threshold */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 351 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Alan Stern | e198a31 | 2007-03-15 15:54:30 -0400 | [diff] [blame] | 353 | /* Some controller/firmware combinations need a delay during which |
| 354 | * they set up the port statuses. See Bugzilla #8190. */ |
Vikram Pandita | 3a4e72c | 2008-10-24 23:41:30 +0530 | [diff] [blame] | 355 | spin_unlock_irq(&ehci->lock); |
| 356 | msleep(8); |
| 357 | spin_lock_irq(&ehci->lock); |
Alan Stern | e198a31 | 2007-03-15 15:54:30 -0400 | [diff] [blame] | 358 | |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 359 | /* clear phy low-power mode before resume */ |
| 360 | if (ehci->bus_suspended && ehci->has_hostpc) { |
| 361 | i = HCS_N_PORTS(ehci->hcs_params); |
| 362 | while (i--) { |
| 363 | if (test_bit(i, &ehci->bus_suspended)) { |
| 364 | u32 __iomem *hostpc_reg; |
| 365 | |
| 366 | hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs |
| 367 | + HOSTPC0 + 4 * i); |
| 368 | temp = ehci_readl(ehci, hostpc_reg); |
| 369 | ehci_writel(ehci, temp & ~HOSTPC_PHCD, |
| 370 | hostpc_reg); |
| 371 | } |
| 372 | } |
| 373 | spin_unlock_irq(&ehci->lock); |
| 374 | msleep(5); |
| 375 | spin_lock_irq(&ehci->lock); |
| 376 | } |
| 377 | |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 378 | /* manually resume the ports we suspended during bus_suspend() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | i = HCS_N_PORTS (ehci->hcs_params); |
| 380 | while (i--) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 381 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
Alan Stern | 58a97ff | 2008-04-14 12:17:10 -0400 | [diff] [blame] | 382 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 383 | if (test_bit(i, &ehci->bus_suspended) && |
Vikram Pandita | 3a4e72c | 2008-10-24 23:41:30 +0530 | [diff] [blame] | 384 | (temp & PORT_SUSPEND)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | temp |= PORT_RESUME; |
Vikram Pandita | 3a4e72c | 2008-10-24 23:41:30 +0530 | [diff] [blame] | 386 | resume_needed = 1; |
| 387 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 388 | ehci_writel(ehci, temp, &ehci->regs->port_status [i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
Vikram Pandita | 3a4e72c | 2008-10-24 23:41:30 +0530 | [diff] [blame] | 390 | |
| 391 | /* msleep for 20ms only if code is trying to resume port */ |
| 392 | if (resume_needed) { |
| 393 | spin_unlock_irq(&ehci->lock); |
| 394 | msleep(20); |
| 395 | spin_lock_irq(&ehci->lock); |
| 396 | } |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | i = HCS_N_PORTS (ehci->hcs_params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | while (i--) { |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 400 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 401 | if (test_bit(i, &ehci->bus_suspended) && |
| 402 | (temp & PORT_SUSPEND)) { |
| 403 | temp &= ~(PORT_RWC_BITS | PORT_RESUME); |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 404 | ehci_writel(ehci, temp, &ehci->regs->port_status [i]); |
Alan Stern | 8c03356 | 2006-11-09 14:42:16 -0500 | [diff] [blame] | 405 | ehci_vdbg (ehci, "resumed port %d\n", i + 1); |
| 406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 408 | (void) ehci_readl(ehci, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | /* maybe re-activate the schedule(s) */ |
| 411 | temp = 0; |
| 412 | if (ehci->async->qh_next.qh) |
| 413 | temp |= CMD_ASE; |
| 414 | if (ehci->periodic_sched) |
| 415 | temp |= CMD_PSE; |
| 416 | if (temp) { |
| 417 | ehci->command |= temp; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 418 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | ehci->next_statechange = jiffies + msecs_to_jiffies(5); |
| 422 | hcd->state = HC_STATE_RUNNING; |
| 423 | |
| 424 | /* Now we can safely re-enable irqs */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 425 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | spin_unlock_irq (&ehci->lock); |
Alan Stern | 3bb1af5 | 2008-03-03 15:15:36 -0500 | [diff] [blame] | 428 | ehci_handover_companion_ports(ehci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | #else |
| 433 | |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 434 | #define ehci_bus_suspend NULL |
| 435 | #define ehci_bus_resume NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | #endif /* CONFIG_PM */ |
| 438 | |
| 439 | /*-------------------------------------------------------------------------*/ |
| 440 | |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 441 | /* Display the ports dedicated to the companion controller */ |
Tony Jones | 5a3201b | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 442 | static ssize_t show_companion(struct device *dev, |
| 443 | struct device_attribute *attr, |
| 444 | char *buf) |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 445 | { |
| 446 | struct ehci_hcd *ehci; |
| 447 | int nports, index, n; |
| 448 | int count = PAGE_SIZE; |
| 449 | char *ptr = buf; |
| 450 | |
Tony Jones | 5a3201b | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 451 | ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev))); |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 452 | nports = HCS_N_PORTS(ehci->hcs_params); |
| 453 | |
| 454 | for (index = 0; index < nports; ++index) { |
| 455 | if (test_bit(index, &ehci->companion_ports)) { |
| 456 | n = scnprintf(ptr, count, "%d\n", index + 1); |
| 457 | ptr += n; |
| 458 | count -= n; |
| 459 | } |
| 460 | } |
| 461 | return ptr - buf; |
| 462 | } |
| 463 | |
| 464 | /* |
Balaji Rao | 90da096 | 2007-11-22 01:58:14 +0530 | [diff] [blame] | 465 | * Sets the owner of a port |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 466 | */ |
Balaji Rao | 90da096 | 2007-11-22 01:58:14 +0530 | [diff] [blame] | 467 | 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] | 468 | { |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 469 | u32 __iomem *status_reg; |
| 470 | u32 port_status; |
Balaji Rao | 90da096 | 2007-11-22 01:58:14 +0530 | [diff] [blame] | 471 | int try; |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 472 | |
Balaji Rao | 90da096 | 2007-11-22 01:58:14 +0530 | [diff] [blame] | 473 | status_reg = &ehci->regs->port_status[portnum]; |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * The controller won't set the OWNER bit if the port is |
| 477 | * enabled, so this loop will sometimes require at least two |
| 478 | * iterations: one to disable the port and one to set OWNER. |
| 479 | */ |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 480 | for (try = 4; try > 0; --try) { |
| 481 | spin_lock_irq(&ehci->lock); |
| 482 | port_status = ehci_readl(ehci, status_reg); |
| 483 | if ((port_status & PORT_OWNER) == new_owner |
| 484 | || (port_status & (PORT_OWNER | PORT_CONNECT)) |
| 485 | == 0) |
| 486 | try = 0; |
| 487 | else { |
| 488 | port_status ^= PORT_OWNER; |
| 489 | port_status &= ~(PORT_PE | PORT_RWC_BITS); |
| 490 | ehci_writel(ehci, port_status, status_reg); |
| 491 | } |
| 492 | spin_unlock_irq(&ehci->lock); |
| 493 | if (try > 1) |
| 494 | msleep(5); |
| 495 | } |
Balaji Rao | 90da096 | 2007-11-22 01:58:14 +0530 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Dedicate or undedicate a port to the companion controller. |
| 500 | * Syntax is "[-]portnum", where a leading '-' sign means |
| 501 | * return control of the port to the EHCI controller. |
| 502 | */ |
| 503 | static ssize_t store_companion(struct device *dev, |
| 504 | struct device_attribute *attr, |
| 505 | const char *buf, size_t count) |
| 506 | { |
| 507 | struct ehci_hcd *ehci; |
| 508 | int portnum, new_owner; |
| 509 | |
| 510 | ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev))); |
| 511 | new_owner = PORT_OWNER; /* Owned by companion */ |
| 512 | if (sscanf(buf, "%d", &portnum) != 1) |
| 513 | return -EINVAL; |
| 514 | if (portnum < 0) { |
| 515 | portnum = - portnum; |
| 516 | new_owner = 0; /* Owned by EHCI */ |
| 517 | } |
| 518 | if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params)) |
| 519 | return -ENOENT; |
| 520 | portnum--; |
| 521 | if (new_owner) |
| 522 | set_bit(portnum, &ehci->companion_ports); |
| 523 | else |
| 524 | clear_bit(portnum, &ehci->companion_ports); |
| 525 | set_owner(ehci, portnum, new_owner); |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 526 | return count; |
| 527 | } |
Tony Jones | 5a3201b | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 528 | static DEVICE_ATTR(companion, 0644, show_companion, store_companion); |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 529 | |
| 530 | static inline void create_companion_file(struct ehci_hcd *ehci) |
| 531 | { |
| 532 | int i; |
| 533 | |
| 534 | /* with integrated TT there is no companion! */ |
| 535 | if (!ehci_is_TDI(ehci)) |
Greg Kroah-Hartman | ed14f03 | 2009-04-27 13:15:38 -0700 | [diff] [blame] | 536 | i = device_create_file(ehci_to_hcd(ehci)->self.controller, |
Tony Jones | 5a3201b | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 537 | &dev_attr_companion); |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static inline void remove_companion_file(struct ehci_hcd *ehci) |
| 541 | { |
| 542 | /* with integrated TT there is no companion! */ |
| 543 | if (!ehci_is_TDI(ehci)) |
Greg Kroah-Hartman | ed14f03 | 2009-04-27 13:15:38 -0700 | [diff] [blame] | 544 | device_remove_file(ehci_to_hcd(ehci)->self.controller, |
Tony Jones | 5a3201b | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 545 | &dev_attr_companion); |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
| 549 | /*-------------------------------------------------------------------------*/ |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | static int check_reset_complete ( |
| 552 | struct ehci_hcd *ehci, |
| 553 | int index, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 554 | u32 __iomem *status_reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | int port_status |
| 556 | ) { |
David Brownell | cd4cdc9 | 2008-01-24 12:39:43 -0800 | [diff] [blame] | 557 | if (!(port_status & PORT_CONNECT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | return port_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | /* if reset finished and it's still not enabled -- handoff */ |
| 561 | if (!(port_status & PORT_PE)) { |
| 562 | |
| 563 | /* with integrated TT, there's nobody to hand it to! */ |
| 564 | if (ehci_is_TDI(ehci)) { |
| 565 | ehci_dbg (ehci, |
| 566 | "Failed to enable port %d on root hub TT\n", |
| 567 | index+1); |
| 568 | return port_status; |
| 569 | } |
| 570 | |
| 571 | ehci_dbg (ehci, "port %d full speed --> companion\n", |
| 572 | index + 1); |
| 573 | |
| 574 | // what happens if HCS_N_CC(params) == 0 ? |
| 575 | port_status |= PORT_OWNER; |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 576 | port_status &= ~PORT_RWC_BITS; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 577 | ehci_writel(ehci, port_status, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Vitaly Bordug | 796bcae | 2008-11-09 19:43:30 +0100 | [diff] [blame] | 579 | /* ensure 440EPX ohci controller state is operational */ |
| 580 | if (ehci->has_amcc_usb23) |
| 581 | set_ohci_hcfs(ehci, 1); |
| 582 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | ehci_dbg (ehci, "port %d high speed\n", index + 1); |
Vitaly Bordug | 796bcae | 2008-11-09 19:43:30 +0100 | [diff] [blame] | 584 | /* ensure 440EPx ohci controller state is suspended */ |
| 585 | if (ehci->has_amcc_usb23) |
| 586 | set_ohci_hcfs(ehci, 0); |
| 587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | return port_status; |
| 590 | } |
| 591 | |
| 592 | /*-------------------------------------------------------------------------*/ |
| 593 | |
| 594 | |
| 595 | /* build "status change" packet (one or two bytes) from HC registers */ |
| 596 | |
| 597 | static int |
| 598 | ehci_hub_status_data (struct usb_hcd *hcd, char *buf) |
| 599 | { |
| 600 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 601 | u32 temp, status = 0; |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 602 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | int ports, i, retval = 1; |
| 604 | unsigned long flags; |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 605 | u32 ppcd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 608 | if (!HC_IS_RUNNING(hcd->state)) |
| 609 | return 0; |
| 610 | |
| 611 | /* init status to no-changes */ |
| 612 | buf [0] = 0; |
| 613 | ports = HCS_N_PORTS (ehci->hcs_params); |
| 614 | if (ports > 7) { |
| 615 | buf [1] = 0; |
| 616 | retval++; |
| 617 | } |
David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 618 | |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 619 | /* Some boards (mostly VIA?) report bogus overcurrent indications, |
| 620 | * causing massive log spam unless we completely ignore them. It |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 621 | * may be relevant that VIA VT8235 controllers, where PORT_POWER is |
David Brownell | 93f1a47 | 2006-11-16 23:34:58 -0800 | [diff] [blame] | 622 | * always set, seem to clear PORT_OCC and PORT_CSC when writing to |
| 623 | * PORT_POWER; that's surprising, but maybe within-spec. |
| 624 | */ |
| 625 | if (!ignore_oc) |
| 626 | mask = PORT_CSC | PORT_PEC | PORT_OCC; |
| 627 | else |
| 628 | mask = PORT_CSC | PORT_PEC; |
| 629 | // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | /* no hub change reports (bit 0) for now (power, ...) */ |
| 632 | |
| 633 | /* port N changes (bit N)? */ |
| 634 | spin_lock_irqsave (&ehci->lock, flags); |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 635 | |
| 636 | /* get per-port change detect bits */ |
| 637 | if (ehci->has_ppcd) |
| 638 | ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16; |
| 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | for (i = 0; i < ports; i++) { |
Alek Du | 5a9cdf3 | 2010-06-04 15:47:56 +0800 | [diff] [blame] | 641 | /* leverage per-port change bits feature */ |
| 642 | if (ehci->has_ppcd && !(ppcd & (1 << i))) |
| 643 | continue; |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 644 | temp = ehci_readl(ehci, &ehci->regs->port_status [i]); |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * Return status information even for ports with OWNER set. |
| 648 | * Otherwise khubd wouldn't see the disconnect event when a |
| 649 | * high-speed device is switched over to the companion |
| 650 | * controller by the user. |
| 651 | */ |
| 652 | |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 653 | if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend) |
| 654 | || (ehci->reset_done[i] && time_after_eq( |
| 655 | jiffies, ehci->reset_done[i]))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | if (i < 7) |
| 657 | buf [0] |= 1 << (i + 1); |
| 658 | else |
| 659 | buf [1] |= 1 << (i - 7); |
| 660 | status = STS_PCD; |
| 661 | } |
| 662 | } |
| 663 | /* FIXME autosuspend idle root hubs */ |
| 664 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 665 | return status ? retval : 0; |
| 666 | } |
| 667 | |
| 668 | /*-------------------------------------------------------------------------*/ |
| 669 | |
| 670 | static void |
| 671 | ehci_hub_descriptor ( |
| 672 | struct ehci_hcd *ehci, |
| 673 | struct usb_hub_descriptor *desc |
| 674 | ) { |
| 675 | int ports = HCS_N_PORTS (ehci->hcs_params); |
| 676 | u16 temp; |
| 677 | |
| 678 | desc->bDescriptorType = 0x29; |
| 679 | desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */ |
| 680 | desc->bHubContrCurrent = 0; |
| 681 | |
| 682 | desc->bNbrPorts = ports; |
| 683 | temp = 1 + (ports / 8); |
| 684 | desc->bDescLength = 7 + 2 * temp; |
| 685 | |
| 686 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
| 687 | memset (&desc->bitmap [0], 0, temp); |
| 688 | memset (&desc->bitmap [temp], 0xff, temp); |
| 689 | |
| 690 | temp = 0x0008; /* per-port overcurrent reporting */ |
| 691 | if (HCS_PPC (ehci->hcs_params)) |
| 692 | temp |= 0x0001; /* per-port power control */ |
David Brownell | 56c1e26 | 2005-04-09 09:00:29 -0700 | [diff] [blame] | 693 | else |
| 694 | temp |= 0x0002; /* no power switching */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | #if 0 |
| 696 | // re-enable when we support USB_PORT_FEAT_INDICATOR below. |
| 697 | if (HCS_INDICATOR (ehci->hcs_params)) |
| 698 | temp |= 0x0080; /* per-port indicators (LEDs) */ |
| 699 | #endif |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 700 | desc->wHubCharacteristics = cpu_to_le16(temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /*-------------------------------------------------------------------------*/ |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | static int ehci_hub_control ( |
| 706 | struct usb_hcd *hcd, |
| 707 | u16 typeReq, |
| 708 | u16 wValue, |
| 709 | u16 wIndex, |
| 710 | char *buf, |
| 711 | u16 wLength |
| 712 | ) { |
| 713 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 714 | int ports = HCS_N_PORTS (ehci->hcs_params); |
Alan Stern | 383975d | 2007-05-04 11:52:40 -0400 | [diff] [blame] | 715 | u32 __iomem *status_reg = &ehci->regs->port_status[ |
| 716 | (wIndex & 0xff) - 1]; |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 717 | u32 __iomem *hostpc_reg = NULL; |
| 718 | u32 temp, temp1, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | unsigned long flags; |
| 720 | int retval = 0; |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 721 | unsigned selector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. |
| 725 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. |
| 726 | * (track current state ourselves) ... blink for diagnostics, |
| 727 | * power, "this is the one", etc. EHCI spec supports this. |
| 728 | */ |
| 729 | |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 730 | if (ehci->has_hostpc) |
| 731 | hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs |
| 732 | + HOSTPC0 + 4 * ((wIndex & 0xff) - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | spin_lock_irqsave (&ehci->lock, flags); |
| 734 | switch (typeReq) { |
| 735 | case ClearHubFeature: |
| 736 | switch (wValue) { |
| 737 | case C_HUB_LOCAL_POWER: |
| 738 | case C_HUB_OVER_CURRENT: |
| 739 | /* no hub-wide feature/status flags */ |
| 740 | break; |
| 741 | default: |
| 742 | goto error; |
| 743 | } |
| 744 | break; |
| 745 | case ClearPortFeature: |
| 746 | if (!wIndex || wIndex > ports) |
| 747 | goto error; |
| 748 | wIndex--; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 749 | temp = ehci_readl(ehci, status_reg); |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 750 | |
| 751 | /* |
| 752 | * Even if OWNER is set, so the port is owned by the |
| 753 | * companion controller, khubd needs to be able to clear |
| 754 | * the port-change status bits (especially |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 755 | * USB_PORT_STAT_C_CONNECTION). |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 756 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
| 758 | switch (wValue) { |
| 759 | case USB_PORT_FEAT_ENABLE: |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 760 | ehci_writel(ehci, temp & ~PORT_PE, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | break; |
| 762 | case USB_PORT_FEAT_C_ENABLE: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 763 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 764 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | break; |
| 766 | case USB_PORT_FEAT_SUSPEND: |
| 767 | if (temp & PORT_RESET) |
| 768 | goto error; |
David Brownell | f8aeb3b | 2006-01-20 13:55:14 -0800 | [diff] [blame] | 769 | if (ehci->no_selective_suspend) |
| 770 | break; |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 771 | if (!(temp & PORT_SUSPEND)) |
| 772 | break; |
| 773 | if ((temp & PORT_PE) == 0) |
| 774 | goto error; |
| 775 | |
| 776 | /* clear phy low-power mode before resume */ |
| 777 | if (hostpc_reg) { |
| 778 | temp1 = ehci_readl(ehci, hostpc_reg); |
| 779 | ehci_writel(ehci, temp1 & ~HOSTPC_PHCD, |
Alek Du | eab80de | 2010-05-10 11:17:49 +0800 | [diff] [blame] | 780 | hostpc_reg); |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 781 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 782 | msleep(5);/* wait to leave low-power mode */ |
| 783 | spin_lock_irqsave(&ehci->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | } |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 785 | /* resume signaling for 20 msec */ |
| 786 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
| 787 | ehci_writel(ehci, temp | PORT_RESUME, status_reg); |
| 788 | ehci->reset_done[wIndex] = jiffies |
| 789 | + msecs_to_jiffies(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | break; |
| 791 | case USB_PORT_FEAT_C_SUSPEND: |
Alan Stern | d1f114d | 2008-05-20 16:58:58 -0400 | [diff] [blame] | 792 | clear_bit(wIndex, &ehci->port_c_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | break; |
| 794 | case USB_PORT_FEAT_POWER: |
| 795 | if (HCS_PPC (ehci->hcs_params)) |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 796 | ehci_writel(ehci, |
| 797 | temp & ~(PORT_RWC_BITS | PORT_POWER), |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 798 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | break; |
| 800 | case USB_PORT_FEAT_C_CONNECTION: |
Alek Du | 48f2497 | 2010-06-04 15:47:55 +0800 | [diff] [blame] | 801 | if (ehci->has_lpm) { |
| 802 | /* clear PORTSC bits on disconnect */ |
| 803 | temp &= ~PORT_LPM; |
| 804 | temp &= ~PORT_DEV_ADDR; |
| 805 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 806 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 807 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | break; |
| 809 | case USB_PORT_FEAT_C_OVER_CURRENT: |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 810 | ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC, |
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_C_RESET: |
| 814 | /* GetPortStatus clears reset */ |
| 815 | break; |
| 816 | default: |
| 817 | goto error; |
| 818 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 819 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | break; |
| 821 | case GetHubDescriptor: |
| 822 | ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *) |
| 823 | buf); |
| 824 | break; |
| 825 | case GetHubStatus: |
| 826 | /* no hub-wide feature/status flags */ |
| 827 | memset (buf, 0, 4); |
| 828 | //cpu_to_le32s ((u32 *) buf); |
| 829 | break; |
| 830 | case GetPortStatus: |
| 831 | if (!wIndex || wIndex > ports) |
| 832 | goto error; |
| 833 | wIndex--; |
| 834 | status = 0; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 835 | temp = ehci_readl(ehci, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
| 837 | // wPortChange bits |
| 838 | if (temp & PORT_CSC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 839 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | if (temp & PORT_PEC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 841 | status |= USB_PORT_STAT_C_ENABLE << 16; |
Christian Engelmayer | 756aa6b | 2007-05-30 11:04:48 -0700 | [diff] [blame] | 842 | |
| 843 | if ((temp & PORT_OCC) && !ignore_oc){ |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 844 | status |= USB_PORT_STAT_C_OVERCURRENT << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Christian Engelmayer | 756aa6b | 2007-05-30 11:04:48 -0700 | [diff] [blame] | 846 | /* |
| 847 | * Hubs should disable port power on over-current. |
| 848 | * However, not all EHCI implementations do this |
| 849 | * automatically, even if they _do_ support per-port |
| 850 | * power switching; they're allowed to just limit the |
| 851 | * current. khubd will turn the power back on. |
| 852 | */ |
| 853 | if (HCS_PPC (ehci->hcs_params)){ |
| 854 | ehci_writel(ehci, |
| 855 | temp & ~(PORT_RWC_BITS | PORT_POWER), |
| 856 | status_reg); |
| 857 | } |
| 858 | } |
| 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | /* whoever resumes must GetPortStatus to complete it!! */ |
Alan Stern | 629e442 | 2007-01-22 16:08:53 -0500 | [diff] [blame] | 861 | if (temp & PORT_RESUME) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Alan Stern | 629e442 | 2007-01-22 16:08:53 -0500 | [diff] [blame] | 863 | /* Remote Wakeup received? */ |
| 864 | if (!ehci->reset_done[wIndex]) { |
| 865 | /* resume signaling for 20 msec */ |
| 866 | ehci->reset_done[wIndex] = jiffies |
| 867 | + msecs_to_jiffies(20); |
| 868 | /* check the port again */ |
| 869 | mod_timer(&ehci_to_hcd(ehci)->rh_timer, |
| 870 | ehci->reset_done[wIndex]); |
| 871 | } |
| 872 | |
| 873 | /* resume completed? */ |
| 874 | else if (time_after_eq(jiffies, |
| 875 | ehci->reset_done[wIndex])) { |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 876 | clear_bit(wIndex, &ehci->suspended_ports); |
Alan Stern | d1f114d | 2008-05-20 16:58:58 -0400 | [diff] [blame] | 877 | set_bit(wIndex, &ehci->port_c_suspend); |
Alan Stern | 629e442 | 2007-01-22 16:08:53 -0500 | [diff] [blame] | 878 | ehci->reset_done[wIndex] = 0; |
| 879 | |
| 880 | /* stop resume signaling */ |
| 881 | temp = ehci_readl(ehci, status_reg); |
| 882 | ehci_writel(ehci, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 883 | temp & ~(PORT_RWC_BITS | PORT_RESUME), |
| 884 | status_reg); |
Alan Stern | 629e442 | 2007-01-22 16:08:53 -0500 | [diff] [blame] | 885 | retval = handshake(ehci, status_reg, |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 886 | PORT_RESUME, 0, 2000 /* 2msec */); |
Alan Stern | 629e442 | 2007-01-22 16:08:53 -0500 | [diff] [blame] | 887 | if (retval != 0) { |
| 888 | ehci_err(ehci, |
| 889 | "port %d resume error %d\n", |
| 890 | wIndex + 1, retval); |
| 891 | goto error; |
| 892 | } |
| 893 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /* whoever resets must GetPortStatus to complete it!! */ |
| 898 | if ((temp & PORT_RESET) |
Alan Stern | 629e442 | 2007-01-22 16:08:53 -0500 | [diff] [blame] | 899 | && time_after_eq(jiffies, |
| 900 | ehci->reset_done[wIndex])) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 901 | status |= USB_PORT_STAT_C_RESET << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | ehci->reset_done [wIndex] = 0; |
| 903 | |
| 904 | /* force reset to complete */ |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 905 | ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET), |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 906 | status_reg); |
David Brownell | c22fa3a | 2005-06-13 07:15:28 -0700 | [diff] [blame] | 907 | /* REVISIT: some hardware needs 550+ usec to clear |
| 908 | * this bit; seems too long to spin routinely... |
| 909 | */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 910 | retval = handshake(ehci, status_reg, |
Dinh Nguyen | 6307e09 | 2010-04-13 11:13:15 -0500 | [diff] [blame] | 911 | PORT_RESET, 0, 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | if (retval != 0) { |
| 913 | ehci_err (ehci, "port %d reset error %d\n", |
| 914 | wIndex + 1, retval); |
| 915 | goto error; |
| 916 | } |
| 917 | |
| 918 | /* see what we found out */ |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 919 | temp = check_reset_complete (ehci, wIndex, status_reg, |
| 920 | ehci_readl(ehci, status_reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 923 | if (!(temp & (PORT_RESUME|PORT_RESET))) |
| 924 | ehci->reset_done[wIndex] = 0; |
| 925 | |
Alan Stern | 57e06c1 | 2007-01-16 11:59:45 -0500 | [diff] [blame] | 926 | /* transfer dedicated ports to the companion hc */ |
| 927 | if ((temp & PORT_CONNECT) && |
| 928 | test_bit(wIndex, &ehci->companion_ports)) { |
| 929 | temp &= ~PORT_RWC_BITS; |
| 930 | temp |= PORT_OWNER; |
| 931 | ehci_writel(ehci, temp, status_reg); |
| 932 | ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1); |
| 933 | temp = ehci_readl(ehci, status_reg); |
| 934 | } |
| 935 | |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 936 | /* |
| 937 | * Even if OWNER is set, there's no harm letting khubd |
| 938 | * see the wPortStatus values (they should all be 0 except |
| 939 | * for PORT_POWER anyway). |
| 940 | */ |
| 941 | |
| 942 | if (temp & PORT_CONNECT) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 943 | status |= USB_PORT_STAT_CONNECTION; |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 944 | // status may be from integrated TT |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 945 | if (ehci->has_hostpc) { |
| 946 | temp1 = ehci_readl(ehci, hostpc_reg); |
| 947 | status |= ehci_port_speed(ehci, temp1); |
| 948 | } else |
| 949 | status |= ehci_port_speed(ehci, temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 951 | if (temp & PORT_PE) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 952 | status |= USB_PORT_STAT_ENABLE; |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 953 | |
| 954 | /* maybe the port was unsuspended without our knowledge */ |
| 955 | if (temp & (PORT_SUSPEND|PORT_RESUME)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 956 | status |= USB_PORT_STAT_SUSPEND; |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 957 | } else if (test_bit(wIndex, &ehci->suspended_ports)) { |
| 958 | clear_bit(wIndex, &ehci->suspended_ports); |
| 959 | ehci->reset_done[wIndex] = 0; |
| 960 | if (temp & PORT_PE) |
| 961 | set_bit(wIndex, &ehci->port_c_suspend); |
| 962 | } |
| 963 | |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 964 | if (temp & PORT_OC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 965 | status |= USB_PORT_STAT_OVERCURRENT; |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 966 | if (temp & PORT_RESET) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 967 | status |= USB_PORT_STAT_RESET; |
Alan Stern | 625b5c9 | 2007-01-16 11:58:47 -0500 | [diff] [blame] | 968 | if (temp & PORT_POWER) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 969 | status |= USB_PORT_STAT_POWER; |
Alan Stern | d1f114d | 2008-05-20 16:58:58 -0400 | [diff] [blame] | 970 | if (test_bit(wIndex, &ehci->port_c_suspend)) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 971 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
David Brownell | 9776afc | 2008-02-01 11:42:05 -0800 | [diff] [blame] | 973 | #ifndef VERBOSE_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
| 975 | #endif |
| 976 | dbg_port (ehci, "GetStatus", wIndex + 1, temp); |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 977 | put_unaligned_le32(status, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | break; |
| 979 | case SetHubFeature: |
| 980 | switch (wValue) { |
| 981 | case C_HUB_LOCAL_POWER: |
| 982 | case C_HUB_OVER_CURRENT: |
| 983 | /* no hub-wide feature/status flags */ |
| 984 | break; |
| 985 | default: |
| 986 | goto error; |
| 987 | } |
| 988 | break; |
| 989 | case SetPortFeature: |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 990 | selector = wIndex >> 8; |
| 991 | wIndex &= 0xff; |
Jason Wessel | 8d053c7 | 2009-08-20 15:39:54 -0500 | [diff] [blame] | 992 | if (unlikely(ehci->debug)) { |
| 993 | /* If the debug port is active any port |
| 994 | * feature requests should get denied */ |
| 995 | if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) && |
| 996 | (readl(&ehci->debug->control) & DBGP_ENABLED)) { |
| 997 | retval = -ENODEV; |
| 998 | goto error_exit; |
| 999 | } |
| 1000 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | if (!wIndex || wIndex > ports) |
| 1002 | goto error; |
| 1003 | wIndex--; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 1004 | temp = ehci_readl(ehci, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | if (temp & PORT_OWNER) |
| 1006 | break; |
| 1007 | |
David Brownell | 10f6524 | 2005-08-31 10:55:38 -0700 | [diff] [blame] | 1008 | temp &= ~PORT_RWC_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | switch (wValue) { |
| 1010 | case USB_PORT_FEAT_SUSPEND: |
David Brownell | f8aeb3b | 2006-01-20 13:55:14 -0800 | [diff] [blame] | 1011 | if (ehci->no_selective_suspend) |
| 1012 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | if ((temp & PORT_PE) == 0 |
| 1014 | || (temp & PORT_RESET) != 0) |
| 1015 | goto error; |
Alek Du | b9df7942 | 2010-01-19 16:31:31 +0800 | [diff] [blame] | 1016 | |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 1017 | /* After above check the port must be connected. |
| 1018 | * Set appropriate bit thus could put phy into low power |
| 1019 | * mode if we have hostpc feature |
| 1020 | */ |
Alek Du | b9df7942 | 2010-01-19 16:31:31 +0800 | [diff] [blame] | 1021 | temp &= ~PORT_WKCONN_E; |
| 1022 | temp |= PORT_WKDISC_E | PORT_WKOC_E; |
| 1023 | ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 1024 | if (hostpc_reg) { |
Alek Du | b9df7942 | 2010-01-19 16:31:31 +0800 | [diff] [blame] | 1025 | spin_unlock_irqrestore(&ehci->lock, flags); |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 1026 | msleep(5);/* 5ms for HCD enter low pwr mode */ |
Alek Du | b9df7942 | 2010-01-19 16:31:31 +0800 | [diff] [blame] | 1027 | spin_lock_irqsave(&ehci->lock, flags); |
Alek Du | 331ac6b | 2009-07-13 12:41:20 +0800 | [diff] [blame] | 1028 | temp1 = ehci_readl(ehci, hostpc_reg); |
| 1029 | ehci_writel(ehci, temp1 | HOSTPC_PHCD, |
| 1030 | hostpc_reg); |
| 1031 | temp1 = ehci_readl(ehci, hostpc_reg); |
| 1032 | ehci_dbg(ehci, "Port%d phy low pwr mode %s\n", |
| 1033 | wIndex, (temp1 & HOSTPC_PHCD) ? |
| 1034 | "succeeded" : "failed"); |
| 1035 | } |
Alan Stern | eafe5b9 | 2008-10-06 11:25:53 -0400 | [diff] [blame] | 1036 | set_bit(wIndex, &ehci->suspended_ports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | break; |
| 1038 | case USB_PORT_FEAT_POWER: |
| 1039 | if (HCS_PPC (ehci->hcs_params)) |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 1040 | ehci_writel(ehci, temp | PORT_POWER, |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 1041 | status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | case USB_PORT_FEAT_RESET: |
| 1044 | if (temp & PORT_RESUME) |
| 1045 | goto error; |
| 1046 | /* line status bits may report this as low speed, |
| 1047 | * which can be fine if this root hub has a |
| 1048 | * transaction translator built in. |
| 1049 | */ |
| 1050 | if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT |
| 1051 | && !ehci_is_TDI(ehci) |
| 1052 | && PORT_USB11 (temp)) { |
| 1053 | ehci_dbg (ehci, |
| 1054 | "port %d low speed --> companion\n", |
| 1055 | wIndex + 1); |
| 1056 | temp |= PORT_OWNER; |
| 1057 | } else { |
| 1058 | ehci_vdbg (ehci, "port %d reset\n", wIndex + 1); |
| 1059 | temp |= PORT_RESET; |
| 1060 | temp &= ~PORT_PE; |
| 1061 | |
| 1062 | /* |
| 1063 | * caller must wait, then call GetPortStatus |
| 1064 | * usb 2.0 spec says 50 ms resets on root |
| 1065 | */ |
| 1066 | ehci->reset_done [wIndex] = jiffies |
| 1067 | + msecs_to_jiffies (50); |
| 1068 | } |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 1069 | ehci_writel(ehci, temp, status_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | break; |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 1071 | |
| 1072 | /* For downstream facing ports (these): one hub port is put |
| 1073 | * into test mode according to USB2 11.24.2.13, then the hub |
| 1074 | * must be reset (which for root hub now means rmmod+modprobe, |
| 1075 | * or else system reboot). See EHCI 2.3.9 and 4.14 for info |
| 1076 | * about the EHCI-specific stuff. |
| 1077 | */ |
| 1078 | case USB_PORT_FEAT_TEST: |
| 1079 | if (!selector || selector > 5) |
| 1080 | goto error; |
| 1081 | ehci_quiesce(ehci); |
| 1082 | ehci_halt(ehci); |
| 1083 | temp |= selector << 16; |
Alan Stern | e631656 | 2007-01-16 11:58:00 -0500 | [diff] [blame] | 1084 | ehci_writel(ehci, temp, status_reg); |
David Brownell | f0d7f27 | 2006-11-16 23:56:15 -0800 | [diff] [blame] | 1085 | break; |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | default: |
| 1088 | goto error; |
| 1089 | } |
Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 1090 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | break; |
| 1092 | |
| 1093 | default: |
| 1094 | error: |
| 1095 | /* "stall" on error */ |
| 1096 | retval = -EPIPE; |
| 1097 | } |
Jason Wessel | 8d053c7 | 2009-08-20 15:39:54 -0500 | [diff] [blame] | 1098 | error_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | spin_unlock_irqrestore (&ehci->lock, flags); |
| 1100 | return retval; |
| 1101 | } |
Balaji Rao | 90da096 | 2007-11-22 01:58:14 +0530 | [diff] [blame] | 1102 | |
| 1103 | static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum) |
| 1104 | { |
| 1105 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1106 | |
| 1107 | if (ehci_is_TDI(ehci)) |
| 1108 | return; |
| 1109 | set_owner(ehci, --portnum, PORT_OWNER); |
| 1110 | } |
| 1111 | |
Alan Stern | 3a31155 | 2008-05-20 16:58:29 -0400 | [diff] [blame] | 1112 | static int ehci_port_handed_over(struct usb_hcd *hcd, int portnum) |
| 1113 | { |
| 1114 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1115 | u32 __iomem *reg; |
| 1116 | |
| 1117 | if (ehci_is_TDI(ehci)) |
| 1118 | return 0; |
| 1119 | reg = &ehci->regs->port_status[portnum - 1]; |
| 1120 | return ehci_readl(ehci, reg) & PORT_OWNER; |
| 1121 | } |