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