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
,
115 /* If remote wakeup is enabled for the root hub but disabled
116 * for the controller, we must adjust all the port wakeup flags
117 * when the controller is suspended or resumed. In all other
118 * cases they don't need to be changed.
120 if (!ehci_to_hcd(ehci
)->self
.root_hub
->do_remote_wakeup
||
121 device_may_wakeup(ehci_to_hcd(ehci
)->self
.controller
))
124 /* clear phy low-power mode before changing wakeup flags */
125 if (ehci
->has_hostpc
) {
126 port
= HCS_N_PORTS(ehci
->hcs_params
);
128 u32 __iomem
*hostpc_reg
;
130 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
131 + HOSTPC0
+ 4 * port
);
132 temp
= ehci_readl(ehci
, hostpc_reg
);
133 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
, hostpc_reg
);
138 port
= HCS_N_PORTS(ehci
->hcs_params
);
140 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
141 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
142 u32 t2
= t1
& ~PORT_WAKE_BITS
;
144 /* If we are suspending the controller, clear the flags.
145 * If we are resuming the controller, set the wakeup flags.
148 if (t1
& PORT_CONNECT
)
149 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
151 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
153 ehci_vdbg(ehci
, "port %d, %08x -> %08x\n",
155 ehci_writel(ehci
, t2
, reg
);
158 /* enter phy low-power mode again */
159 if (ehci
->has_hostpc
) {
160 port
= HCS_N_PORTS(ehci
->hcs_params
);
162 u32 __iomem
*hostpc_reg
;
164 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
165 + HOSTPC0
+ 4 * port
);
166 temp
= ehci_readl(ehci
, hostpc_reg
);
167 ehci_writel(ehci
, temp
| HOSTPC_PHCD
, hostpc_reg
);
172 static int ehci_bus_suspend (struct usb_hcd
*hcd
)
174 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
179 ehci_dbg(ehci
, "suspend root hub\n");
181 if (time_before (jiffies
, ehci
->next_statechange
))
183 del_timer_sync(&ehci
->watchdog
);
184 del_timer_sync(&ehci
->iaa_watchdog
);
186 spin_lock_irq (&ehci
->lock
);
188 /* Once the controller is stopped, port resumes that are already
189 * in progress won't complete. Hence if remote wakeup is enabled
190 * for the root hub and any ports are in the middle of a resume or
191 * remote wakeup, we must fail the suspend.
193 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
194 port
= HCS_N_PORTS(ehci
->hcs_params
);
196 if (ehci
->reset_done
[port
] != 0) {
197 spin_unlock_irq(&ehci
->lock
);
198 ehci_dbg(ehci
, "suspend failed because "
199 "port %d is resuming\n",
206 /* stop schedules, clean any completed work */
207 if (HC_IS_RUNNING(hcd
->state
)) {
209 hcd
->state
= HC_STATE_QUIESCING
;
211 ehci
->command
= ehci_readl(ehci
, &ehci
->regs
->command
);
214 /* Unlike other USB host controller types, EHCI doesn't have
215 * any notion of "global" or bus-wide suspend. The driver has
216 * to manually suspend all the active unsuspended ports, and
217 * then manually resume them in the bus_resume() routine.
219 ehci
->bus_suspended
= 0;
220 ehci
->owned_ports
= 0;
222 port
= HCS_N_PORTS(ehci
->hcs_params
);
224 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
225 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
226 u32 t2
= t1
& ~PORT_WAKE_BITS
;
228 /* keep track of which ports we suspend */
230 set_bit(port
, &ehci
->owned_ports
);
231 else if ((t1
& PORT_PE
) && !(t1
& PORT_SUSPEND
)) {
233 set_bit(port
, &ehci
->bus_suspended
);
236 /* enable remote wakeup on all ports, if told to do so */
237 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
238 /* only enable appropriate wake bits, otherwise the
239 * hardware can not go phy low power mode. If a race
240 * condition happens here(connection change during bits
241 * set), the port change detection will finally fix it.
243 if (t1
& PORT_CONNECT
)
244 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
246 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
250 ehci_vdbg (ehci
, "port %d, %08x -> %08x\n",
252 ehci_writel(ehci
, t2
, reg
);
257 if (changed
&& ehci
->has_hostpc
) {
258 spin_unlock_irq(&ehci
->lock
);
259 msleep(5); /* 5 ms for HCD to enter low-power mode */
260 spin_lock_irq(&ehci
->lock
);
262 port
= HCS_N_PORTS(ehci
->hcs_params
);
264 u32 __iomem
*hostpc_reg
;
267 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
268 + HOSTPC0
+ 4 * port
);
269 t3
= ehci_readl(ehci
, hostpc_reg
);
270 ehci_writel(ehci
, t3
| HOSTPC_PHCD
, hostpc_reg
);
271 t3
= ehci_readl(ehci
, hostpc_reg
);
272 ehci_dbg(ehci
, "Port %d phy low-power mode %s\n",
273 port
, (t3
& HOSTPC_PHCD
) ?
274 "succeeded" : "failed");
278 /* Apparently some devices need a >= 1-uframe delay here */
279 if (ehci
->bus_suspended
)
282 /* turn off now-idle HC */
284 hcd
->state
= HC_STATE_SUSPENDED
;
287 end_unlink_async(ehci
);
289 /* allow remote wakeup */
291 if (!hcd
->self
.root_hub
->do_remote_wakeup
)
293 ehci_writel(ehci
, mask
, &ehci
->regs
->intr_enable
);
294 ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
296 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(10);
297 spin_unlock_irq (&ehci
->lock
);
299 /* ehci_work() may have re-enabled the watchdog timer, which we do not
300 * want, and so we must delete any pending watchdog timer events.
302 del_timer_sync(&ehci
->watchdog
);
307 /* caller has locked the root hub, and should reset/reinit on error */
308 static int ehci_bus_resume (struct usb_hcd
*hcd
)
310 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
314 u8 resume_needed
= 0;
316 if (time_before (jiffies
, ehci
->next_statechange
))
318 spin_lock_irq (&ehci
->lock
);
319 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)) {
320 spin_unlock_irq(&ehci
->lock
);
324 if (unlikely(ehci
->debug
)) {
325 if (!dbgp_reset_prep())
328 dbgp_external_startup();
331 /* Ideally and we've got a real resume here, and no port's power
332 * was lost. (For PCI, that means Vaux was maintained.) But we
333 * could instead be restoring a swsusp snapshot -- so that BIOS was
334 * the last user of the controller, not reset/pm hardware keeping
335 * state we gave to it.
337 power_okay
= ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
338 ehci_dbg(ehci
, "resume root hub%s\n",
339 power_okay
? "" : " after power loss");
341 /* at least some APM implementations will try to deliver
342 * IRQs right away, so delay them until we're ready.
344 ehci_writel(ehci
, 0, &ehci
->regs
->intr_enable
);
346 /* re-init operational registers */
347 ehci_writel(ehci
, 0, &ehci
->regs
->segment
);
348 ehci_writel(ehci
, ehci
->periodic_dma
, &ehci
->regs
->frame_list
);
349 ehci_writel(ehci
, (u32
) ehci
->async
->qh_dma
, &ehci
->regs
->async_next
);
351 /* restore CMD_RUN, framelist size, and irq threshold */
352 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
354 /* Some controller/firmware combinations need a delay during which
355 * they set up the port statuses. See Bugzilla #8190. */
356 spin_unlock_irq(&ehci
->lock
);
358 spin_lock_irq(&ehci
->lock
);
360 /* clear phy low-power mode before resume */
361 if (ehci
->bus_suspended
&& ehci
->has_hostpc
) {
362 i
= HCS_N_PORTS(ehci
->hcs_params
);
364 if (test_bit(i
, &ehci
->bus_suspended
)) {
365 u32 __iomem
*hostpc_reg
;
367 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
369 temp
= ehci_readl(ehci
, hostpc_reg
);
370 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
,
374 spin_unlock_irq(&ehci
->lock
);
376 spin_lock_irq(&ehci
->lock
);
379 /* manually resume the ports we suspended during bus_suspend() */
380 i
= HCS_N_PORTS (ehci
->hcs_params
);
382 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
383 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
384 if (test_bit(i
, &ehci
->bus_suspended
) &&
385 (temp
& PORT_SUSPEND
)) {
389 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
392 /* msleep for 20ms only if code is trying to resume port */
394 spin_unlock_irq(&ehci
->lock
);
396 spin_lock_irq(&ehci
->lock
);
399 i
= HCS_N_PORTS (ehci
->hcs_params
);
401 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
402 if (test_bit(i
, &ehci
->bus_suspended
) &&
403 (temp
& PORT_SUSPEND
)) {
404 temp
&= ~(PORT_RWC_BITS
| PORT_RESUME
);
405 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
406 ehci_vdbg (ehci
, "resumed port %d\n", i
+ 1);
409 (void) ehci_readl(ehci
, &ehci
->regs
->command
);
411 /* maybe re-activate the schedule(s) */
413 if (ehci
->async
->qh_next
.qh
)
415 if (ehci
->periodic_sched
)
418 ehci
->command
|= temp
;
419 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
422 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
423 hcd
->state
= HC_STATE_RUNNING
;
425 /* Now we can safely re-enable irqs */
426 ehci_writel(ehci
, INTR_MASK
, &ehci
->regs
->intr_enable
);
428 spin_unlock_irq (&ehci
->lock
);
429 ehci_handover_companion_ports(ehci
);
435 #define ehci_bus_suspend NULL
436 #define ehci_bus_resume NULL
438 #endif /* CONFIG_PM */
440 /*-------------------------------------------------------------------------*/
442 /* Display the ports dedicated to the companion controller */
443 static ssize_t
show_companion(struct device
*dev
,
444 struct device_attribute
*attr
,
447 struct ehci_hcd
*ehci
;
448 int nports
, index
, n
;
449 int count
= PAGE_SIZE
;
452 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
453 nports
= HCS_N_PORTS(ehci
->hcs_params
);
455 for (index
= 0; index
< nports
; ++index
) {
456 if (test_bit(index
, &ehci
->companion_ports
)) {
457 n
= scnprintf(ptr
, count
, "%d\n", index
+ 1);
466 * Sets the owner of a port
468 static void set_owner(struct ehci_hcd
*ehci
, int portnum
, int new_owner
)
470 u32 __iomem
*status_reg
;
474 status_reg
= &ehci
->regs
->port_status
[portnum
];
477 * The controller won't set the OWNER bit if the port is
478 * enabled, so this loop will sometimes require at least two
479 * iterations: one to disable the port and one to set OWNER.
481 for (try = 4; try > 0; --try) {
482 spin_lock_irq(&ehci
->lock
);
483 port_status
= ehci_readl(ehci
, status_reg
);
484 if ((port_status
& PORT_OWNER
) == new_owner
485 || (port_status
& (PORT_OWNER
| PORT_CONNECT
))
489 port_status
^= PORT_OWNER
;
490 port_status
&= ~(PORT_PE
| PORT_RWC_BITS
);
491 ehci_writel(ehci
, port_status
, status_reg
);
493 spin_unlock_irq(&ehci
->lock
);
500 * Dedicate or undedicate a port to the companion controller.
501 * Syntax is "[-]portnum", where a leading '-' sign means
502 * return control of the port to the EHCI controller.
504 static ssize_t
store_companion(struct device
*dev
,
505 struct device_attribute
*attr
,
506 const char *buf
, size_t count
)
508 struct ehci_hcd
*ehci
;
509 int portnum
, new_owner
;
511 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
512 new_owner
= PORT_OWNER
; /* Owned by companion */
513 if (sscanf(buf
, "%d", &portnum
) != 1)
517 new_owner
= 0; /* Owned by EHCI */
519 if (portnum
<= 0 || portnum
> HCS_N_PORTS(ehci
->hcs_params
))
523 set_bit(portnum
, &ehci
->companion_ports
);
525 clear_bit(portnum
, &ehci
->companion_ports
);
526 set_owner(ehci
, portnum
, new_owner
);
529 static DEVICE_ATTR(companion
, 0644, show_companion
, store_companion
);
531 static inline void create_companion_file(struct ehci_hcd
*ehci
)
535 /* with integrated TT there is no companion! */
536 if (!ehci_is_TDI(ehci
))
537 i
= device_create_file(ehci_to_hcd(ehci
)->self
.controller
,
538 &dev_attr_companion
);
541 static inline void remove_companion_file(struct ehci_hcd
*ehci
)
543 /* with integrated TT there is no companion! */
544 if (!ehci_is_TDI(ehci
))
545 device_remove_file(ehci_to_hcd(ehci
)->self
.controller
,
546 &dev_attr_companion
);
550 /*-------------------------------------------------------------------------*/
552 static int check_reset_complete (
553 struct ehci_hcd
*ehci
,
555 u32 __iomem
*status_reg
,
558 if (!(port_status
& PORT_CONNECT
))
561 /* if reset finished and it's still not enabled -- handoff */
562 if (!(port_status
& PORT_PE
)) {
564 /* with integrated TT, there's nobody to hand it to! */
565 if (ehci_is_TDI(ehci
)) {
567 "Failed to enable port %d on root hub TT\n",
572 ehci_dbg (ehci
, "port %d full speed --> companion\n",
575 // what happens if HCS_N_CC(params) == 0 ?
576 port_status
|= PORT_OWNER
;
577 port_status
&= ~PORT_RWC_BITS
;
578 ehci_writel(ehci
, port_status
, status_reg
);
580 /* ensure 440EPX ohci controller state is operational */
581 if (ehci
->has_amcc_usb23
)
582 set_ohci_hcfs(ehci
, 1);
584 ehci_dbg (ehci
, "port %d high speed\n", index
+ 1);
585 /* ensure 440EPx ohci controller state is suspended */
586 if (ehci
->has_amcc_usb23
)
587 set_ohci_hcfs(ehci
, 0);
593 /*-------------------------------------------------------------------------*/
596 /* build "status change" packet (one or two bytes) from HC registers */
599 ehci_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
601 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
602 u32 temp
, status
= 0;
604 int ports
, i
, retval
= 1;
607 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
608 if (!HC_IS_RUNNING(hcd
->state
))
611 /* init status to no-changes */
613 ports
= HCS_N_PORTS (ehci
->hcs_params
);
619 /* Some boards (mostly VIA?) report bogus overcurrent indications,
620 * causing massive log spam unless we completely ignore them. It
621 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
622 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
623 * PORT_POWER; that's surprising, but maybe within-spec.
626 mask
= PORT_CSC
| PORT_PEC
| PORT_OCC
;
628 mask
= PORT_CSC
| PORT_PEC
;
629 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
631 /* no hub change reports (bit 0) for now (power, ...) */
633 /* port N changes (bit N)? */
634 spin_lock_irqsave (&ehci
->lock
, flags
);
635 for (i
= 0; i
< ports
; i
++) {
636 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
639 * Return status information even for ports with OWNER set.
640 * Otherwise khubd wouldn't see the disconnect event when a
641 * high-speed device is switched over to the companion
642 * controller by the user.
645 if ((temp
& mask
) != 0 || test_bit(i
, &ehci
->port_c_suspend
)
646 || (ehci
->reset_done
[i
] && time_after_eq(
647 jiffies
, ehci
->reset_done
[i
]))) {
649 buf
[0] |= 1 << (i
+ 1);
651 buf
[1] |= 1 << (i
- 7);
655 /* FIXME autosuspend idle root hubs */
656 spin_unlock_irqrestore (&ehci
->lock
, flags
);
657 return status
? retval
: 0;
660 /*-------------------------------------------------------------------------*/
663 ehci_hub_descriptor (
664 struct ehci_hcd
*ehci
,
665 struct usb_hub_descriptor
*desc
667 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
670 desc
->bDescriptorType
= 0x29;
671 desc
->bPwrOn2PwrGood
= 10; /* ehci 1.0, 2.3.9 says 20ms max */
672 desc
->bHubContrCurrent
= 0;
674 desc
->bNbrPorts
= ports
;
675 temp
= 1 + (ports
/ 8);
676 desc
->bDescLength
= 7 + 2 * temp
;
678 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
679 memset (&desc
->bitmap
[0], 0, temp
);
680 memset (&desc
->bitmap
[temp
], 0xff, temp
);
682 temp
= 0x0008; /* per-port overcurrent reporting */
683 if (HCS_PPC (ehci
->hcs_params
))
684 temp
|= 0x0001; /* per-port power control */
686 temp
|= 0x0002; /* no power switching */
688 // re-enable when we support USB_PORT_FEAT_INDICATOR below.
689 if (HCS_INDICATOR (ehci
->hcs_params
))
690 temp
|= 0x0080; /* per-port indicators (LEDs) */
692 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
695 /*-------------------------------------------------------------------------*/
697 static int ehci_hub_control (
705 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
706 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
707 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
708 (wIndex
& 0xff) - 1];
709 u32 __iomem
*hostpc_reg
= NULL
;
710 u32 temp
, temp1
, status
;
716 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
717 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
718 * (track current state ourselves) ... blink for diagnostics,
719 * power, "this is the one", etc. EHCI spec supports this.
722 if (ehci
->has_hostpc
)
723 hostpc_reg
= (u32 __iomem
*)((u8
*)ehci
->regs
724 + HOSTPC0
+ 4 * ((wIndex
& 0xff) - 1));
725 spin_lock_irqsave (&ehci
->lock
, flags
);
727 case ClearHubFeature
:
729 case C_HUB_LOCAL_POWER
:
730 case C_HUB_OVER_CURRENT
:
731 /* no hub-wide feature/status flags */
737 case ClearPortFeature
:
738 if (!wIndex
|| wIndex
> ports
)
741 temp
= ehci_readl(ehci
, status_reg
);
744 * Even if OWNER is set, so the port is owned by the
745 * companion controller, khubd needs to be able to clear
746 * the port-change status bits (especially
747 * USB_PORT_STAT_C_CONNECTION).
751 case USB_PORT_FEAT_ENABLE
:
752 ehci_writel(ehci
, temp
& ~PORT_PE
, status_reg
);
754 case USB_PORT_FEAT_C_ENABLE
:
755 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_PEC
,
758 case USB_PORT_FEAT_SUSPEND
:
759 if (temp
& PORT_RESET
)
761 if (ehci
->no_selective_suspend
)
763 if (!(temp
& PORT_SUSPEND
))
765 if ((temp
& PORT_PE
) == 0)
768 /* clear phy low-power mode before resume */
770 temp1
= ehci_readl(ehci
, hostpc_reg
);
771 ehci_writel(ehci
, temp1
& ~HOSTPC_PHCD
,
773 spin_unlock_irqrestore(&ehci
->lock
, flags
);
774 msleep(5);/* wait to leave low-power mode */
775 spin_lock_irqsave(&ehci
->lock
, flags
);
777 /* resume signaling for 20 msec */
778 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
779 ehci_writel(ehci
, temp
| PORT_RESUME
, status_reg
);
780 ehci
->reset_done
[wIndex
] = jiffies
781 + msecs_to_jiffies(20);
783 case USB_PORT_FEAT_C_SUSPEND
:
784 clear_bit(wIndex
, &ehci
->port_c_suspend
);
786 case USB_PORT_FEAT_POWER
:
787 if (HCS_PPC (ehci
->hcs_params
))
789 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
792 case USB_PORT_FEAT_C_CONNECTION
:
793 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_CSC
,
796 case USB_PORT_FEAT_C_OVER_CURRENT
:
797 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_OCC
,
800 case USB_PORT_FEAT_C_RESET
:
801 /* GetPortStatus clears reset */
806 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted write */
808 case GetHubDescriptor
:
809 ehci_hub_descriptor (ehci
, (struct usb_hub_descriptor
*)
813 /* no hub-wide feature/status flags */
815 //cpu_to_le32s ((u32 *) buf);
818 if (!wIndex
|| wIndex
> ports
)
822 temp
= ehci_readl(ehci
, status_reg
);
826 status
|= USB_PORT_STAT_C_CONNECTION
<< 16;
828 status
|= USB_PORT_STAT_C_ENABLE
<< 16;
830 if ((temp
& PORT_OCC
) && !ignore_oc
){
831 status
|= USB_PORT_STAT_C_OVERCURRENT
<< 16;
834 * Hubs should disable port power on over-current.
835 * However, not all EHCI implementations do this
836 * automatically, even if they _do_ support per-port
837 * power switching; they're allowed to just limit the
838 * current. khubd will turn the power back on.
840 if (HCS_PPC (ehci
->hcs_params
)){
842 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
847 /* whoever resumes must GetPortStatus to complete it!! */
848 if (temp
& PORT_RESUME
) {
850 /* Remote Wakeup received? */
851 if (!ehci
->reset_done
[wIndex
]) {
852 /* resume signaling for 20 msec */
853 ehci
->reset_done
[wIndex
] = jiffies
854 + msecs_to_jiffies(20);
855 /* check the port again */
856 mod_timer(&ehci_to_hcd(ehci
)->rh_timer
,
857 ehci
->reset_done
[wIndex
]);
860 /* resume completed? */
861 else if (time_after_eq(jiffies
,
862 ehci
->reset_done
[wIndex
])) {
863 clear_bit(wIndex
, &ehci
->suspended_ports
);
864 set_bit(wIndex
, &ehci
->port_c_suspend
);
865 ehci
->reset_done
[wIndex
] = 0;
867 /* stop resume signaling */
868 temp
= ehci_readl(ehci
, status_reg
);
870 temp
& ~(PORT_RWC_BITS
| PORT_RESUME
),
872 retval
= handshake(ehci
, status_reg
,
873 PORT_RESUME
, 0, 2000 /* 2msec */);
876 "port %d resume error %d\n",
880 temp
&= ~(PORT_SUSPEND
|PORT_RESUME
|(3<<10));
884 /* whoever resets must GetPortStatus to complete it!! */
885 if ((temp
& PORT_RESET
)
886 && time_after_eq(jiffies
,
887 ehci
->reset_done
[wIndex
])) {
888 status
|= USB_PORT_STAT_C_RESET
<< 16;
889 ehci
->reset_done
[wIndex
] = 0;
891 /* force reset to complete */
892 ehci_writel(ehci
, temp
& ~(PORT_RWC_BITS
| PORT_RESET
),
894 /* REVISIT: some hardware needs 550+ usec to clear
895 * this bit; seems too long to spin routinely...
897 retval
= handshake(ehci
, status_reg
,
898 PORT_RESET
, 0, 1000);
900 ehci_err (ehci
, "port %d reset error %d\n",
905 /* see what we found out */
906 temp
= check_reset_complete (ehci
, wIndex
, status_reg
,
907 ehci_readl(ehci
, status_reg
));
910 if (!(temp
& (PORT_RESUME
|PORT_RESET
)))
911 ehci
->reset_done
[wIndex
] = 0;
913 /* transfer dedicated ports to the companion hc */
914 if ((temp
& PORT_CONNECT
) &&
915 test_bit(wIndex
, &ehci
->companion_ports
)) {
916 temp
&= ~PORT_RWC_BITS
;
918 ehci_writel(ehci
, temp
, status_reg
);
919 ehci_dbg(ehci
, "port %d --> companion\n", wIndex
+ 1);
920 temp
= ehci_readl(ehci
, status_reg
);
924 * Even if OWNER is set, there's no harm letting khubd
925 * see the wPortStatus values (they should all be 0 except
926 * for PORT_POWER anyway).
929 if (temp
& PORT_CONNECT
) {
930 status
|= USB_PORT_STAT_CONNECTION
;
931 // status may be from integrated TT
932 if (ehci
->has_hostpc
) {
933 temp1
= ehci_readl(ehci
, hostpc_reg
);
934 status
|= ehci_port_speed(ehci
, temp1
);
936 status
|= ehci_port_speed(ehci
, temp
);
939 status
|= USB_PORT_STAT_ENABLE
;
941 /* maybe the port was unsuspended without our knowledge */
942 if (temp
& (PORT_SUSPEND
|PORT_RESUME
)) {
943 status
|= USB_PORT_STAT_SUSPEND
;
944 } else if (test_bit(wIndex
, &ehci
->suspended_ports
)) {
945 clear_bit(wIndex
, &ehci
->suspended_ports
);
946 ehci
->reset_done
[wIndex
] = 0;
948 set_bit(wIndex
, &ehci
->port_c_suspend
);
952 status
|= USB_PORT_STAT_OVERCURRENT
;
953 if (temp
& PORT_RESET
)
954 status
|= USB_PORT_STAT_RESET
;
955 if (temp
& PORT_POWER
)
956 status
|= USB_PORT_STAT_POWER
;
957 if (test_bit(wIndex
, &ehci
->port_c_suspend
))
958 status
|= USB_PORT_STAT_C_SUSPEND
<< 16;
960 #ifndef VERBOSE_DEBUG
961 if (status
& ~0xffff) /* only if wPortChange is interesting */
963 dbg_port (ehci
, "GetStatus", wIndex
+ 1, temp
);
964 put_unaligned_le32(status
, buf
);
968 case C_HUB_LOCAL_POWER
:
969 case C_HUB_OVER_CURRENT
:
970 /* no hub-wide feature/status flags */
977 selector
= wIndex
>> 8;
979 if (unlikely(ehci
->debug
)) {
980 /* If the debug port is active any port
981 * feature requests should get denied */
982 if (wIndex
== HCS_DEBUG_PORT(ehci
->hcs_params
) &&
983 (readl(&ehci
->debug
->control
) & DBGP_ENABLED
)) {
988 if (!wIndex
|| wIndex
> ports
)
991 temp
= ehci_readl(ehci
, status_reg
);
992 if (temp
& PORT_OWNER
)
995 temp
&= ~PORT_RWC_BITS
;
997 case USB_PORT_FEAT_SUSPEND
:
998 if (ehci
->no_selective_suspend
)
1000 if ((temp
& PORT_PE
) == 0
1001 || (temp
& PORT_RESET
) != 0)
1004 /* After above check the port must be connected.
1005 * Set appropriate bit thus could put phy into low power
1006 * mode if we have hostpc feature
1008 temp
&= ~PORT_WKCONN_E
;
1009 temp
|= PORT_WKDISC_E
| PORT_WKOC_E
;
1010 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
1012 spin_unlock_irqrestore(&ehci
->lock
, flags
);
1013 msleep(5);/* 5ms for HCD enter low pwr mode */
1014 spin_lock_irqsave(&ehci
->lock
, flags
);
1015 temp1
= ehci_readl(ehci
, hostpc_reg
);
1016 ehci_writel(ehci
, temp1
| HOSTPC_PHCD
,
1018 temp1
= ehci_readl(ehci
, hostpc_reg
);
1019 ehci_dbg(ehci
, "Port%d phy low pwr mode %s\n",
1020 wIndex
, (temp1
& HOSTPC_PHCD
) ?
1021 "succeeded" : "failed");
1023 set_bit(wIndex
, &ehci
->suspended_ports
);
1025 case USB_PORT_FEAT_POWER
:
1026 if (HCS_PPC (ehci
->hcs_params
))
1027 ehci_writel(ehci
, temp
| PORT_POWER
,
1030 case USB_PORT_FEAT_RESET
:
1031 if (temp
& PORT_RESUME
)
1033 /* line status bits may report this as low speed,
1034 * which can be fine if this root hub has a
1035 * transaction translator built in.
1037 if ((temp
& (PORT_PE
|PORT_CONNECT
)) == PORT_CONNECT
1038 && !ehci_is_TDI(ehci
)
1039 && PORT_USB11 (temp
)) {
1041 "port %d low speed --> companion\n",
1045 ehci_vdbg (ehci
, "port %d reset\n", wIndex
+ 1);
1050 * caller must wait, then call GetPortStatus
1051 * usb 2.0 spec says 50 ms resets on root
1053 ehci
->reset_done
[wIndex
] = jiffies
1054 + msecs_to_jiffies (50);
1056 ehci_writel(ehci
, temp
, status_reg
);
1059 /* For downstream facing ports (these): one hub port is put
1060 * into test mode according to USB2 11.24.2.13, then the hub
1061 * must be reset (which for root hub now means rmmod+modprobe,
1062 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1063 * about the EHCI-specific stuff.
1065 case USB_PORT_FEAT_TEST
:
1066 if (!selector
|| selector
> 5)
1070 temp
|= selector
<< 16;
1071 ehci_writel(ehci
, temp
, status_reg
);
1077 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted writes */
1082 /* "stall" on error */
1086 spin_unlock_irqrestore (&ehci
->lock
, flags
);
1090 static void ehci_relinquish_port(struct usb_hcd
*hcd
, int portnum
)
1092 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1094 if (ehci_is_TDI(ehci
))
1096 set_owner(ehci
, --portnum
, PORT_OWNER
);
1099 static int ehci_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
1101 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1104 if (ehci_is_TDI(ehci
))
1106 reg
= &ehci
->regs
->port_status
[portnum
- 1];
1107 return ehci_readl(ehci
, reg
) & PORT_OWNER
;