Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[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/*-------------------------------------------------------------------------*/
83722bc9 30#include <linux/usb/otg.h>
1da177e4 31
58a97ffe
AS
32#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
33
aff6d18f
AS
34#ifdef CONFIG_PM
35
383975d7
AS
36static int ehci_hub_control(
37 struct usb_hcd *hcd,
38 u16 typeReq,
39 u16 wValue,
40 u16 wIndex,
41 char *buf,
42 u16 wLength
43);
44
9b790915
JW
45static int persist_enabled_on_companion(struct usb_device *udev, void *unused)
46{
47 return !udev->maxchild && udev->persist_enabled &&
48 udev->bus->root_hub->speed < USB_SPEED_HIGH;
49}
50
383975d7
AS
51/* After a power loss, ports that were owned by the companion must be
52 * reset so that the companion can still own them.
53 */
54static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
55{
56 u32 __iomem *reg;
57 u32 status;
58 int port;
59 __le32 buf;
60 struct usb_hcd *hcd = ehci_to_hcd(ehci);
61
62 if (!ehci->owned_ports)
63 return;
64
9b790915
JW
65 /*
66 * USB 1.1 devices are mostly HIDs, which don't need to persist across
67 * suspends. If we ensure that none of our companion's devices have
68 * persist_enabled (by looking through all USB 1.1 buses in the system),
69 * we can skip this and avoid slowing resume down. Devices without
70 * persist will just get reenumerated shortly after resume anyway.
71 */
72 if (!usb_for_each_dev(NULL, persist_enabled_on_companion))
73 return;
74
c73cee71
AS
75 /* Make sure the ports are powered */
76 port = HCS_N_PORTS(ehci->hcs_params);
77 while (port--) {
78 if (test_bit(port, &ehci->owned_ports)) {
79 reg = &ehci->regs->port_status[port];
80 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
81 if (!(status & PORT_POWER)) {
82 status |= PORT_POWER;
83 ehci_writel(ehci, status, reg);
84 }
85 }
86 }
87
383975d7
AS
88 /* Give the connections some time to appear */
89 msleep(20);
90
c4f34764 91 spin_lock_irq(&ehci->lock);
383975d7
AS
92 port = HCS_N_PORTS(ehci->hcs_params);
93 while (port--) {
94 if (test_bit(port, &ehci->owned_ports)) {
95 reg = &ehci->regs->port_status[port];
3c519b84 96 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
383975d7
AS
97
98 /* Port already owned by companion? */
99 if (status & PORT_OWNER)
100 clear_bit(port, &ehci->owned_ports);
3c519b84
AS
101 else if (test_bit(port, &ehci->companion_ports))
102 ehci_writel(ehci, status & ~PORT_PE, reg);
c4f34764
AS
103 else {
104 spin_unlock_irq(&ehci->lock);
383975d7
AS
105 ehci_hub_control(hcd, SetPortFeature,
106 USB_PORT_FEAT_RESET, port + 1,
107 NULL, 0);
c4f34764
AS
108 spin_lock_irq(&ehci->lock);
109 }
383975d7
AS
110 }
111 }
c4f34764 112 spin_unlock_irq(&ehci->lock);
383975d7
AS
113
114 if (!ehci->owned_ports)
115 return;
116 msleep(90); /* Wait for resets to complete */
117
c4f34764 118 spin_lock_irq(&ehci->lock);
383975d7
AS
119 port = HCS_N_PORTS(ehci->hcs_params);
120 while (port--) {
121 if (test_bit(port, &ehci->owned_ports)) {
c4f34764 122 spin_unlock_irq(&ehci->lock);
383975d7
AS
123 ehci_hub_control(hcd, GetPortStatus,
124 0, port + 1,
125 (char *) &buf, sizeof(buf));
c4f34764 126 spin_lock_irq(&ehci->lock);
383975d7
AS
127
128 /* The companion should now own the port,
129 * but if something went wrong the port must not
130 * remain enabled.
131 */
132 reg = &ehci->regs->port_status[port];
133 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
134 if (status & PORT_OWNER)
135 ehci_writel(ehci, status | PORT_CSC, reg);
136 else {
137 ehci_dbg(ehci, "failed handover port %d: %x\n",
138 port + 1, status);
139 ehci_writel(ehci, status & ~PORT_PE, reg);
140 }
141 }
142 }
143
144 ehci->owned_ports = 0;
c4f34764 145 spin_unlock_irq(&ehci->lock);
383975d7
AS
146}
147
c5cf9212 148static int ehci_port_change(struct ehci_hcd *ehci)
294d95f2
MG
149{
150 int i = HCS_N_PORTS(ehci->hcs_params);
151
152 /* First check if the controller indicates a change event */
153
154 if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
155 return 1;
156
157 /*
158 * Not all controllers appear to update this while going from D3 to D0,
159 * so check the individual port status registers as well
160 */
161
162 while (i--)
163 if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
164 return 1;
165
166 return 0;
167}
168
c5cf9212 169static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
4147200d 170 bool suspending, bool do_wakeup)
16032c4f
AS
171{
172 int port;
173 u32 temp;
174
175 /* If remote wakeup is enabled for the root hub but disabled
176 * for the controller, we must adjust all the port wakeup flags
177 * when the controller is suspended or resumed. In all other
178 * cases they don't need to be changed.
179 */
4147200d 180 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
16032c4f
AS
181 return;
182
c4f34764 183 spin_lock_irq(&ehci->lock);
148fc55f 184
16032c4f 185 /* clear phy low-power mode before changing wakeup flags */
2cdcec4f 186 if (ehci->has_tdi_phy_lpm) {
16032c4f
AS
187 port = HCS_N_PORTS(ehci->hcs_params);
188 while (port--) {
a46af4eb 189 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
16032c4f 190
16032c4f
AS
191 temp = ehci_readl(ehci, hostpc_reg);
192 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
193 }
c4f34764 194 spin_unlock_irq(&ehci->lock);
16032c4f 195 msleep(5);
c4f34764 196 spin_lock_irq(&ehci->lock);
16032c4f
AS
197 }
198
199 port = HCS_N_PORTS(ehci->hcs_params);
200 while (port--) {
201 u32 __iomem *reg = &ehci->regs->port_status[port];
202 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
203 u32 t2 = t1 & ~PORT_WAKE_BITS;
204
205 /* If we are suspending the controller, clear the flags.
206 * If we are resuming the controller, set the wakeup flags.
207 */
208 if (!suspending) {
209 if (t1 & PORT_CONNECT)
210 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
211 else
212 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
213 }
16032c4f
AS
214 ehci_writel(ehci, t2, reg);
215 }
216
217 /* enter phy low-power mode again */
2cdcec4f 218 if (ehci->has_tdi_phy_lpm) {
16032c4f
AS
219 port = HCS_N_PORTS(ehci->hcs_params);
220 while (port--) {
a46af4eb 221 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
16032c4f 222
16032c4f
AS
223 temp = ehci_readl(ehci, hostpc_reg);
224 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
225 }
226 }
ee0b9be8
AS
227
228 /* Does the root hub have a port wakeup pending? */
294d95f2 229 if (!suspending && ehci_port_change(ehci))
ee0b9be8 230 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
148fc55f 231
c4f34764 232 spin_unlock_irq(&ehci->lock);
16032c4f
AS
233}
234
0c0382e3 235static int ehci_bus_suspend (struct usb_hcd *hcd)
1da177e4
LT
236{
237 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
238 int port;
8c03356a 239 int mask;
16032c4f 240 int changed;
1da177e4 241
8c774fe8
AS
242 ehci_dbg(ehci, "suspend root hub\n");
243
1da177e4
LT
244 if (time_before (jiffies, ehci->next_statechange))
245 msleep(5);
246
c4f34764
AS
247 /* stop the schedules */
248 ehci_quiesce(ehci);
249
1da177e4 250 spin_lock_irq (&ehci->lock);
43fe3a99
AS
251 if (ehci->rh_state < EHCI_RH_RUNNING)
252 goto done;
1da177e4 253
cec3a53c
AS
254 /* Once the controller is stopped, port resumes that are already
255 * in progress won't complete. Hence if remote wakeup is enabled
256 * for the root hub and any ports are in the middle of a resume or
257 * remote wakeup, we must fail the suspend.
258 */
259 if (hcd->self.root_hub->do_remote_wakeup) {
a448e4dc
AS
260 if (ehci->resuming_ports) {
261 spin_unlock_irq(&ehci->lock);
262 ehci_dbg(ehci, "suspend failed because a port is resuming\n");
263 return -EBUSY;
cec3a53c
AS
264 }
265 }
266
8c03356a
AS
267 /* Unlike other USB host controller types, EHCI doesn't have
268 * any notion of "global" or bus-wide suspend. The driver has
269 * to manually suspend all the active unsuspended ports, and
270 * then manually resume them in the bus_resume() routine.
271 */
272 ehci->bus_suspended = 0;
383975d7 273 ehci->owned_ports = 0;
16032c4f 274 changed = 0;
cec3a53c 275 port = HCS_N_PORTS(ehci->hcs_params);
1da177e4
LT
276 while (port--) {
277 u32 __iomem *reg = &ehci->regs->port_status [port];
083522d7 278 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
16032c4f 279 u32 t2 = t1 & ~PORT_WAKE_BITS;
1da177e4 280
8c03356a 281 /* keep track of which ports we suspend */
383975d7
AS
282 if (t1 & PORT_OWNER)
283 set_bit(port, &ehci->owned_ports);
284 else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
1da177e4 285 t2 |= PORT_SUSPEND;
8c03356a
AS
286 set_bit(port, &ehci->bus_suspended);
287 }
288
16032c4f 289 /* enable remote wakeup on all ports, if told to do so */
331ac6b2
AD
290 if (hcd->self.root_hub->do_remote_wakeup) {
291 /* only enable appropriate wake bits, otherwise the
292 * hardware can not go phy low power mode. If a race
293 * condition happens here(connection change during bits
294 * set), the port change detection will finally fix it.
295 */
16032c4f 296 if (t1 & PORT_CONNECT)
331ac6b2 297 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
16032c4f 298 else
331ac6b2 299 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
16032c4f 300 }
1da177e4
LT
301
302 if (t1 != t2) {
083522d7 303 ehci_writel(ehci, t2, reg);
16032c4f
AS
304 changed = 1;
305 }
306 }
331ac6b2 307
2cdcec4f 308 if (changed && ehci->has_tdi_phy_lpm) {
16032c4f
AS
309 spin_unlock_irq(&ehci->lock);
310 msleep(5); /* 5 ms for HCD to enter low-power mode */
311 spin_lock_irq(&ehci->lock);
312
313 port = HCS_N_PORTS(ehci->hcs_params);
314 while (port--) {
a46af4eb 315 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
16032c4f
AS
316 u32 t3;
317
16032c4f
AS
318 t3 = ehci_readl(ehci, hostpc_reg);
319 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
320 t3 = ehci_readl(ehci, hostpc_reg);
321 ehci_dbg(ehci, "Port %d phy low-power mode %s\n",
331ac6b2
AD
322 port, (t3 & HOSTPC_PHCD) ?
323 "succeeded" : "failed");
1da177e4
LT
324 }
325 }
c4f34764 326 spin_unlock_irq(&ehci->lock);
1da177e4 327
cd930c93
AS
328 /* Apparently some devices need a >= 1-uframe delay here */
329 if (ehci->bus_suspended)
330 udelay(150);
331
1da177e4
LT
332 /* turn off now-idle HC */
333 ehci_halt (ehci);
c4f34764
AS
334
335 spin_lock_irq(&ehci->lock);
43fe3a99
AS
336 if (ehci->enabled_hrtimer_events & BIT(EHCI_HRTIMER_POLL_DEAD))
337 ehci_handle_controller_death(ehci);
338 if (ehci->rh_state != EHCI_RH_RUNNING)
339 goto done;
e8799906 340 ehci->rh_state = EHCI_RH_SUSPENDED;
1da177e4 341
3c273a05 342 end_unlink_async(ehci);
2a40f324 343 unlink_empty_async_suspended(ehci);
9118f9eb 344 ehci_handle_start_intr_unlinks(ehci);
df202255 345 ehci_handle_intr_unlinks(ehci);
55934eb3 346 end_free_itds(ehci);
cdc647a9 347
8c03356a
AS
348 /* allow remote wakeup */
349 mask = INTR_MASK;
58a97ffe 350 if (!hcd->self.root_hub->do_remote_wakeup)
8c03356a 351 mask &= ~STS_PCD;
083522d7
BH
352 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
353 ehci_readl(ehci, &ehci->regs->intr_enable);
8c03356a 354
43fe3a99 355 done:
1da177e4 356 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
d58b4bcc
AS
357 ehci->enabled_hrtimer_events = 0;
358 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
1da177e4 359 spin_unlock_irq (&ehci->lock);
015798b2 360
d58b4bcc 361 hrtimer_cancel(&ehci->hrtimer);
1da177e4
LT
362 return 0;
363}
364
365
366/* caller has locked the root hub, and should reset/reinit on error */
0c0382e3 367static int ehci_bus_resume (struct usb_hcd *hcd)
1da177e4
LT
368{
369 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
370 u32 temp;
383975d7 371 u32 power_okay;
1da177e4 372 int i;
d0f2fb25 373 unsigned long resume_needed = 0;
1da177e4
LT
374
375 if (time_before (jiffies, ehci->next_statechange))
376 msleep(5);
377 spin_lock_irq (&ehci->lock);
43fe3a99
AS
378 if (!HCD_HW_ACCESSIBLE(hcd) || ehci->shutdown)
379 goto shutdown;
1da177e4 380
ad45f1dc 381 if (unlikely(ehci->debug)) {
9fa5780b 382 if (!dbgp_reset_prep(hcd))
ad45f1dc
JW
383 ehci->debug = NULL;
384 else
9fa5780b 385 dbgp_external_startup(hcd);
ad45f1dc
JW
386 }
387
f03c17fc
DB
388 /* Ideally and we've got a real resume here, and no port's power
389 * was lost. (For PCI, that means Vaux was maintained.) But we
390 * could instead be restoring a swsusp snapshot -- so that BIOS was
391 * the last user of the controller, not reset/pm hardware keeping
392 * state we gave to it.
393 */
383975d7
AS
394 power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
395 ehci_dbg(ehci, "resume root hub%s\n",
396 power_okay ? "" : " after power loss");
f03c17fc 397
8c03356a
AS
398 /* at least some APM implementations will try to deliver
399 * IRQs right away, so delay them until we're ready.
400 */
083522d7 401 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
8c03356a
AS
402
403 /* re-init operational registers */
083522d7
BH
404 ehci_writel(ehci, 0, &ehci->regs->segment);
405 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
406 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
1da177e4
LT
407
408 /* restore CMD_RUN, framelist size, and irq threshold */
3d9545cc 409 ehci->command |= CMD_RUN;
083522d7 410 ehci_writel(ehci, ehci->command, &ehci->regs->command);
e8799906 411 ehci->rh_state = EHCI_RH_RUNNING;
1da177e4 412
6273f181
PC
413 /*
414 * According to Bugzilla #8190, the port status for some controllers
415 * will be wrong without a delay. At their wrong status, the port
416 * is enabled, but not suspended neither resumed.
417 */
418 i = HCS_N_PORTS(ehci->hcs_params);
419 while (i--) {
420 temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
421 if ((temp & PORT_PE) &&
422 !(temp & (PORT_SUSPEND | PORT_RESUME))) {
423 ehci_dbg(ehci, "Port status(0x%x) is wrong\n", temp);
424 spin_unlock_irq(&ehci->lock);
425 msleep(8);
426 spin_lock_irq(&ehci->lock);
427 break;
428 }
429 }
430
43fe3a99
AS
431 if (ehci->shutdown)
432 goto shutdown;
e198a314 433
16032c4f 434 /* clear phy low-power mode before resume */
2cdcec4f 435 if (ehci->bus_suspended && ehci->has_tdi_phy_lpm) {
16032c4f
AS
436 i = HCS_N_PORTS(ehci->hcs_params);
437 while (i--) {
438 if (test_bit(i, &ehci->bus_suspended)) {
a46af4eb
AS
439 u32 __iomem *hostpc_reg =
440 &ehci->regs->hostpc[i];
16032c4f 441
16032c4f
AS
442 temp = ehci_readl(ehci, hostpc_reg);
443 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
444 hostpc_reg);
445 }
446 }
447 spin_unlock_irq(&ehci->lock);
448 msleep(5);
449 spin_lock_irq(&ehci->lock);
43fe3a99
AS
450 if (ehci->shutdown)
451 goto shutdown;
16032c4f
AS
452 }
453
8c03356a 454 /* manually resume the ports we suspended during bus_suspend() */
1da177e4
LT
455 i = HCS_N_PORTS (ehci->hcs_params);
456 while (i--) {
083522d7 457 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
58a97ffe 458 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
8c03356a 459 if (test_bit(i, &ehci->bus_suspended) &&
3a4e72cb 460 (temp & PORT_SUSPEND)) {
1da177e4 461 temp |= PORT_RESUME;
d0f2fb25 462 set_bit(i, &resume_needed);
3a4e72cb 463 }
083522d7 464 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
1da177e4 465 }
3a4e72cb
VP
466
467 /* msleep for 20ms only if code is trying to resume port */
468 if (resume_needed) {
469 spin_unlock_irq(&ehci->lock);
470 msleep(20);
471 spin_lock_irq(&ehci->lock);
43fe3a99
AS
472 if (ehci->shutdown)
473 goto shutdown;
3a4e72cb
VP
474 }
475
1da177e4 476 i = HCS_N_PORTS (ehci->hcs_params);
1da177e4 477 while (i--) {
083522d7 478 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
d0f2fb25 479 if (test_bit(i, &resume_needed)) {
24b90814 480 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
083522d7 481 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
8c03356a 482 }
1da177e4 483 }
1da177e4
LT
484
485 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
c4f34764
AS
486 spin_unlock_irq(&ehci->lock);
487
488 ehci_handover_companion_ports(ehci);
1da177e4
LT
489
490 /* Now we can safely re-enable irqs */
43fe3a99
AS
491 spin_lock_irq(&ehci->lock);
492 if (ehci->shutdown)
493 goto shutdown;
083522d7 494 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
15be105b 495 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
43fe3a99 496 spin_unlock_irq(&ehci->lock);
1da177e4 497
1da177e4 498 return 0;
43fe3a99
AS
499
500 shutdown:
501 spin_unlock_irq(&ehci->lock);
502 return -ESHUTDOWN;
1da177e4
LT
503}
504
505#else
506
0c0382e3
AS
507#define ehci_bus_suspend NULL
508#define ehci_bus_resume NULL
1da177e4
LT
509
510#endif /* CONFIG_PM */
511
57e06c11
AS
512/*-------------------------------------------------------------------------*/
513
57e06c11 514/*
90da096e 515 * Sets the owner of a port
57e06c11 516 */
90da096e 517static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
57e06c11 518{
57e06c11
AS
519 u32 __iomem *status_reg;
520 u32 port_status;
90da096e 521 int try;
57e06c11 522
90da096e 523 status_reg = &ehci->regs->port_status[portnum];
57e06c11
AS
524
525 /*
526 * The controller won't set the OWNER bit if the port is
527 * enabled, so this loop will sometimes require at least two
528 * iterations: one to disable the port and one to set OWNER.
529 */
57e06c11
AS
530 for (try = 4; try > 0; --try) {
531 spin_lock_irq(&ehci->lock);
532 port_status = ehci_readl(ehci, status_reg);
533 if ((port_status & PORT_OWNER) == new_owner
534 || (port_status & (PORT_OWNER | PORT_CONNECT))
535 == 0)
536 try = 0;
537 else {
538 port_status ^= PORT_OWNER;
539 port_status &= ~(PORT_PE | PORT_RWC_BITS);
540 ehci_writel(ehci, port_status, status_reg);
541 }
542 spin_unlock_irq(&ehci->lock);
543 if (try > 1)
544 msleep(5);
545 }
90da096e
BR
546}
547
1da177e4
LT
548/*-------------------------------------------------------------------------*/
549
550static int check_reset_complete (
551 struct ehci_hcd *ehci,
552 int index,
e6316565 553 u32 __iomem *status_reg,
1da177e4
LT
554 int port_status
555) {
cd4cdc93 556 if (!(port_status & PORT_CONNECT))
1da177e4 557 return port_status;
1da177e4
LT
558
559 /* if reset finished and it's still not enabled -- handoff */
560 if (!(port_status & PORT_PE)) {
561
562 /* with integrated TT, there's nobody to hand it to! */
563 if (ehci_is_TDI(ehci)) {
564 ehci_dbg (ehci,
565 "Failed to enable port %d on root hub TT\n",
566 index+1);
567 return port_status;
568 }
569
570 ehci_dbg (ehci, "port %d full speed --> companion\n",
571 index + 1);
572
573 // what happens if HCS_N_CC(params) == 0 ?
574 port_status |= PORT_OWNER;
10f6524a 575 port_status &= ~PORT_RWC_BITS;
e6316565 576 ehci_writel(ehci, port_status, status_reg);
1da177e4 577
796bcae7
VB
578 /* ensure 440EPX ohci controller state is operational */
579 if (ehci->has_amcc_usb23)
580 set_ohci_hcfs(ehci, 1);
581 } else {
0ca7eb23
PC
582 ehci_dbg(ehci, "port %d reset complete, port enabled\n",
583 index + 1);
796bcae7
VB
584 /* ensure 440EPx ohci controller state is suspended */
585 if (ehci->has_amcc_usb23)
586 set_ohci_hcfs(ehci, 0);
587 }
1da177e4
LT
588
589 return port_status;
590}
591
592/*-------------------------------------------------------------------------*/
593
594
595/* build "status change" packet (one or two bytes) from HC registers */
596
597static int
598ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
599{
600 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
a448e4dc 601 u32 temp, status;
93f1a47c 602 u32 mask;
1da177e4
LT
603 int ports, i, retval = 1;
604 unsigned long flags;
4dd405a4 605 u32 ppcd = ~0;
1da177e4 606
1da177e4
LT
607 /* init status to no-changes */
608 buf [0] = 0;
609 ports = HCS_N_PORTS (ehci->hcs_params);
610 if (ports > 7) {
611 buf [1] = 0;
612 retval++;
613 }
53bd6a60 614
a448e4dc
AS
615 /* Inform the core about resumes-in-progress by returning
616 * a non-zero value even if there are no status changes.
617 */
618 status = ehci->resuming_ports;
619
93f1a47c
DB
620 /* Some boards (mostly VIA?) report bogus overcurrent indications,
621 * causing massive log spam unless we completely ignore them. It
3a4fa0a2 622 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
93f1a47c
DB
623 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
624 * PORT_POWER; that's surprising, but maybe within-spec.
625 */
626 if (!ignore_oc)
627 mask = PORT_CSC | PORT_PEC | PORT_OCC;
628 else
629 mask = PORT_CSC | PORT_PEC;
630 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
631
1da177e4
LT
632 /* no hub change reports (bit 0) for now (power, ...) */
633
634 /* port N changes (bit N)? */
635 spin_lock_irqsave (&ehci->lock, flags);
5a9cdf33
AD
636
637 /* get per-port change detect bits */
638 if (ehci->has_ppcd)
639 ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
640
1da177e4 641 for (i = 0; i < ports; i++) {
5a9cdf33 642 /* leverage per-port change bits feature */
4dd405a4
AS
643 if (ppcd & (1 << i))
644 temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
645 else
646 temp = 0;
625b5c9a
AS
647
648 /*
649 * Return status information even for ports with OWNER set.
650 * Otherwise khubd wouldn't see the disconnect event when a
651 * high-speed device is switched over to the companion
652 * controller by the user.
653 */
654
eafe5b99
AS
655 if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend)
656 || (ehci->reset_done[i] && time_after_eq(
657 jiffies, ehci->reset_done[i]))) {
1da177e4
LT
658 if (i < 7)
659 buf [0] |= 1 << (i + 1);
660 else
661 buf [1] |= 1 << (i - 7);
662 status = STS_PCD;
663 }
664 }
ee74290b
AS
665
666 /* If a resume is in progress, make sure it can finish */
667 if (ehci->resuming_ports)
668 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(25));
669
1da177e4
LT
670 spin_unlock_irqrestore (&ehci->lock, flags);
671 return status ? retval : 0;
672}
673
674/*-------------------------------------------------------------------------*/
675
676static void
677ehci_hub_descriptor (
678 struct ehci_hcd *ehci,
679 struct usb_hub_descriptor *desc
680) {
681 int ports = HCS_N_PORTS (ehci->hcs_params);
682 u16 temp;
683
684 desc->bDescriptorType = 0x29;
685 desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
686 desc->bHubContrCurrent = 0;
687
688 desc->bNbrPorts = ports;
689 temp = 1 + (ports / 8);
690 desc->bDescLength = 7 + 2 * temp;
691
692 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
dbe79bbe
JY
693 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
694 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
1da177e4
LT
695
696 temp = 0x0008; /* per-port overcurrent reporting */
697 if (HCS_PPC (ehci->hcs_params))
698 temp |= 0x0001; /* per-port power control */
56c1e26d
DB
699 else
700 temp |= 0x0002; /* no power switching */
1da177e4
LT
701#if 0
702// re-enable when we support USB_PORT_FEAT_INDICATOR below.
703 if (HCS_INDICATOR (ehci->hcs_params))
704 temp |= 0x0080; /* per-port indicators (LEDs) */
705#endif
fd05e720 706 desc->wHubCharacteristics = cpu_to_le16(temp);
1da177e4
LT
707}
708
9841f37a 709/*-------------------------------------------------------------------------*/
726a85ca
JP
710#ifdef CONFIG_USB_HCD_TEST_MODE
711
9841f37a
MG
712#define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06
713
714static void usb_ehset_completion(struct urb *urb)
715{
716 struct completion *done = urb->context;
717
718 complete(done);
719}
720static int submit_single_step_set_feature(
721 struct usb_hcd *hcd,
722 struct urb *urb,
723 int is_setup
724);
725
726/*
727 * Allocate and initialize a control URB. This request will be used by the
728 * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages
729 * of the GetDescriptor request are sent 15 seconds after the SETUP stage.
730 * Return NULL if failed.
731 */
732static struct urb *request_single_step_set_feature_urb(
733 struct usb_device *udev,
734 void *dr,
735 void *buf,
736 struct completion *done
737) {
738 struct urb *urb;
739 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
740 struct usb_host_endpoint *ep;
741
742 urb = usb_alloc_urb(0, GFP_KERNEL);
743 if (!urb)
744 return NULL;
745
746 urb->pipe = usb_rcvctrlpipe(udev, 0);
747 ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out)
748 [usb_pipeendpoint(urb->pipe)];
749 if (!ep) {
750 usb_free_urb(urb);
751 return NULL;
752 }
753
754 urb->ep = ep;
755 urb->dev = udev;
756 urb->setup_packet = (void *)dr;
757 urb->transfer_buffer = buf;
758 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE;
759 urb->complete = usb_ehset_completion;
760 urb->status = -EINPROGRESS;
761 urb->actual_length = 0;
762 urb->transfer_flags = URB_DIR_IN;
763 usb_get_urb(urb);
764 atomic_inc(&urb->use_count);
765 atomic_inc(&urb->dev->urbnum);
766 urb->setup_dma = dma_map_single(
767 hcd->self.controller,
768 urb->setup_packet,
769 sizeof(struct usb_ctrlrequest),
770 DMA_TO_DEVICE);
771 urb->transfer_dma = dma_map_single(
772 hcd->self.controller,
773 urb->transfer_buffer,
774 urb->transfer_buffer_length,
775 DMA_FROM_DEVICE);
776 urb->context = done;
777 return urb;
778}
779
780static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
781{
782 int retval = -ENOMEM;
783 struct usb_ctrlrequest *dr;
784 struct urb *urb;
785 struct usb_device *udev;
786 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
787 struct usb_device_descriptor *buf;
788 DECLARE_COMPLETION_ONSTACK(done);
789
790 /* Obtain udev of the rhub's child port */
791 udev = usb_hub_find_child(hcd->self.root_hub, port);
792 if (!udev) {
793 ehci_err(ehci, "No device attached to the RootHub\n");
794 return -ENODEV;
795 }
796 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
797 if (!buf)
798 return -ENOMEM;
799
800 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
801 if (!dr) {
802 kfree(buf);
803 return -ENOMEM;
804 }
805
806 /* Fill Setup packet for GetDescriptor */
807 dr->bRequestType = USB_DIR_IN;
808 dr->bRequest = USB_REQ_GET_DESCRIPTOR;
809 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8);
810 dr->wIndex = 0;
811 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE);
812 urb = request_single_step_set_feature_urb(udev, dr, buf, &done);
813 if (!urb)
814 goto cleanup;
815
816 /* Submit just the SETUP stage */
817 retval = submit_single_step_set_feature(hcd, urb, 1);
818 if (retval)
819 goto out1;
820 if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) {
821 usb_kill_urb(urb);
822 retval = -ETIMEDOUT;
823 ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__);
824 goto out1;
825 }
826 msleep(15 * 1000);
827
828 /* Complete remaining DATA and STATUS stages using the same URB */
829 urb->status = -EINPROGRESS;
830 usb_get_urb(urb);
831 atomic_inc(&urb->use_count);
832 atomic_inc(&urb->dev->urbnum);
833 retval = submit_single_step_set_feature(hcd, urb, 0);
834 if (!retval && !wait_for_completion_timeout(&done,
835 msecs_to_jiffies(2000))) {
836 usb_kill_urb(urb);
837 retval = -ETIMEDOUT;
838 ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__);
839 }
840out1:
841 usb_free_urb(urb);
842cleanup:
843 kfree(dr);
844 kfree(buf);
845 return retval;
846}
726a85ca 847#endif /* CONFIG_USB_HCD_TEST_MODE */
1da177e4
LT
848/*-------------------------------------------------------------------------*/
849
1da177e4
LT
850static int ehci_hub_control (
851 struct usb_hcd *hcd,
852 u16 typeReq,
853 u16 wValue,
854 u16 wIndex,
855 char *buf,
856 u16 wLength
857) {
858 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
859 int ports = HCS_N_PORTS (ehci->hcs_params);
383975d7
AS
860 u32 __iomem *status_reg = &ehci->regs->port_status[
861 (wIndex & 0xff) - 1];
a46af4eb 862 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
331ac6b2 863 u32 temp, temp1, status;
1da177e4
LT
864 unsigned long flags;
865 int retval = 0;
f0d7f273 866 unsigned selector;
1da177e4
LT
867
868 /*
869 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
870 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
871 * (track current state ourselves) ... blink for diagnostics,
872 * power, "this is the one", etc. EHCI spec supports this.
873 */
874
875 spin_lock_irqsave (&ehci->lock, flags);
876 switch (typeReq) {
877 case ClearHubFeature:
878 switch (wValue) {
879 case C_HUB_LOCAL_POWER:
880 case C_HUB_OVER_CURRENT:
881 /* no hub-wide feature/status flags */
882 break;
883 default:
884 goto error;
885 }
886 break;
887 case ClearPortFeature:
888 if (!wIndex || wIndex > ports)
889 goto error;
890 wIndex--;
e6316565 891 temp = ehci_readl(ehci, status_reg);
6d5f89c7 892 temp &= ~PORT_RWC_BITS;
625b5c9a
AS
893
894 /*
895 * Even if OWNER is set, so the port is owned by the
896 * companion controller, khubd needs to be able to clear
897 * the port-change status bits (especially
749da5f8 898 * USB_PORT_STAT_C_CONNECTION).
625b5c9a 899 */
1da177e4
LT
900
901 switch (wValue) {
902 case USB_PORT_FEAT_ENABLE:
e6316565 903 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
1da177e4
LT
904 break;
905 case USB_PORT_FEAT_C_ENABLE:
6d5f89c7 906 ehci_writel(ehci, temp | PORT_PEC, status_reg);
1da177e4
LT
907 break;
908 case USB_PORT_FEAT_SUSPEND:
909 if (temp & PORT_RESET)
910 goto error;
f8aeb3bb
DB
911 if (ehci->no_selective_suspend)
912 break;
83722bc9
AG
913#ifdef CONFIG_USB_OTG
914 if ((hcd->self.otg_port == (wIndex + 1))
915 && hcd->self.b_hnp_enable) {
c2e935a7 916 otg_start_hnp(hcd->phy->otg);
83722bc9
AG
917 break;
918 }
919#endif
16032c4f
AS
920 if (!(temp & PORT_SUSPEND))
921 break;
922 if ((temp & PORT_PE) == 0)
923 goto error;
924
925 /* clear phy low-power mode before resume */
2cdcec4f 926 if (ehci->has_tdi_phy_lpm) {
16032c4f
AS
927 temp1 = ehci_readl(ehci, hostpc_reg);
928 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
eab80de0 929 hostpc_reg);
16032c4f
AS
930 spin_unlock_irqrestore(&ehci->lock, flags);
931 msleep(5);/* wait to leave low-power mode */
932 spin_lock_irqsave(&ehci->lock, flags);
1da177e4 933 }
16032c4f 934 /* resume signaling for 20 msec */
6d5f89c7 935 temp &= ~PORT_WAKE_BITS;
16032c4f
AS
936 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
937 ehci->reset_done[wIndex] = jiffies
938 + msecs_to_jiffies(20);
3a20446f
AS
939 set_bit(wIndex, &ehci->resuming_ports);
940 usb_hcd_start_port_resume(&hcd->self, wIndex);
1da177e4
LT
941 break;
942 case USB_PORT_FEAT_C_SUSPEND:
d1f114d1 943 clear_bit(wIndex, &ehci->port_c_suspend);
1da177e4
LT
944 break;
945 case USB_PORT_FEAT_POWER:
946 if (HCS_PPC (ehci->hcs_params))
6d5f89c7
SW
947 ehci_writel(ehci, temp & ~PORT_POWER,
948 status_reg);
1da177e4
LT
949 break;
950 case USB_PORT_FEAT_C_CONNECTION:
6d5f89c7 951 ehci_writel(ehci, temp | PORT_CSC, status_reg);
1da177e4
LT
952 break;
953 case USB_PORT_FEAT_C_OVER_CURRENT:
6d5f89c7 954 ehci_writel(ehci, temp | PORT_OCC, status_reg);
1da177e4
LT
955 break;
956 case USB_PORT_FEAT_C_RESET:
957 /* GetPortStatus clears reset */
958 break;
959 default:
960 goto error;
961 }
083522d7 962 ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
1da177e4
LT
963 break;
964 case GetHubDescriptor:
965 ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
966 buf);
967 break;
968 case GetHubStatus:
969 /* no hub-wide feature/status flags */
970 memset (buf, 0, 4);
971 //cpu_to_le32s ((u32 *) buf);
972 break;
973 case GetPortStatus:
974 if (!wIndex || wIndex > ports)
975 goto error;
976 wIndex--;
977 status = 0;
e6316565 978 temp = ehci_readl(ehci, status_reg);
1da177e4
LT
979
980 // wPortChange bits
981 if (temp & PORT_CSC)
749da5f8 982 status |= USB_PORT_STAT_C_CONNECTION << 16;
1da177e4 983 if (temp & PORT_PEC)
749da5f8 984 status |= USB_PORT_STAT_C_ENABLE << 16;
756aa6b3
CE
985
986 if ((temp & PORT_OCC) && !ignore_oc){
749da5f8 987 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
1da177e4 988
756aa6b3
CE
989 /*
990 * Hubs should disable port power on over-current.
991 * However, not all EHCI implementations do this
992 * automatically, even if they _do_ support per-port
993 * power switching; they're allowed to just limit the
994 * current. khubd will turn the power back on.
995 */
e6604a7f
CE
996 if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
997 && HCS_PPC(ehci->hcs_params)) {
756aa6b3
CE
998 ehci_writel(ehci,
999 temp & ~(PORT_RWC_BITS | PORT_POWER),
1000 status_reg);
81463c1d 1001 temp = ehci_readl(ehci, status_reg);
756aa6b3
CE
1002 }
1003 }
1004
6753f4cf
AS
1005 /* no reset or resume pending */
1006 if (!ehci->reset_done[wIndex]) {
629e4427
AS
1007
1008 /* Remote Wakeup received? */
6753f4cf 1009 if (temp & PORT_RESUME) {
629e4427
AS
1010 /* resume signaling for 20 msec */
1011 ehci->reset_done[wIndex] = jiffies
1012 + msecs_to_jiffies(20);
f292e7f9 1013 usb_hcd_start_port_resume(&hcd->self, wIndex);
47a64a13 1014 set_bit(wIndex, &ehci->resuming_ports);
629e4427
AS
1015 /* check the port again */
1016 mod_timer(&ehci_to_hcd(ehci)->rh_timer,
1017 ehci->reset_done[wIndex]);
1018 }
1da177e4 1019
6753f4cf
AS
1020 /* reset or resume not yet complete */
1021 } else if (!time_after_eq(jiffies, ehci->reset_done[wIndex])) {
1022 ; /* wait until it is complete */
1023
1024 /* resume completed */
1025 } else if (test_bit(wIndex, &ehci->resuming_ports)) {
1026 clear_bit(wIndex, &ehci->suspended_ports);
1027 set_bit(wIndex, &ehci->port_c_suspend);
1028 ehci->reset_done[wIndex] = 0;
1029 usb_hcd_end_port_resume(&hcd->self, wIndex);
1030
1031 /* stop resume signaling */
1032 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
1033 ehci_writel(ehci, temp, status_reg);
1034 clear_bit(wIndex, &ehci->resuming_ports);
1035 retval = ehci_handshake(ehci, status_reg,
1036 PORT_RESUME, 0, 2000 /* 2msec */);
1037 if (retval != 0) {
1038 ehci_err(ehci, "port %d resume error %d\n",
629e4427 1039 wIndex + 1, retval);
6753f4cf 1040 goto error;
1da177e4 1041 }
6753f4cf 1042 temp = ehci_readl(ehci, status_reg);
1da177e4
LT
1043
1044 /* whoever resets must GetPortStatus to complete it!! */
6753f4cf 1045 } else {
749da5f8 1046 status |= USB_PORT_STAT_C_RESET << 16;
1da177e4
LT
1047 ehci->reset_done [wIndex] = 0;
1048
1049 /* force reset to complete */
083522d7 1050 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
e6316565 1051 status_reg);
c22fa3ac
DB
1052 /* REVISIT: some hardware needs 550+ usec to clear
1053 * this bit; seems too long to spin routinely...
1054 */
2f3a6b86 1055 retval = ehci_handshake(ehci, status_reg,
6307e096 1056 PORT_RESET, 0, 1000);
1da177e4
LT
1057 if (retval != 0) {
1058 ehci_err (ehci, "port %d reset error %d\n",
1059 wIndex + 1, retval);
1060 goto error;
1061 }
1062
1063 /* see what we found out */
e6316565
AS
1064 temp = check_reset_complete (ehci, wIndex, status_reg,
1065 ehci_readl(ehci, status_reg));
1da177e4
LT
1066 }
1067
57e06c11
AS
1068 /* transfer dedicated ports to the companion hc */
1069 if ((temp & PORT_CONNECT) &&
1070 test_bit(wIndex, &ehci->companion_ports)) {
1071 temp &= ~PORT_RWC_BITS;
1072 temp |= PORT_OWNER;
1073 ehci_writel(ehci, temp, status_reg);
1074 ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
1075 temp = ehci_readl(ehci, status_reg);
1076 }
1077
625b5c9a
AS
1078 /*
1079 * Even if OWNER is set, there's no harm letting khubd
1080 * see the wPortStatus values (they should all be 0 except
1081 * for PORT_POWER anyway).
1082 */
1083
1084 if (temp & PORT_CONNECT) {
749da5f8 1085 status |= USB_PORT_STAT_CONNECTION;
625b5c9a 1086 // status may be from integrated TT
331ac6b2
AD
1087 if (ehci->has_hostpc) {
1088 temp1 = ehci_readl(ehci, hostpc_reg);
1089 status |= ehci_port_speed(ehci, temp1);
1090 } else
1091 status |= ehci_port_speed(ehci, temp);
1da177e4 1092 }
625b5c9a 1093 if (temp & PORT_PE)
749da5f8 1094 status |= USB_PORT_STAT_ENABLE;
eafe5b99
AS
1095
1096 /* maybe the port was unsuspended without our knowledge */
1097 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
749da5f8 1098 status |= USB_PORT_STAT_SUSPEND;
eafe5b99
AS
1099 } else if (test_bit(wIndex, &ehci->suspended_ports)) {
1100 clear_bit(wIndex, &ehci->suspended_ports);
a448e4dc 1101 clear_bit(wIndex, &ehci->resuming_ports);
eafe5b99
AS
1102 ehci->reset_done[wIndex] = 0;
1103 if (temp & PORT_PE)
1104 set_bit(wIndex, &ehci->port_c_suspend);
f292e7f9 1105 usb_hcd_end_port_resume(&hcd->self, wIndex);
eafe5b99
AS
1106 }
1107
625b5c9a 1108 if (temp & PORT_OC)
749da5f8 1109 status |= USB_PORT_STAT_OVERCURRENT;
625b5c9a 1110 if (temp & PORT_RESET)
749da5f8 1111 status |= USB_PORT_STAT_RESET;
625b5c9a 1112 if (temp & PORT_POWER)
749da5f8 1113 status |= USB_PORT_STAT_POWER;
d1f114d1 1114 if (test_bit(wIndex, &ehci->port_c_suspend))
749da5f8 1115 status |= USB_PORT_STAT_C_SUSPEND << 16;
1da177e4 1116
9776afc8 1117#ifndef VERBOSE_DEBUG
1da177e4
LT
1118 if (status & ~0xffff) /* only if wPortChange is interesting */
1119#endif
1120 dbg_port (ehci, "GetStatus", wIndex + 1, temp);
a5abdeaf 1121 put_unaligned_le32(status, buf);
1da177e4
LT
1122 break;
1123 case SetHubFeature:
1124 switch (wValue) {
1125 case C_HUB_LOCAL_POWER:
1126 case C_HUB_OVER_CURRENT:
1127 /* no hub-wide feature/status flags */
1128 break;
1129 default:
1130 goto error;
1131 }
1132 break;
1133 case SetPortFeature:
f0d7f273
DB
1134 selector = wIndex >> 8;
1135 wIndex &= 0xff;
8d053c79
JW
1136 if (unlikely(ehci->debug)) {
1137 /* If the debug port is active any port
1138 * feature requests should get denied */
1139 if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
1140 (readl(&ehci->debug->control) & DBGP_ENABLED)) {
1141 retval = -ENODEV;
1142 goto error_exit;
1143 }
1144 }
1da177e4
LT
1145 if (!wIndex || wIndex > ports)
1146 goto error;
1147 wIndex--;
e6316565 1148 temp = ehci_readl(ehci, status_reg);
1da177e4
LT
1149 if (temp & PORT_OWNER)
1150 break;
1151
10f6524a 1152 temp &= ~PORT_RWC_BITS;
1da177e4
LT
1153 switch (wValue) {
1154 case USB_PORT_FEAT_SUSPEND:
f8aeb3bb
DB
1155 if (ehci->no_selective_suspend)
1156 break;
1da177e4
LT
1157 if ((temp & PORT_PE) == 0
1158 || (temp & PORT_RESET) != 0)
1159 goto error;
b9df7942 1160
331ac6b2
AD
1161 /* After above check the port must be connected.
1162 * Set appropriate bit thus could put phy into low power
2cdcec4f 1163 * mode if we have tdi_phy_lpm feature
331ac6b2 1164 */
b9df7942
AD
1165 temp &= ~PORT_WKCONN_E;
1166 temp |= PORT_WKDISC_E | PORT_WKOC_E;
1167 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
2cdcec4f 1168 if (ehci->has_tdi_phy_lpm) {
b9df7942 1169 spin_unlock_irqrestore(&ehci->lock, flags);
331ac6b2 1170 msleep(5);/* 5ms for HCD enter low pwr mode */
b9df7942 1171 spin_lock_irqsave(&ehci->lock, flags);
331ac6b2
AD
1172 temp1 = ehci_readl(ehci, hostpc_reg);
1173 ehci_writel(ehci, temp1 | HOSTPC_PHCD,
1174 hostpc_reg);
1175 temp1 = ehci_readl(ehci, hostpc_reg);
1176 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
1177 wIndex, (temp1 & HOSTPC_PHCD) ?
1178 "succeeded" : "failed");
1179 }
eafe5b99 1180 set_bit(wIndex, &ehci->suspended_ports);
1da177e4
LT
1181 break;
1182 case USB_PORT_FEAT_POWER:
1183 if (HCS_PPC (ehci->hcs_params))
083522d7 1184 ehci_writel(ehci, temp | PORT_POWER,
e6316565 1185 status_reg);
1da177e4
LT
1186 break;
1187 case USB_PORT_FEAT_RESET:
6753f4cf 1188 if (temp & (PORT_SUSPEND|PORT_RESUME))
1da177e4
LT
1189 goto error;
1190 /* line status bits may report this as low speed,
1191 * which can be fine if this root hub has a
1192 * transaction translator built in.
1193 */
1194 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1195 && !ehci_is_TDI(ehci)
1196 && PORT_USB11 (temp)) {
1197 ehci_dbg (ehci,
1198 "port %d low speed --> companion\n",
1199 wIndex + 1);
1200 temp |= PORT_OWNER;
1201 } else {
1da177e4
LT
1202 temp |= PORT_RESET;
1203 temp &= ~PORT_PE;
1204
1205 /*
1206 * caller must wait, then call GetPortStatus
1207 * usb 2.0 spec says 50 ms resets on root
1208 */
1209 ehci->reset_done [wIndex] = jiffies
1210 + msecs_to_jiffies (50);
1211 }
e6316565 1212 ehci_writel(ehci, temp, status_reg);
1da177e4 1213 break;
f0d7f273
DB
1214
1215 /* For downstream facing ports (these): one hub port is put
1216 * into test mode according to USB2 11.24.2.13, then the hub
1217 * must be reset (which for root hub now means rmmod+modprobe,
1218 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1219 * about the EHCI-specific stuff.
1220 */
1221 case USB_PORT_FEAT_TEST:
726a85ca 1222#ifdef CONFIG_USB_HCD_TEST_MODE
9841f37a
MG
1223 if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
1224 spin_unlock_irqrestore(&ehci->lock, flags);
1225 retval = ehset_single_step_set_feature(hcd,
1226 wIndex);
1227 spin_lock_irqsave(&ehci->lock, flags);
1228 break;
726a85ca
JP
1229 }
1230#endif
1231 if (!selector || selector > 5)
f0d7f273 1232 goto error;
c4f34764 1233 spin_unlock_irqrestore(&ehci->lock, flags);
f0d7f273 1234 ehci_quiesce(ehci);
c4f34764 1235 spin_lock_irqsave(&ehci->lock, flags);
77636c86
BT
1236
1237 /* Put all enabled ports into suspend */
1238 while (ports--) {
1239 u32 __iomem *sreg =
1240 &ehci->regs->port_status[ports];
1241
1242 temp = ehci_readl(ehci, sreg) & ~PORT_RWC_BITS;
1243 if (temp & PORT_PE)
1244 ehci_writel(ehci, temp | PORT_SUSPEND,
1245 sreg);
1246 }
c4f34764
AS
1247
1248 spin_unlock_irqrestore(&ehci->lock, flags);
f0d7f273 1249 ehci_halt(ehci);
c4f34764
AS
1250 spin_lock_irqsave(&ehci->lock, flags);
1251
77636c86 1252 temp = ehci_readl(ehci, status_reg);
f0d7f273 1253 temp |= selector << 16;
e6316565 1254 ehci_writel(ehci, temp, status_reg);
f0d7f273
DB
1255 break;
1256
1da177e4
LT
1257 default:
1258 goto error;
1259 }
083522d7 1260 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
1da177e4
LT
1261 break;
1262
1263 default:
1264error:
1265 /* "stall" on error */
1266 retval = -EPIPE;
1267 }
8d053c79 1268error_exit:
1da177e4
LT
1269 spin_unlock_irqrestore (&ehci->lock, flags);
1270 return retval;
1271}
90da096e 1272
3e023203 1273static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
90da096e
BR
1274{
1275 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1276
1277 if (ehci_is_TDI(ehci))
1278 return;
1279 set_owner(ehci, --portnum, PORT_OWNER);
1280}
1281
3e023203 1282static int ehci_port_handed_over(struct usb_hcd *hcd, int portnum)
3a31155c
AS
1283{
1284 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1285 u32 __iomem *reg;
1286
1287 if (ehci_is_TDI(ehci))
1288 return 0;
1289 reg = &ehci->regs->port_status[portnum - 1];
1290 return ehci_readl(ehci, reg) & PORT_OWNER;
1291}
This page took 0.903369 seconds and 5 git commands to generate.