2 * Copyright (C) 2001-2004 by David Brownell
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.
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
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.
19 /* this file is part of ehci-hcd.c */
21 /*-------------------------------------------------------------------------*/
24 * EHCI Root Hub ... the nonsharable stuff
26 * Registers don't need cpu_to_le32, that happens transparently
29 /*-------------------------------------------------------------------------*/
31 #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
35 static int ehci_hub_control(
44 /* After a power loss, ports that were owned by the companion must be
45 * reset so that the companion can still own them.
47 static void ehci_handover_companion_ports(struct ehci_hcd
*ehci
)
53 struct usb_hcd
*hcd
= ehci_to_hcd(ehci
);
55 if (!ehci
->owned_ports
)
58 /* Give the connections some time to appear */
61 port
= HCS_N_PORTS(ehci
->hcs_params
);
63 if (test_bit(port
, &ehci
->owned_ports
)) {
64 reg
= &ehci
->regs
->port_status
[port
];
65 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
67 /* Port already owned by companion? */
68 if (status
& PORT_OWNER
)
69 clear_bit(port
, &ehci
->owned_ports
);
70 else if (test_bit(port
, &ehci
->companion_ports
))
71 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
73 ehci_hub_control(hcd
, SetPortFeature
,
74 USB_PORT_FEAT_RESET
, port
+ 1,
79 if (!ehci
->owned_ports
)
81 msleep(90); /* Wait for resets to complete */
83 port
= HCS_N_PORTS(ehci
->hcs_params
);
85 if (test_bit(port
, &ehci
->owned_ports
)) {
86 ehci_hub_control(hcd
, GetPortStatus
,
88 (char *) &buf
, sizeof(buf
));
90 /* The companion should now own the port,
91 * but if something went wrong the port must not
94 reg
= &ehci
->regs
->port_status
[port
];
95 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
96 if (status
& PORT_OWNER
)
97 ehci_writel(ehci
, status
| PORT_CSC
, reg
);
99 ehci_dbg(ehci
, "failed handover port %d: %x\n",
101 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
106 ehci
->owned_ports
= 0;
109 static void ehci_adjust_port_wakeup_flags(struct ehci_hcd
*ehci
,
110 bool suspending
, bool do_wakeup
)
116 /* If remote wakeup is enabled for the root hub but disabled
117 * for the controller, we must adjust all the port wakeup flags
118 * when the controller is suspended or resumed. In all other
119 * cases they don't need to be changed.
121 if (!ehci_to_hcd(ehci
)->self
.root_hub
->do_remote_wakeup
|| do_wakeup
)
124 spin_lock_irqsave(&ehci
->lock
, flags
);
126 /* clear phy low-power mode before changing wakeup flags */
127 if (ehci
->has_hostpc
) {
128 port
= HCS_N_PORTS(ehci
->hcs_params
);
130 u32 __iomem
*hostpc_reg
;
132 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
133 + HOSTPC0
+ 4 * port
);
134 temp
= ehci_readl(ehci
, hostpc_reg
);
135 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
, hostpc_reg
);
137 spin_unlock_irqrestore(&ehci
->lock
, flags
);
139 spin_lock_irqsave(&ehci
->lock
, flags
);
142 port
= HCS_N_PORTS(ehci
->hcs_params
);
144 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
145 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
146 u32 t2
= t1
& ~PORT_WAKE_BITS
;
148 /* If we are suspending the controller, clear the flags.
149 * If we are resuming the controller, set the wakeup flags.
152 if (t1
& PORT_CONNECT
)
153 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
155 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
157 ehci_vdbg(ehci
, "port %d, %08x -> %08x\n",
159 ehci_writel(ehci
, t2
, reg
);
162 /* enter phy low-power mode again */
163 if (ehci
->has_hostpc
) {
164 port
= HCS_N_PORTS(ehci
->hcs_params
);
166 u32 __iomem
*hostpc_reg
;
168 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
169 + HOSTPC0
+ 4 * port
);
170 temp
= ehci_readl(ehci
, hostpc_reg
);
171 ehci_writel(ehci
, temp
| HOSTPC_PHCD
, hostpc_reg
);
175 /* Does the root hub have a port wakeup pending? */
176 if (!suspending
&& (ehci_readl(ehci
, &ehci
->regs
->status
) & STS_PCD
))
177 usb_hcd_resume_root_hub(ehci_to_hcd(ehci
));
179 spin_unlock_irqrestore(&ehci
->lock
, flags
);
182 static int ehci_bus_suspend (struct usb_hcd
*hcd
)
184 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
189 ehci_dbg(ehci
, "suspend root hub\n");
191 if (time_before (jiffies
, ehci
->next_statechange
))
193 del_timer_sync(&ehci
->watchdog
);
194 del_timer_sync(&ehci
->iaa_watchdog
);
196 spin_lock_irq (&ehci
->lock
);
198 /* Once the controller is stopped, port resumes that are already
199 * in progress won't complete. Hence if remote wakeup is enabled
200 * for the root hub and any ports are in the middle of a resume or
201 * remote wakeup, we must fail the suspend.
203 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
204 port
= HCS_N_PORTS(ehci
->hcs_params
);
206 if (ehci
->reset_done
[port
] != 0) {
207 spin_unlock_irq(&ehci
->lock
);
208 ehci_dbg(ehci
, "suspend failed because "
209 "port %d is resuming\n",
216 /* stop schedules, clean any completed work */
217 if (HC_IS_RUNNING(hcd
->state
)) {
219 hcd
->state
= HC_STATE_QUIESCING
;
221 ehci
->command
= ehci_readl(ehci
, &ehci
->regs
->command
);
224 /* Unlike other USB host controller types, EHCI doesn't have
225 * any notion of "global" or bus-wide suspend. The driver has
226 * to manually suspend all the active unsuspended ports, and
227 * then manually resume them in the bus_resume() routine.
229 ehci
->bus_suspended
= 0;
230 ehci
->owned_ports
= 0;
232 port
= HCS_N_PORTS(ehci
->hcs_params
);
234 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
235 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
236 u32 t2
= t1
& ~PORT_WAKE_BITS
;
238 /* keep track of which ports we suspend */
240 set_bit(port
, &ehci
->owned_ports
);
241 else if ((t1
& PORT_PE
) && !(t1
& PORT_SUSPEND
)) {
243 set_bit(port
, &ehci
->bus_suspended
);
246 /* enable remote wakeup on all ports, if told to do so */
247 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
248 /* only enable appropriate wake bits, otherwise the
249 * hardware can not go phy low power mode. If a race
250 * condition happens here(connection change during bits
251 * set), the port change detection will finally fix it.
253 if (t1
& PORT_CONNECT
)
254 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
256 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
260 ehci_vdbg (ehci
, "port %d, %08x -> %08x\n",
262 ehci_writel(ehci
, t2
, reg
);
267 if (changed
&& ehci
->has_hostpc
) {
268 spin_unlock_irq(&ehci
->lock
);
269 msleep(5); /* 5 ms for HCD to enter low-power mode */
270 spin_lock_irq(&ehci
->lock
);
272 port
= HCS_N_PORTS(ehci
->hcs_params
);
274 u32 __iomem
*hostpc_reg
;
277 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
278 + HOSTPC0
+ 4 * port
);
279 t3
= ehci_readl(ehci
, hostpc_reg
);
280 ehci_writel(ehci
, t3
| HOSTPC_PHCD
, hostpc_reg
);
281 t3
= ehci_readl(ehci
, hostpc_reg
);
282 ehci_dbg(ehci
, "Port %d phy low-power mode %s\n",
283 port
, (t3
& HOSTPC_PHCD
) ?
284 "succeeded" : "failed");
288 /* Apparently some devices need a >= 1-uframe delay here */
289 if (ehci
->bus_suspended
)
292 /* turn off now-idle HC */
294 hcd
->state
= HC_STATE_SUSPENDED
;
297 end_unlink_async(ehci
);
299 /* allow remote wakeup */
301 if (!hcd
->self
.root_hub
->do_remote_wakeup
)
303 ehci_writel(ehci
, mask
, &ehci
->regs
->intr_enable
);
304 ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
306 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(10);
307 spin_unlock_irq (&ehci
->lock
);
309 /* ehci_work() may have re-enabled the watchdog timer, which we do not
310 * want, and so we must delete any pending watchdog timer events.
312 del_timer_sync(&ehci
->watchdog
);
317 /* caller has locked the root hub, and should reset/reinit on error */
318 static int ehci_bus_resume (struct usb_hcd
*hcd
)
320 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
324 u8 resume_needed
= 0;
326 if (time_before (jiffies
, ehci
->next_statechange
))
328 spin_lock_irq (&ehci
->lock
);
329 if (!HCD_HW_ACCESSIBLE(hcd
)) {
330 spin_unlock_irq(&ehci
->lock
);
334 if (unlikely(ehci
->debug
)) {
335 if (!dbgp_reset_prep())
338 dbgp_external_startup();
341 /* Ideally and we've got a real resume here, and no port's power
342 * was lost. (For PCI, that means Vaux was maintained.) But we
343 * could instead be restoring a swsusp snapshot -- so that BIOS was
344 * the last user of the controller, not reset/pm hardware keeping
345 * state we gave to it.
347 power_okay
= ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
348 ehci_dbg(ehci
, "resume root hub%s\n",
349 power_okay
? "" : " after power loss");
351 /* at least some APM implementations will try to deliver
352 * IRQs right away, so delay them until we're ready.
354 ehci_writel(ehci
, 0, &ehci
->regs
->intr_enable
);
356 /* re-init operational registers */
357 ehci_writel(ehci
, 0, &ehci
->regs
->segment
);
358 ehci_writel(ehci
, ehci
->periodic_dma
, &ehci
->regs
->frame_list
);
359 ehci_writel(ehci
, (u32
) ehci
->async
->qh_dma
, &ehci
->regs
->async_next
);
361 /* restore CMD_RUN, framelist size, and irq threshold */
362 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
364 /* Some controller/firmware combinations need a delay during which
365 * they set up the port statuses. See Bugzilla #8190. */
366 spin_unlock_irq(&ehci
->lock
);
368 spin_lock_irq(&ehci
->lock
);
370 /* clear phy low-power mode before resume */
371 if (ehci
->bus_suspended
&& ehci
->has_hostpc
) {
372 i
= HCS_N_PORTS(ehci
->hcs_params
);
374 if (test_bit(i
, &ehci
->bus_suspended
)) {
375 u32 __iomem
*hostpc_reg
;
377 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
379 temp
= ehci_readl(ehci
, hostpc_reg
);
380 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
,
384 spin_unlock_irq(&ehci
->lock
);
386 spin_lock_irq(&ehci
->lock
);
389 /* manually resume the ports we suspended during bus_suspend() */
390 i
= HCS_N_PORTS (ehci
->hcs_params
);
392 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
393 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
394 if (test_bit(i
, &ehci
->bus_suspended
) &&
395 (temp
& PORT_SUSPEND
)) {
399 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
402 /* msleep for 20ms only if code is trying to resume port */
404 spin_unlock_irq(&ehci
->lock
);
406 spin_lock_irq(&ehci
->lock
);
409 i
= HCS_N_PORTS (ehci
->hcs_params
);
411 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
412 if (test_bit(i
, &ehci
->bus_suspended
) &&
413 (temp
& PORT_SUSPEND
)) {
414 temp
&= ~(PORT_RWC_BITS
| PORT_RESUME
);
415 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
416 ehci_vdbg (ehci
, "resumed port %d\n", i
+ 1);
419 (void) ehci_readl(ehci
, &ehci
->regs
->command
);
421 /* maybe re-activate the schedule(s) */
423 if (ehci
->async
->qh_next
.qh
)
425 if (ehci
->periodic_sched
)
428 ehci
->command
|= temp
;
429 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
432 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
433 hcd
->state
= HC_STATE_RUNNING
;
435 /* Now we can safely re-enable irqs */
436 ehci_writel(ehci
, INTR_MASK
, &ehci
->regs
->intr_enable
);
438 spin_unlock_irq (&ehci
->lock
);
439 ehci_handover_companion_ports(ehci
);
445 #define ehci_bus_suspend NULL
446 #define ehci_bus_resume NULL
448 #endif /* CONFIG_PM */
450 /*-------------------------------------------------------------------------*/
452 /* Display the ports dedicated to the companion controller */
453 static ssize_t
show_companion(struct device
*dev
,
454 struct device_attribute
*attr
,
457 struct ehci_hcd
*ehci
;
458 int nports
, index
, n
;
459 int count
= PAGE_SIZE
;
462 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
463 nports
= HCS_N_PORTS(ehci
->hcs_params
);
465 for (index
= 0; index
< nports
; ++index
) {
466 if (test_bit(index
, &ehci
->companion_ports
)) {
467 n
= scnprintf(ptr
, count
, "%d\n", index
+ 1);
476 * Sets the owner of a port
478 static void set_owner(struct ehci_hcd
*ehci
, int portnum
, int new_owner
)
480 u32 __iomem
*status_reg
;
484 status_reg
= &ehci
->regs
->port_status
[portnum
];
487 * The controller won't set the OWNER bit if the port is
488 * enabled, so this loop will sometimes require at least two
489 * iterations: one to disable the port and one to set OWNER.
491 for (try = 4; try > 0; --try) {
492 spin_lock_irq(&ehci
->lock
);
493 port_status
= ehci_readl(ehci
, status_reg
);
494 if ((port_status
& PORT_OWNER
) == new_owner
495 || (port_status
& (PORT_OWNER
| PORT_CONNECT
))
499 port_status
^= PORT_OWNER
;
500 port_status
&= ~(PORT_PE
| PORT_RWC_BITS
);
501 ehci_writel(ehci
, port_status
, status_reg
);
503 spin_unlock_irq(&ehci
->lock
);
510 * Dedicate or undedicate a port to the companion controller.
511 * Syntax is "[-]portnum", where a leading '-' sign means
512 * return control of the port to the EHCI controller.
514 static ssize_t
store_companion(struct device
*dev
,
515 struct device_attribute
*attr
,
516 const char *buf
, size_t count
)
518 struct ehci_hcd
*ehci
;
519 int portnum
, new_owner
;
521 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
522 new_owner
= PORT_OWNER
; /* Owned by companion */
523 if (sscanf(buf
, "%d", &portnum
) != 1)
527 new_owner
= 0; /* Owned by EHCI */
529 if (portnum
<= 0 || portnum
> HCS_N_PORTS(ehci
->hcs_params
))
533 set_bit(portnum
, &ehci
->companion_ports
);
535 clear_bit(portnum
, &ehci
->companion_ports
);
536 set_owner(ehci
, portnum
, new_owner
);
539 static DEVICE_ATTR(companion
, 0644, show_companion
, store_companion
);
541 static inline void create_companion_file(struct ehci_hcd
*ehci
)
545 /* with integrated TT there is no companion! */
546 if (!ehci_is_TDI(ehci
))
547 i
= device_create_file(ehci_to_hcd(ehci
)->self
.controller
,
548 &dev_attr_companion
);
551 static inline void remove_companion_file(struct ehci_hcd
*ehci
)
553 /* with integrated TT there is no companion! */
554 if (!ehci_is_TDI(ehci
))
555 device_remove_file(ehci_to_hcd(ehci
)->self
.controller
,
556 &dev_attr_companion
);
560 /*-------------------------------------------------------------------------*/
562 static int check_reset_complete (
563 struct ehci_hcd
*ehci
,
565 u32 __iomem
*status_reg
,
568 if (!(port_status
& PORT_CONNECT
))
571 /* if reset finished and it's still not enabled -- handoff */
572 if (!(port_status
& PORT_PE
)) {
574 /* with integrated TT, there's nobody to hand it to! */
575 if (ehci_is_TDI(ehci
)) {
577 "Failed to enable port %d on root hub TT\n",
582 ehci_dbg (ehci
, "port %d full speed --> companion\n",
585 // what happens if HCS_N_CC(params) == 0 ?
586 port_status
|= PORT_OWNER
;
587 port_status
&= ~PORT_RWC_BITS
;
588 ehci_writel(ehci
, port_status
, status_reg
);
590 /* ensure 440EPX ohci controller state is operational */
591 if (ehci
->has_amcc_usb23
)
592 set_ohci_hcfs(ehci
, 1);
594 ehci_dbg (ehci
, "port %d high speed\n", index
+ 1);
595 /* ensure 440EPx ohci controller state is suspended */
596 if (ehci
->has_amcc_usb23
)
597 set_ohci_hcfs(ehci
, 0);
603 /*-------------------------------------------------------------------------*/
606 /* build "status change" packet (one or two bytes) from HC registers */
609 ehci_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
611 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
612 u32 temp
, status
= 0;
614 int ports
, i
, retval
= 1;
618 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
619 if (!HC_IS_RUNNING(hcd
->state
))
622 /* init status to no-changes */
624 ports
= HCS_N_PORTS (ehci
->hcs_params
);
630 /* Some boards (mostly VIA?) report bogus overcurrent indications,
631 * causing massive log spam unless we completely ignore them. It
632 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
633 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
634 * PORT_POWER; that's surprising, but maybe within-spec.
637 mask
= PORT_CSC
| PORT_PEC
| PORT_OCC
;
639 mask
= PORT_CSC
| PORT_PEC
;
640 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
642 /* no hub change reports (bit 0) for now (power, ...) */
644 /* port N changes (bit N)? */
645 spin_lock_irqsave (&ehci
->lock
, flags
);
647 /* get per-port change detect bits */
649 ppcd
= ehci_readl(ehci
, &ehci
->regs
->status
) >> 16;
651 for (i
= 0; i
< ports
; i
++) {
652 /* leverage per-port change bits feature */
653 if (ehci
->has_ppcd
&& !(ppcd
& (1 << i
)))
655 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
658 * Return status information even for ports with OWNER set.
659 * Otherwise khubd wouldn't see the disconnect event when a
660 * high-speed device is switched over to the companion
661 * controller by the user.
664 if ((temp
& mask
) != 0 || test_bit(i
, &ehci
->port_c_suspend
)
665 || (ehci
->reset_done
[i
] && time_after_eq(
666 jiffies
, ehci
->reset_done
[i
]))) {
668 buf
[0] |= 1 << (i
+ 1);
670 buf
[1] |= 1 << (i
- 7);
674 spin_unlock_irqrestore (&ehci
->lock
, flags
);
675 return status
? retval
: 0;
678 /*-------------------------------------------------------------------------*/
681 ehci_hub_descriptor (
682 struct ehci_hcd
*ehci
,
683 struct usb_hub_descriptor
*desc
685 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
688 desc
->bDescriptorType
= 0x29;
689 desc
->bPwrOn2PwrGood
= 10; /* ehci 1.0, 2.3.9 says 20ms max */
690 desc
->bHubContrCurrent
= 0;
692 desc
->bNbrPorts
= ports
;
693 temp
= 1 + (ports
/ 8);
694 desc
->bDescLength
= 7 + 2 * temp
;
696 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
697 memset (&desc
->bitmap
[0], 0, temp
);
698 memset (&desc
->bitmap
[temp
], 0xff, temp
);
700 temp
= 0x0008; /* per-port overcurrent reporting */
701 if (HCS_PPC (ehci
->hcs_params
))
702 temp
|= 0x0001; /* per-port power control */
704 temp
|= 0x0002; /* no power switching */
705 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
708 /*-------------------------------------------------------------------------*/
710 static int ehci_hub_control (
718 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
719 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
720 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
721 (wIndex
& 0xff) - 1];
722 u32 __iomem
*hostpc_reg
= NULL
;
723 u32 temp
, temp1
, status
;
729 if (ehci
->has_hostpc
)
730 hostpc_reg
= (u32 __iomem
*)((u8
*)ehci
->regs
731 + HOSTPC0
+ 4 * ((wIndex
& 0xff) - 1));
732 spin_lock_irqsave (&ehci
->lock
, flags
);
734 case ClearHubFeature
:
736 case C_HUB_LOCAL_POWER
:
737 case C_HUB_OVER_CURRENT
:
738 /* no hub-wide feature/status flags */
744 case ClearPortFeature
:
745 if (!wIndex
|| wIndex
> ports
)
748 temp
= ehci_readl(ehci
, status_reg
);
751 * Even if OWNER is set, so the port is owned by the
752 * companion controller, khubd needs to be able to clear
753 * the port-change status bits (especially
754 * USB_PORT_STAT_C_CONNECTION).
758 case USB_PORT_FEAT_ENABLE
:
759 ehci_writel(ehci
, temp
& ~PORT_PE
, status_reg
);
761 case USB_PORT_FEAT_C_ENABLE
:
762 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_PEC
,
765 case USB_PORT_FEAT_SUSPEND
:
766 if (temp
& PORT_RESET
)
768 if (ehci
->no_selective_suspend
)
770 if (!(temp
& PORT_SUSPEND
))
772 if ((temp
& PORT_PE
) == 0)
775 /* clear phy low-power mode before resume */
777 temp1
= ehci_readl(ehci
, hostpc_reg
);
778 ehci_writel(ehci
, temp1
& ~HOSTPC_PHCD
,
780 spin_unlock_irqrestore(&ehci
->lock
, flags
);
781 msleep(5);/* wait to leave low-power mode */
782 spin_lock_irqsave(&ehci
->lock
, flags
);
784 /* resume signaling for 20 msec */
785 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
786 ehci_writel(ehci
, temp
| PORT_RESUME
, status_reg
);
787 ehci
->reset_done
[wIndex
] = jiffies
788 + msecs_to_jiffies(20);
790 case USB_PORT_FEAT_C_SUSPEND
:
791 clear_bit(wIndex
, &ehci
->port_c_suspend
);
793 case USB_PORT_FEAT_POWER
:
794 if (HCS_PPC (ehci
->hcs_params
))
796 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
799 case USB_PORT_FEAT_C_CONNECTION
:
801 /* clear PORTSC bits on disconnect */
803 temp
&= ~PORT_DEV_ADDR
;
805 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_CSC
,
808 case USB_PORT_FEAT_C_OVER_CURRENT
:
809 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_OCC
,
812 case USB_PORT_FEAT_C_RESET
:
813 /* GetPortStatus clears reset */
818 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted write */
820 case GetHubDescriptor
:
821 ehci_hub_descriptor (ehci
, (struct usb_hub_descriptor
*)
825 /* no hub-wide feature/status flags */
827 //cpu_to_le32s ((u32 *) buf);
830 if (!wIndex
|| wIndex
> ports
)
834 temp
= ehci_readl(ehci
, status_reg
);
838 status
|= USB_PORT_STAT_C_CONNECTION
<< 16;
840 status
|= USB_PORT_STAT_C_ENABLE
<< 16;
842 if ((temp
& PORT_OCC
) && !ignore_oc
){
843 status
|= USB_PORT_STAT_C_OVERCURRENT
<< 16;
846 * Hubs should disable port power on over-current.
847 * However, not all EHCI implementations do this
848 * automatically, even if they _do_ support per-port
849 * power switching; they're allowed to just limit the
850 * current. khubd will turn the power back on.
852 if (HCS_PPC (ehci
->hcs_params
)){
854 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
859 /* whoever resumes must GetPortStatus to complete it!! */
860 if (temp
& PORT_RESUME
) {
862 /* Remote Wakeup received? */
863 if (!ehci
->reset_done
[wIndex
]) {
864 /* resume signaling for 20 msec */
865 ehci
->reset_done
[wIndex
] = jiffies
866 + msecs_to_jiffies(20);
867 /* check the port again */
868 mod_timer(&ehci_to_hcd(ehci
)->rh_timer
,
869 ehci
->reset_done
[wIndex
]);
872 /* resume completed? */
873 else if (time_after_eq(jiffies
,
874 ehci
->reset_done
[wIndex
])) {
875 clear_bit(wIndex
, &ehci
->suspended_ports
);
876 set_bit(wIndex
, &ehci
->port_c_suspend
);
877 ehci
->reset_done
[wIndex
] = 0;
879 /* stop resume signaling */
880 temp
= ehci_readl(ehci
, status_reg
);
882 temp
& ~(PORT_RWC_BITS
| PORT_RESUME
),
884 retval
= handshake(ehci
, status_reg
,
885 PORT_RESUME
, 0, 2000 /* 2msec */);
888 "port %d resume error %d\n",
892 temp
&= ~(PORT_SUSPEND
|PORT_RESUME
|(3<<10));
896 /* whoever resets must GetPortStatus to complete it!! */
897 if ((temp
& PORT_RESET
)
898 && time_after_eq(jiffies
,
899 ehci
->reset_done
[wIndex
])) {
900 status
|= USB_PORT_STAT_C_RESET
<< 16;
901 ehci
->reset_done
[wIndex
] = 0;
903 /* force reset to complete */
904 ehci_writel(ehci
, temp
& ~(PORT_RWC_BITS
| PORT_RESET
),
906 /* REVISIT: some hardware needs 550+ usec to clear
907 * this bit; seems too long to spin routinely...
909 retval
= handshake(ehci
, status_reg
,
910 PORT_RESET
, 0, 1000);
912 ehci_err (ehci
, "port %d reset error %d\n",
917 /* see what we found out */
918 temp
= check_reset_complete (ehci
, wIndex
, status_reg
,
919 ehci_readl(ehci
, status_reg
));
922 if (!(temp
& (PORT_RESUME
|PORT_RESET
)))
923 ehci
->reset_done
[wIndex
] = 0;
925 /* transfer dedicated ports to the companion hc */
926 if ((temp
& PORT_CONNECT
) &&
927 test_bit(wIndex
, &ehci
->companion_ports
)) {
928 temp
&= ~PORT_RWC_BITS
;
930 ehci_writel(ehci
, temp
, status_reg
);
931 ehci_dbg(ehci
, "port %d --> companion\n", wIndex
+ 1);
932 temp
= ehci_readl(ehci
, status_reg
);
936 * Even if OWNER is set, there's no harm letting khubd
937 * see the wPortStatus values (they should all be 0 except
938 * for PORT_POWER anyway).
941 if (temp
& PORT_CONNECT
) {
942 status
|= USB_PORT_STAT_CONNECTION
;
943 // status may be from integrated TT
944 if (ehci
->has_hostpc
) {
945 temp1
= ehci_readl(ehci
, hostpc_reg
);
946 status
|= ehci_port_speed(ehci
, temp1
);
948 status
|= ehci_port_speed(ehci
, temp
);
951 status
|= USB_PORT_STAT_ENABLE
;
953 /* maybe the port was unsuspended without our knowledge */
954 if (temp
& (PORT_SUSPEND
|PORT_RESUME
)) {
955 status
|= USB_PORT_STAT_SUSPEND
;
956 } else if (test_bit(wIndex
, &ehci
->suspended_ports
)) {
957 clear_bit(wIndex
, &ehci
->suspended_ports
);
958 ehci
->reset_done
[wIndex
] = 0;
960 set_bit(wIndex
, &ehci
->port_c_suspend
);
964 status
|= USB_PORT_STAT_OVERCURRENT
;
965 if (temp
& PORT_RESET
)
966 status
|= USB_PORT_STAT_RESET
;
967 if (temp
& PORT_POWER
)
968 status
|= USB_PORT_STAT_POWER
;
969 if (test_bit(wIndex
, &ehci
->port_c_suspend
))
970 status
|= USB_PORT_STAT_C_SUSPEND
<< 16;
972 #ifndef VERBOSE_DEBUG
973 if (status
& ~0xffff) /* only if wPortChange is interesting */
975 dbg_port (ehci
, "GetStatus", wIndex
+ 1, temp
);
976 put_unaligned_le32(status
, buf
);
980 case C_HUB_LOCAL_POWER
:
981 case C_HUB_OVER_CURRENT
:
982 /* no hub-wide feature/status flags */
989 selector
= wIndex
>> 8;
991 if (unlikely(ehci
->debug
)) {
992 /* If the debug port is active any port
993 * feature requests should get denied */
994 if (wIndex
== HCS_DEBUG_PORT(ehci
->hcs_params
) &&
995 (readl(&ehci
->debug
->control
) & DBGP_ENABLED
)) {
1000 if (!wIndex
|| wIndex
> ports
)
1003 temp
= ehci_readl(ehci
, status_reg
);
1004 if (temp
& PORT_OWNER
)
1007 temp
&= ~PORT_RWC_BITS
;
1009 case USB_PORT_FEAT_SUSPEND
:
1010 if (ehci
->no_selective_suspend
)
1012 if ((temp
& PORT_PE
) == 0
1013 || (temp
& PORT_RESET
) != 0)
1016 /* After above check the port must be connected.
1017 * Set appropriate bit thus could put phy into low power
1018 * mode if we have hostpc feature
1020 temp
&= ~PORT_WKCONN_E
;
1021 temp
|= PORT_WKDISC_E
| PORT_WKOC_E
;
1022 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
1024 spin_unlock_irqrestore(&ehci
->lock
, flags
);
1025 msleep(5);/* 5ms for HCD enter low pwr mode */
1026 spin_lock_irqsave(&ehci
->lock
, flags
);
1027 temp1
= ehci_readl(ehci
, hostpc_reg
);
1028 ehci_writel(ehci
, temp1
| HOSTPC_PHCD
,
1030 temp1
= ehci_readl(ehci
, hostpc_reg
);
1031 ehci_dbg(ehci
, "Port%d phy low pwr mode %s\n",
1032 wIndex
, (temp1
& HOSTPC_PHCD
) ?
1033 "succeeded" : "failed");
1035 set_bit(wIndex
, &ehci
->suspended_ports
);
1037 case USB_PORT_FEAT_POWER
:
1038 if (HCS_PPC (ehci
->hcs_params
))
1039 ehci_writel(ehci
, temp
| PORT_POWER
,
1042 case USB_PORT_FEAT_RESET
:
1043 if (temp
& PORT_RESUME
)
1045 /* line status bits may report this as low speed,
1046 * which can be fine if this root hub has a
1047 * transaction translator built in.
1049 if ((temp
& (PORT_PE
|PORT_CONNECT
)) == PORT_CONNECT
1050 && !ehci_is_TDI(ehci
)
1051 && PORT_USB11 (temp
)) {
1053 "port %d low speed --> companion\n",
1057 ehci_vdbg (ehci
, "port %d reset\n", wIndex
+ 1);
1062 * caller must wait, then call GetPortStatus
1063 * usb 2.0 spec says 50 ms resets on root
1065 ehci
->reset_done
[wIndex
] = jiffies
1066 + msecs_to_jiffies (50);
1068 ehci_writel(ehci
, temp
, status_reg
);
1071 /* For downstream facing ports (these): one hub port is put
1072 * into test mode according to USB2 11.24.2.13, then the hub
1073 * must be reset (which for root hub now means rmmod+modprobe,
1074 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1075 * about the EHCI-specific stuff.
1077 case USB_PORT_FEAT_TEST
:
1078 if (!selector
|| selector
> 5)
1082 temp
|= selector
<< 16;
1083 ehci_writel(ehci
, temp
, status_reg
);
1089 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted writes */
1094 /* "stall" on error */
1098 spin_unlock_irqrestore (&ehci
->lock
, flags
);
1102 static void ehci_relinquish_port(struct usb_hcd
*hcd
, int portnum
)
1104 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1106 if (ehci_is_TDI(ehci
))
1108 set_owner(ehci
, --portnum
, PORT_OWNER
);
1111 static int ehci_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
1113 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1116 if (ehci_is_TDI(ehci
))
1118 reg
= &ehci
->regs
->port_status
[portnum
- 1];
1119 return ehci_readl(ehci
, reg
) & PORT_OWNER
;