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