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