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 /*-------------------------------------------------------------------------*/
30 #include <linux/usb/otg.h>
32 #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
36 static int ehci_hub_control(
45 /* After a power loss, ports that were owned by the companion must be
46 * reset so that the companion can still own them.
48 static void ehci_handover_companion_ports(struct ehci_hcd
*ehci
)
54 struct usb_hcd
*hcd
= ehci_to_hcd(ehci
);
56 if (!ehci
->owned_ports
)
59 /* Give the connections some time to appear */
62 spin_lock_irq(&ehci
->lock
);
63 port
= HCS_N_PORTS(ehci
->hcs_params
);
65 if (test_bit(port
, &ehci
->owned_ports
)) {
66 reg
= &ehci
->regs
->port_status
[port
];
67 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
69 /* Port already owned by companion? */
70 if (status
& PORT_OWNER
)
71 clear_bit(port
, &ehci
->owned_ports
);
72 else if (test_bit(port
, &ehci
->companion_ports
))
73 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
75 spin_unlock_irq(&ehci
->lock
);
76 ehci_hub_control(hcd
, SetPortFeature
,
77 USB_PORT_FEAT_RESET
, port
+ 1,
79 spin_lock_irq(&ehci
->lock
);
83 spin_unlock_irq(&ehci
->lock
);
85 if (!ehci
->owned_ports
)
87 msleep(90); /* Wait for resets to complete */
89 spin_lock_irq(&ehci
->lock
);
90 port
= HCS_N_PORTS(ehci
->hcs_params
);
92 if (test_bit(port
, &ehci
->owned_ports
)) {
93 spin_unlock_irq(&ehci
->lock
);
94 ehci_hub_control(hcd
, GetPortStatus
,
96 (char *) &buf
, sizeof(buf
));
97 spin_lock_irq(&ehci
->lock
);
99 /* The companion should now own the port,
100 * but if something went wrong the port must not
103 reg
= &ehci
->regs
->port_status
[port
];
104 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
105 if (status
& PORT_OWNER
)
106 ehci_writel(ehci
, status
| PORT_CSC
, reg
);
108 ehci_dbg(ehci
, "failed handover port %d: %x\n",
110 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
115 ehci
->owned_ports
= 0;
116 spin_unlock_irq(&ehci
->lock
);
119 static int ehci_port_change(struct ehci_hcd
*ehci
)
121 int i
= HCS_N_PORTS(ehci
->hcs_params
);
123 /* First check if the controller indicates a change event */
125 if (ehci_readl(ehci
, &ehci
->regs
->status
) & STS_PCD
)
129 * Not all controllers appear to update this while going from D3 to D0,
130 * so check the individual port status registers as well
134 if (ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]) & PORT_CSC
)
140 static void ehci_adjust_port_wakeup_flags(struct ehci_hcd
*ehci
,
141 bool suspending
, bool do_wakeup
)
146 /* If remote wakeup is enabled for the root hub but disabled
147 * for the controller, we must adjust all the port wakeup flags
148 * when the controller is suspended or resumed. In all other
149 * cases they don't need to be changed.
151 if (!ehci_to_hcd(ehci
)->self
.root_hub
->do_remote_wakeup
|| do_wakeup
)
154 spin_lock_irq(&ehci
->lock
);
156 /* clear phy low-power mode before changing wakeup flags */
157 if (ehci
->has_hostpc
) {
158 port
= HCS_N_PORTS(ehci
->hcs_params
);
160 u32 __iomem
*hostpc_reg
= &ehci
->regs
->hostpc
[port
];
162 temp
= ehci_readl(ehci
, hostpc_reg
);
163 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
, hostpc_reg
);
165 spin_unlock_irq(&ehci
->lock
);
167 spin_lock_irq(&ehci
->lock
);
170 port
= HCS_N_PORTS(ehci
->hcs_params
);
172 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
173 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
174 u32 t2
= t1
& ~PORT_WAKE_BITS
;
176 /* If we are suspending the controller, clear the flags.
177 * If we are resuming the controller, set the wakeup flags.
180 if (t1
& PORT_CONNECT
)
181 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
183 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
185 ehci_vdbg(ehci
, "port %d, %08x -> %08x\n",
187 ehci_writel(ehci
, t2
, reg
);
190 /* enter phy low-power mode again */
191 if (ehci
->has_hostpc
) {
192 port
= HCS_N_PORTS(ehci
->hcs_params
);
194 u32 __iomem
*hostpc_reg
= &ehci
->regs
->hostpc
[port
];
196 temp
= ehci_readl(ehci
, hostpc_reg
);
197 ehci_writel(ehci
, temp
| HOSTPC_PHCD
, hostpc_reg
);
201 /* Does the root hub have a port wakeup pending? */
202 if (!suspending
&& ehci_port_change(ehci
))
203 usb_hcd_resume_root_hub(ehci_to_hcd(ehci
));
205 spin_unlock_irq(&ehci
->lock
);
208 static int ehci_bus_suspend (struct usb_hcd
*hcd
)
210 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
215 ehci_dbg(ehci
, "suspend root hub\n");
217 if (time_before (jiffies
, ehci
->next_statechange
))
220 /* stop the schedules */
223 spin_lock_irq (&ehci
->lock
);
224 if (ehci
->rh_state
< EHCI_RH_RUNNING
)
227 /* Once the controller is stopped, port resumes that are already
228 * in progress won't complete. Hence if remote wakeup is enabled
229 * for the root hub and any ports are in the middle of a resume or
230 * remote wakeup, we must fail the suspend.
232 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
233 if (ehci
->resuming_ports
) {
234 spin_unlock_irq(&ehci
->lock
);
235 ehci_dbg(ehci
, "suspend failed because a port is resuming\n");
240 /* Unlike other USB host controller types, EHCI doesn't have
241 * any notion of "global" or bus-wide suspend. The driver has
242 * to manually suspend all the active unsuspended ports, and
243 * then manually resume them in the bus_resume() routine.
245 ehci
->bus_suspended
= 0;
246 ehci
->owned_ports
= 0;
248 port
= HCS_N_PORTS(ehci
->hcs_params
);
250 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
251 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
252 u32 t2
= t1
& ~PORT_WAKE_BITS
;
254 /* keep track of which ports we suspend */
256 set_bit(port
, &ehci
->owned_ports
);
257 else if ((t1
& PORT_PE
) && !(t1
& PORT_SUSPEND
)) {
259 set_bit(port
, &ehci
->bus_suspended
);
262 /* enable remote wakeup on all ports, if told to do so */
263 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
264 /* only enable appropriate wake bits, otherwise the
265 * hardware can not go phy low power mode. If a race
266 * condition happens here(connection change during bits
267 * set), the port change detection will finally fix it.
269 if (t1
& PORT_CONNECT
)
270 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
272 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
276 ehci_vdbg (ehci
, "port %d, %08x -> %08x\n",
278 ehci_writel(ehci
, t2
, reg
);
283 if (changed
&& ehci
->has_hostpc
) {
284 spin_unlock_irq(&ehci
->lock
);
285 msleep(5); /* 5 ms for HCD to enter low-power mode */
286 spin_lock_irq(&ehci
->lock
);
288 port
= HCS_N_PORTS(ehci
->hcs_params
);
290 u32 __iomem
*hostpc_reg
= &ehci
->regs
->hostpc
[port
];
293 t3
= ehci_readl(ehci
, hostpc_reg
);
294 ehci_writel(ehci
, t3
| HOSTPC_PHCD
, hostpc_reg
);
295 t3
= ehci_readl(ehci
, hostpc_reg
);
296 ehci_dbg(ehci
, "Port %d phy low-power mode %s\n",
297 port
, (t3
& HOSTPC_PHCD
) ?
298 "succeeded" : "failed");
301 spin_unlock_irq(&ehci
->lock
);
303 /* Apparently some devices need a >= 1-uframe delay here */
304 if (ehci
->bus_suspended
)
307 /* turn off now-idle HC */
310 spin_lock_irq(&ehci
->lock
);
311 if (ehci
->enabled_hrtimer_events
& BIT(EHCI_HRTIMER_POLL_DEAD
))
312 ehci_handle_controller_death(ehci
);
313 if (ehci
->rh_state
!= EHCI_RH_RUNNING
)
315 ehci
->rh_state
= EHCI_RH_SUSPENDED
;
317 end_unlink_async(ehci
);
318 unlink_empty_async(ehci
);
319 ehci_handle_intr_unlinks(ehci
);
322 /* allow remote wakeup */
324 if (!hcd
->self
.root_hub
->do_remote_wakeup
)
326 ehci_writel(ehci
, mask
, &ehci
->regs
->intr_enable
);
327 ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
330 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(10);
331 ehci
->enabled_hrtimer_events
= 0;
332 ehci
->next_hrtimer_event
= EHCI_HRTIMER_NO_EVENT
;
333 spin_unlock_irq (&ehci
->lock
);
335 hrtimer_cancel(&ehci
->hrtimer
);
340 /* caller has locked the root hub, and should reset/reinit on error */
341 static int ehci_bus_resume (struct usb_hcd
*hcd
)
343 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
347 unsigned long resume_needed
= 0;
349 if (time_before (jiffies
, ehci
->next_statechange
))
351 spin_lock_irq (&ehci
->lock
);
352 if (!HCD_HW_ACCESSIBLE(hcd
) || ehci
->shutdown
)
355 if (unlikely(ehci
->debug
)) {
356 if (!dbgp_reset_prep())
359 dbgp_external_startup();
362 /* Ideally and we've got a real resume here, and no port's power
363 * was lost. (For PCI, that means Vaux was maintained.) But we
364 * could instead be restoring a swsusp snapshot -- so that BIOS was
365 * the last user of the controller, not reset/pm hardware keeping
366 * state we gave to it.
368 power_okay
= ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
369 ehci_dbg(ehci
, "resume root hub%s\n",
370 power_okay
? "" : " after power loss");
372 /* at least some APM implementations will try to deliver
373 * IRQs right away, so delay them until we're ready.
375 ehci_writel(ehci
, 0, &ehci
->regs
->intr_enable
);
377 /* re-init operational registers */
378 ehci_writel(ehci
, 0, &ehci
->regs
->segment
);
379 ehci_writel(ehci
, ehci
->periodic_dma
, &ehci
->regs
->frame_list
);
380 ehci_writel(ehci
, (u32
) ehci
->async
->qh_dma
, &ehci
->regs
->async_next
);
382 /* restore CMD_RUN, framelist size, and irq threshold */
383 ehci
->command
|= CMD_RUN
;
384 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
385 ehci
->rh_state
= EHCI_RH_RUNNING
;
387 /* Some controller/firmware combinations need a delay during which
388 * they set up the port statuses. See Bugzilla #8190. */
389 spin_unlock_irq(&ehci
->lock
);
391 spin_lock_irq(&ehci
->lock
);
395 /* clear phy low-power mode before resume */
396 if (ehci
->bus_suspended
&& ehci
->has_hostpc
) {
397 i
= HCS_N_PORTS(ehci
->hcs_params
);
399 if (test_bit(i
, &ehci
->bus_suspended
)) {
400 u32 __iomem
*hostpc_reg
=
401 &ehci
->regs
->hostpc
[i
];
403 temp
= ehci_readl(ehci
, hostpc_reg
);
404 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
,
408 spin_unlock_irq(&ehci
->lock
);
410 spin_lock_irq(&ehci
->lock
);
415 /* manually resume the ports we suspended during bus_suspend() */
416 i
= HCS_N_PORTS (ehci
->hcs_params
);
418 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
419 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
420 if (test_bit(i
, &ehci
->bus_suspended
) &&
421 (temp
& PORT_SUSPEND
)) {
423 set_bit(i
, &resume_needed
);
425 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
428 /* msleep for 20ms only if code is trying to resume port */
430 spin_unlock_irq(&ehci
->lock
);
432 spin_lock_irq(&ehci
->lock
);
437 i
= HCS_N_PORTS (ehci
->hcs_params
);
439 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
440 if (test_bit(i
, &resume_needed
)) {
441 temp
&= ~(PORT_RWC_BITS
| PORT_RESUME
);
442 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
443 ehci_vdbg (ehci
, "resumed port %d\n", i
+ 1);
447 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
448 spin_unlock_irq(&ehci
->lock
);
450 ehci_handover_companion_ports(ehci
);
452 /* Now we can safely re-enable irqs */
453 spin_lock_irq(&ehci
->lock
);
456 ehci_writel(ehci
, INTR_MASK
, &ehci
->regs
->intr_enable
);
457 (void) ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
458 spin_unlock_irq(&ehci
->lock
);
463 spin_unlock_irq(&ehci
->lock
);
469 #define ehci_bus_suspend NULL
470 #define ehci_bus_resume NULL
472 #endif /* CONFIG_PM */
474 /*-------------------------------------------------------------------------*/
477 * Sets the owner of a port
479 static void set_owner(struct ehci_hcd
*ehci
, int portnum
, int new_owner
)
481 u32 __iomem
*status_reg
;
485 status_reg
= &ehci
->regs
->port_status
[portnum
];
488 * The controller won't set the OWNER bit if the port is
489 * enabled, so this loop will sometimes require at least two
490 * iterations: one to disable the port and one to set OWNER.
492 for (try = 4; try > 0; --try) {
493 spin_lock_irq(&ehci
->lock
);
494 port_status
= ehci_readl(ehci
, status_reg
);
495 if ((port_status
& PORT_OWNER
) == new_owner
496 || (port_status
& (PORT_OWNER
| PORT_CONNECT
))
500 port_status
^= PORT_OWNER
;
501 port_status
&= ~(PORT_PE
| PORT_RWC_BITS
);
502 ehci_writel(ehci
, port_status
, status_reg
);
504 spin_unlock_irq(&ehci
->lock
);
510 /*-------------------------------------------------------------------------*/
512 static int check_reset_complete (
513 struct ehci_hcd
*ehci
,
515 u32 __iomem
*status_reg
,
518 if (!(port_status
& PORT_CONNECT
))
521 /* if reset finished and it's still not enabled -- handoff */
522 if (!(port_status
& PORT_PE
)) {
524 /* with integrated TT, there's nobody to hand it to! */
525 if (ehci_is_TDI(ehci
)) {
527 "Failed to enable port %d on root hub TT\n",
532 ehci_dbg (ehci
, "port %d full speed --> companion\n",
535 // what happens if HCS_N_CC(params) == 0 ?
536 port_status
|= PORT_OWNER
;
537 port_status
&= ~PORT_RWC_BITS
;
538 ehci_writel(ehci
, port_status
, status_reg
);
540 /* ensure 440EPX ohci controller state is operational */
541 if (ehci
->has_amcc_usb23
)
542 set_ohci_hcfs(ehci
, 1);
544 ehci_dbg(ehci
, "port %d reset complete, port enabled\n",
546 /* ensure 440EPx ohci controller state is suspended */
547 if (ehci
->has_amcc_usb23
)
548 set_ohci_hcfs(ehci
, 0);
554 /*-------------------------------------------------------------------------*/
557 /* build "status change" packet (one or two bytes) from HC registers */
560 ehci_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
562 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
565 int ports
, i
, retval
= 1;
569 /* init status to no-changes */
571 ports
= HCS_N_PORTS (ehci
->hcs_params
);
577 /* Inform the core about resumes-in-progress by returning
578 * a non-zero value even if there are no status changes.
580 status
= ehci
->resuming_ports
;
582 /* Some boards (mostly VIA?) report bogus overcurrent indications,
583 * causing massive log spam unless we completely ignore them. It
584 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
585 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
586 * PORT_POWER; that's surprising, but maybe within-spec.
589 mask
= PORT_CSC
| PORT_PEC
| PORT_OCC
;
591 mask
= PORT_CSC
| PORT_PEC
;
592 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
594 /* no hub change reports (bit 0) for now (power, ...) */
596 /* port N changes (bit N)? */
597 spin_lock_irqsave (&ehci
->lock
, flags
);
599 /* get per-port change detect bits */
601 ppcd
= ehci_readl(ehci
, &ehci
->regs
->status
) >> 16;
603 for (i
= 0; i
< ports
; i
++) {
604 /* leverage per-port change bits feature */
605 if (ehci
->has_ppcd
&& !(ppcd
& (1 << i
)))
607 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
610 * Return status information even for ports with OWNER set.
611 * Otherwise khubd wouldn't see the disconnect event when a
612 * high-speed device is switched over to the companion
613 * controller by the user.
616 if ((temp
& mask
) != 0 || test_bit(i
, &ehci
->port_c_suspend
)
617 || (ehci
->reset_done
[i
] && time_after_eq(
618 jiffies
, ehci
->reset_done
[i
]))) {
620 buf
[0] |= 1 << (i
+ 1);
622 buf
[1] |= 1 << (i
- 7);
626 /* FIXME autosuspend idle root hubs */
627 spin_unlock_irqrestore (&ehci
->lock
, flags
);
628 return status
? retval
: 0;
631 /*-------------------------------------------------------------------------*/
634 ehci_hub_descriptor (
635 struct ehci_hcd
*ehci
,
636 struct usb_hub_descriptor
*desc
638 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
641 desc
->bDescriptorType
= 0x29;
642 desc
->bPwrOn2PwrGood
= 10; /* ehci 1.0, 2.3.9 says 20ms max */
643 desc
->bHubContrCurrent
= 0;
645 desc
->bNbrPorts
= ports
;
646 temp
= 1 + (ports
/ 8);
647 desc
->bDescLength
= 7 + 2 * temp
;
649 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
650 memset(&desc
->u
.hs
.DeviceRemovable
[0], 0, temp
);
651 memset(&desc
->u
.hs
.DeviceRemovable
[temp
], 0xff, temp
);
653 temp
= 0x0008; /* per-port overcurrent reporting */
654 if (HCS_PPC (ehci
->hcs_params
))
655 temp
|= 0x0001; /* per-port power control */
657 temp
|= 0x0002; /* no power switching */
659 // re-enable when we support USB_PORT_FEAT_INDICATOR below.
660 if (HCS_INDICATOR (ehci
->hcs_params
))
661 temp
|= 0x0080; /* per-port indicators (LEDs) */
663 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
666 /*-------------------------------------------------------------------------*/
668 static int ehci_hub_control (
676 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
677 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
678 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
679 (wIndex
& 0xff) - 1];
680 u32 __iomem
*hostpc_reg
= &ehci
->regs
->hostpc
[(wIndex
& 0xff) - 1];
681 u32 temp
, temp1
, status
;
687 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
688 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
689 * (track current state ourselves) ... blink for diagnostics,
690 * power, "this is the one", etc. EHCI spec supports this.
693 spin_lock_irqsave (&ehci
->lock
, flags
);
695 case ClearHubFeature
:
697 case C_HUB_LOCAL_POWER
:
698 case C_HUB_OVER_CURRENT
:
699 /* no hub-wide feature/status flags */
705 case ClearPortFeature
:
706 if (!wIndex
|| wIndex
> ports
)
709 temp
= ehci_readl(ehci
, status_reg
);
710 temp
&= ~PORT_RWC_BITS
;
713 * Even if OWNER is set, so the port is owned by the
714 * companion controller, khubd needs to be able to clear
715 * the port-change status bits (especially
716 * USB_PORT_STAT_C_CONNECTION).
720 case USB_PORT_FEAT_ENABLE
:
721 ehci_writel(ehci
, temp
& ~PORT_PE
, status_reg
);
723 case USB_PORT_FEAT_C_ENABLE
:
724 ehci_writel(ehci
, temp
| PORT_PEC
, status_reg
);
726 case USB_PORT_FEAT_SUSPEND
:
727 if (temp
& PORT_RESET
)
729 if (ehci
->no_selective_suspend
)
731 #ifdef CONFIG_USB_OTG
732 if ((hcd
->self
.otg_port
== (wIndex
+ 1))
733 && hcd
->self
.b_hnp_enable
) {
734 otg_start_hnp(hcd
->phy
->otg
);
738 if (!(temp
& PORT_SUSPEND
))
740 if ((temp
& PORT_PE
) == 0)
743 /* clear phy low-power mode before resume */
744 if (ehci
->has_hostpc
) {
745 temp1
= ehci_readl(ehci
, hostpc_reg
);
746 ehci_writel(ehci
, temp1
& ~HOSTPC_PHCD
,
748 spin_unlock_irqrestore(&ehci
->lock
, flags
);
749 msleep(5);/* wait to leave low-power mode */
750 spin_lock_irqsave(&ehci
->lock
, flags
);
752 /* resume signaling for 20 msec */
753 temp
&= ~PORT_WAKE_BITS
;
754 ehci_writel(ehci
, temp
| PORT_RESUME
, status_reg
);
755 ehci
->reset_done
[wIndex
] = jiffies
756 + msecs_to_jiffies(20);
758 case USB_PORT_FEAT_C_SUSPEND
:
759 clear_bit(wIndex
, &ehci
->port_c_suspend
);
761 case USB_PORT_FEAT_POWER
:
762 if (HCS_PPC (ehci
->hcs_params
))
763 ehci_writel(ehci
, temp
& ~PORT_POWER
,
766 case USB_PORT_FEAT_C_CONNECTION
:
768 /* clear PORTSC bits on disconnect */
770 temp
&= ~PORT_DEV_ADDR
;
772 ehci_writel(ehci
, temp
| PORT_CSC
, status_reg
);
774 case USB_PORT_FEAT_C_OVER_CURRENT
:
775 ehci_writel(ehci
, temp
| PORT_OCC
, status_reg
);
777 case USB_PORT_FEAT_C_RESET
:
778 /* GetPortStatus clears reset */
783 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted write */
785 case GetHubDescriptor
:
786 ehci_hub_descriptor (ehci
, (struct usb_hub_descriptor
*)
790 /* no hub-wide feature/status flags */
792 //cpu_to_le32s ((u32 *) buf);
795 if (!wIndex
|| wIndex
> ports
)
799 temp
= ehci_readl(ehci
, status_reg
);
803 status
|= USB_PORT_STAT_C_CONNECTION
<< 16;
805 status
|= USB_PORT_STAT_C_ENABLE
<< 16;
807 if ((temp
& PORT_OCC
) && !ignore_oc
){
808 status
|= USB_PORT_STAT_C_OVERCURRENT
<< 16;
811 * Hubs should disable port power on over-current.
812 * However, not all EHCI implementations do this
813 * automatically, even if they _do_ support per-port
814 * power switching; they're allowed to just limit the
815 * current. khubd will turn the power back on.
817 if ((temp
& PORT_OC
) && HCS_PPC(ehci
->hcs_params
)) {
819 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
821 temp
= ehci_readl(ehci
, status_reg
);
825 /* whoever resumes must GetPortStatus to complete it!! */
826 if (temp
& PORT_RESUME
) {
828 /* Remote Wakeup received? */
829 if (!ehci
->reset_done
[wIndex
]) {
830 /* resume signaling for 20 msec */
831 ehci
->reset_done
[wIndex
] = jiffies
832 + msecs_to_jiffies(20);
833 /* check the port again */
834 mod_timer(&ehci_to_hcd(ehci
)->rh_timer
,
835 ehci
->reset_done
[wIndex
]);
838 /* resume completed? */
839 else if (time_after_eq(jiffies
,
840 ehci
->reset_done
[wIndex
])) {
841 clear_bit(wIndex
, &ehci
->suspended_ports
);
842 set_bit(wIndex
, &ehci
->port_c_suspend
);
843 ehci
->reset_done
[wIndex
] = 0;
845 /* stop resume signaling */
846 temp
= ehci_readl(ehci
, status_reg
);
848 temp
& ~(PORT_RWC_BITS
| PORT_RESUME
),
850 clear_bit(wIndex
, &ehci
->resuming_ports
);
851 retval
= handshake(ehci
, status_reg
,
852 PORT_RESUME
, 0, 2000 /* 2msec */);
855 "port %d resume error %d\n",
859 temp
&= ~(PORT_SUSPEND
|PORT_RESUME
|(3<<10));
863 /* whoever resets must GetPortStatus to complete it!! */
864 if ((temp
& PORT_RESET
)
865 && time_after_eq(jiffies
,
866 ehci
->reset_done
[wIndex
])) {
867 status
|= USB_PORT_STAT_C_RESET
<< 16;
868 ehci
->reset_done
[wIndex
] = 0;
869 clear_bit(wIndex
, &ehci
->resuming_ports
);
871 /* force reset to complete */
872 ehci_writel(ehci
, temp
& ~(PORT_RWC_BITS
| PORT_RESET
),
874 /* REVISIT: some hardware needs 550+ usec to clear
875 * this bit; seems too long to spin routinely...
877 retval
= handshake(ehci
, status_reg
,
878 PORT_RESET
, 0, 1000);
880 ehci_err (ehci
, "port %d reset error %d\n",
885 /* see what we found out */
886 temp
= check_reset_complete (ehci
, wIndex
, status_reg
,
887 ehci_readl(ehci
, status_reg
));
890 if (!(temp
& (PORT_RESUME
|PORT_RESET
))) {
891 ehci
->reset_done
[wIndex
] = 0;
892 clear_bit(wIndex
, &ehci
->resuming_ports
);
895 /* transfer dedicated ports to the companion hc */
896 if ((temp
& PORT_CONNECT
) &&
897 test_bit(wIndex
, &ehci
->companion_ports
)) {
898 temp
&= ~PORT_RWC_BITS
;
900 ehci_writel(ehci
, temp
, status_reg
);
901 ehci_dbg(ehci
, "port %d --> companion\n", wIndex
+ 1);
902 temp
= ehci_readl(ehci
, status_reg
);
906 * Even if OWNER is set, there's no harm letting khubd
907 * see the wPortStatus values (they should all be 0 except
908 * for PORT_POWER anyway).
911 if (temp
& PORT_CONNECT
) {
912 status
|= USB_PORT_STAT_CONNECTION
;
913 // status may be from integrated TT
914 if (ehci
->has_hostpc
) {
915 temp1
= ehci_readl(ehci
, hostpc_reg
);
916 status
|= ehci_port_speed(ehci
, temp1
);
918 status
|= ehci_port_speed(ehci
, temp
);
921 status
|= USB_PORT_STAT_ENABLE
;
923 /* maybe the port was unsuspended without our knowledge */
924 if (temp
& (PORT_SUSPEND
|PORT_RESUME
)) {
925 status
|= USB_PORT_STAT_SUSPEND
;
926 } else if (test_bit(wIndex
, &ehci
->suspended_ports
)) {
927 clear_bit(wIndex
, &ehci
->suspended_ports
);
928 clear_bit(wIndex
, &ehci
->resuming_ports
);
929 ehci
->reset_done
[wIndex
] = 0;
931 set_bit(wIndex
, &ehci
->port_c_suspend
);
935 status
|= USB_PORT_STAT_OVERCURRENT
;
936 if (temp
& PORT_RESET
)
937 status
|= USB_PORT_STAT_RESET
;
938 if (temp
& PORT_POWER
)
939 status
|= USB_PORT_STAT_POWER
;
940 if (test_bit(wIndex
, &ehci
->port_c_suspend
))
941 status
|= USB_PORT_STAT_C_SUSPEND
<< 16;
943 #ifndef VERBOSE_DEBUG
944 if (status
& ~0xffff) /* only if wPortChange is interesting */
946 dbg_port (ehci
, "GetStatus", wIndex
+ 1, temp
);
947 put_unaligned_le32(status
, buf
);
951 case C_HUB_LOCAL_POWER
:
952 case C_HUB_OVER_CURRENT
:
953 /* no hub-wide feature/status flags */
960 selector
= wIndex
>> 8;
962 if (unlikely(ehci
->debug
)) {
963 /* If the debug port is active any port
964 * feature requests should get denied */
965 if (wIndex
== HCS_DEBUG_PORT(ehci
->hcs_params
) &&
966 (readl(&ehci
->debug
->control
) & DBGP_ENABLED
)) {
971 if (!wIndex
|| wIndex
> ports
)
974 temp
= ehci_readl(ehci
, status_reg
);
975 if (temp
& PORT_OWNER
)
978 temp
&= ~PORT_RWC_BITS
;
980 case USB_PORT_FEAT_SUSPEND
:
981 if (ehci
->no_selective_suspend
)
983 if ((temp
& PORT_PE
) == 0
984 || (temp
& PORT_RESET
) != 0)
987 /* After above check the port must be connected.
988 * Set appropriate bit thus could put phy into low power
989 * mode if we have hostpc feature
991 temp
&= ~PORT_WKCONN_E
;
992 temp
|= PORT_WKDISC_E
| PORT_WKOC_E
;
993 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
994 if (ehci
->has_hostpc
) {
995 spin_unlock_irqrestore(&ehci
->lock
, flags
);
996 msleep(5);/* 5ms for HCD enter low pwr mode */
997 spin_lock_irqsave(&ehci
->lock
, flags
);
998 temp1
= ehci_readl(ehci
, hostpc_reg
);
999 ehci_writel(ehci
, temp1
| HOSTPC_PHCD
,
1001 temp1
= ehci_readl(ehci
, hostpc_reg
);
1002 ehci_dbg(ehci
, "Port%d phy low pwr mode %s\n",
1003 wIndex
, (temp1
& HOSTPC_PHCD
) ?
1004 "succeeded" : "failed");
1006 set_bit(wIndex
, &ehci
->suspended_ports
);
1008 case USB_PORT_FEAT_POWER
:
1009 if (HCS_PPC (ehci
->hcs_params
))
1010 ehci_writel(ehci
, temp
| PORT_POWER
,
1013 case USB_PORT_FEAT_RESET
:
1014 if (temp
& PORT_RESUME
)
1016 /* line status bits may report this as low speed,
1017 * which can be fine if this root hub has a
1018 * transaction translator built in.
1020 if ((temp
& (PORT_PE
|PORT_CONNECT
)) == PORT_CONNECT
1021 && !ehci_is_TDI(ehci
)
1022 && PORT_USB11 (temp
)) {
1024 "port %d low speed --> companion\n",
1028 ehci_vdbg (ehci
, "port %d reset\n", wIndex
+ 1);
1033 * caller must wait, then call GetPortStatus
1034 * usb 2.0 spec says 50 ms resets on root
1036 ehci
->reset_done
[wIndex
] = jiffies
1037 + msecs_to_jiffies (50);
1039 ehci_writel(ehci
, temp
, status_reg
);
1042 /* For downstream facing ports (these): one hub port is put
1043 * into test mode according to USB2 11.24.2.13, then the hub
1044 * must be reset (which for root hub now means rmmod+modprobe,
1045 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1046 * about the EHCI-specific stuff.
1048 case USB_PORT_FEAT_TEST
:
1049 if (!selector
|| selector
> 5)
1051 spin_unlock_irqrestore(&ehci
->lock
, flags
);
1053 spin_lock_irqsave(&ehci
->lock
, flags
);
1055 /* Put all enabled ports into suspend */
1058 &ehci
->regs
->port_status
[ports
];
1060 temp
= ehci_readl(ehci
, sreg
) & ~PORT_RWC_BITS
;
1062 ehci_writel(ehci
, temp
| PORT_SUSPEND
,
1066 spin_unlock_irqrestore(&ehci
->lock
, flags
);
1068 spin_lock_irqsave(&ehci
->lock
, flags
);
1070 temp
= ehci_readl(ehci
, status_reg
);
1071 temp
|= selector
<< 16;
1072 ehci_writel(ehci
, temp
, status_reg
);
1078 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted writes */
1083 /* "stall" on error */
1087 spin_unlock_irqrestore (&ehci
->lock
, flags
);
1091 static void __maybe_unused
ehci_relinquish_port(struct usb_hcd
*hcd
,
1094 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1096 if (ehci_is_TDI(ehci
))
1098 set_owner(ehci
, --portnum
, PORT_OWNER
);
1101 static int __maybe_unused
ehci_port_handed_over(struct usb_hcd
*hcd
,
1104 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1107 if (ehci_is_TDI(ehci
))
1109 reg
= &ehci
->regs
->port_status
[portnum
- 1];
1110 return ehci_readl(ehci
, reg
) & PORT_OWNER
;