32 #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
36 static int ehci_hub_control(
48 static void ehci_handover_companion_ports(
struct ehci_hcd *ehci)
54 struct usb_hcd *hcd = ehci_to_hcd(ehci);
62 spin_lock_irq(&ehci->
lock);
66 reg = &ehci->
regs->port_status[
port];
73 ehci_writel(ehci, status & ~
PORT_PE, reg);
75 spin_unlock_irq(&ehci->
lock);
76 ehci_hub_control(hcd, SetPortFeature,
79 spin_lock_irq(&ehci->
lock);
83 spin_unlock_irq(&ehci->
lock);
89 spin_lock_irq(&ehci->
lock);
93 spin_unlock_irq(&ehci->
lock);
94 ehci_hub_control(hcd, GetPortStatus,
96 (
char *) &buf,
sizeof(buf));
97 spin_lock_irq(&ehci->
lock);
103 reg = &ehci->
regs->port_status[
port];
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);
116 spin_unlock_irq(&ehci->
lock);
119 static int ehci_port_change(
struct ehci_hcd *ehci)
125 if (ehci_readl(ehci, &ehci->
regs->status) &
STS_PCD)
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)
151 if (!ehci_to_hcd(ehci)->
self.root_hub->do_remote_wakeup || do_wakeup)
154 spin_lock_irq(&ehci->
lock);
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);
185 ehci_vdbg(ehci,
"port %d, %08x -> %08x\n",
187 ehci_writel(ehci, t2, reg);
196 temp = ehci_readl(ehci, hostpc_reg);
202 if (!suspending && ehci_port_change(ehci))
203 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
205 spin_unlock_irq(&ehci->
lock);
210 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
215 ehci_dbg(ehci,
"suspend root hub\n");
223 spin_lock_irq (&ehci->
lock);
232 if (hcd->self.root_hub->do_remote_wakeup) {
234 spin_unlock_irq(&ehci->
lock);
235 ehci_dbg(ehci,
"suspend failed because a port is resuming\n");
263 if (hcd->self.root_hub->do_remote_wakeup) {
276 ehci_vdbg (ehci,
"port %d, %08x -> %08x\n",
278 ehci_writel(ehci, t2, reg);
284 spin_unlock_irq(&ehci->
lock);
286 spin_lock_irq(&ehci->
lock);
293 t3 = ehci_readl(ehci, hostpc_reg);
295 t3 = ehci_readl(ehci, hostpc_reg);
296 ehci_dbg(ehci,
"Port %d phy low-power mode %s\n",
298 "succeeded" :
"failed");
301 spin_unlock_irq(&ehci->
lock);
310 spin_lock_irq(&ehci->
lock);
312 ehci_handle_controller_death(ehci);
317 end_unlink_async(ehci);
318 unlink_empty_async(ehci);
319 ehci_handle_intr_unlinks(ehci);
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);
333 spin_unlock_irq (&ehci->
lock);
343 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
347 unsigned long resume_needed = 0;
351 spin_lock_irq (&ehci->
lock);
352 if (!HCD_HW_ACCESSIBLE(hcd) || ehci->
shutdown)
356 if (!dbgp_reset_prep(hcd))
359 dbgp_external_startup(hcd);
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");
375 ehci_writel(ehci, 0, &ehci->
regs->intr_enable);
378 ehci_writel(ehci, 0, &ehci->
regs->segment);
380 ehci_writel(ehci, (
u32) ehci->
async->qh_dma, &ehci->
regs->async_next);
384 ehci_writel(ehci, ehci->
command, &ehci->
regs->command);
389 spin_unlock_irq(&ehci->
lock);
391 spin_lock_irq(&ehci->
lock);
401 &ehci->
regs->hostpc[
i];
403 temp = ehci_readl(ehci, hostpc_reg);
408 spin_unlock_irq(&ehci->
lock);
410 spin_lock_irq(&ehci->
lock);
418 temp = ehci_readl(ehci, &ehci->
regs->port_status [i]);
425 ehci_writel(ehci, temp, &ehci->
regs->port_status [i]);
430 spin_unlock_irq(&ehci->
lock);
432 spin_lock_irq(&ehci->
lock);
439 temp = ehci_readl(ehci, &ehci->
regs->port_status [i]);
442 ehci_writel(ehci, temp, &ehci->
regs->port_status [i]);
443 ehci_vdbg (ehci,
"resumed port %d\n", i + 1);
448 spin_unlock_irq(&ehci->
lock);
450 ehci_handover_companion_ports(ehci);
453 spin_lock_irq(&ehci->
lock);
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
479 static void set_owner(
struct ehci_hcd *ehci,
int portnum,
int new_owner)
485 status_reg = &ehci->
regs->port_status[portnum];
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
502 ehci_writel(ehci, port_status, status_reg);
504 spin_unlock_irq(&ehci->
lock);
512 static int check_reset_complete (
522 if (!(port_status & PORT_PE)) {
527 "Failed to enable port %d on root hub TT\n",
532 ehci_dbg (ehci,
"port %d full speed --> companion\n",
538 ehci_writel(ehci, port_status, status_reg);
542 set_ohci_hcfs(ehci, 1);
544 ehci_dbg(ehci,
"port %d reset complete, port enabled\n",
548 set_ohci_hcfs(ehci, 0);
560 ehci_hub_status_data (
struct usb_hcd *hcd,
char *buf)
562 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
601 ppcd = ehci_readl(ehci, &ehci->
regs->status) >> 16;
603 for (i = 0; i < ports; i++) {
605 if (ehci->
has_ppcd && !(ppcd & (1 << i)))
607 temp = ehci_readl(ehci, &ehci->
regs->port_status [i]);
620 buf [0] |= 1 << (i + 1);
622 buf [1] |= 1 << (i - 7);
627 spin_unlock_irqrestore (&ehci->
lock, flags);
628 return status ? retval : 0;
634 ehci_hub_descriptor (
646 temp = 1 + (ports / 8);
668 static int ehci_hub_control (
676 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
679 (wIndex & 0xff) - 1];
680 u32 __iomem *hostpc_reg = &ehci->
regs->hostpc[(wIndex & 0xff) - 1];
695 case ClearHubFeature:
705 case ClearPortFeature:
706 if (!wIndex || wIndex > ports)
709 temp = ehci_readl(ehci, status_reg);
721 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
724 ehci_writel(ehci, temp |
PORT_PEC, status_reg);
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)
745 temp1 = ehci_readl(ehci, hostpc_reg);
748 spin_unlock_irqrestore(&ehci->
lock, flags);
772 ehci_writel(ehci, temp |
PORT_CSC, status_reg);
775 ehci_writel(ehci, temp |
PORT_OCC, status_reg);
783 ehci_readl(ehci, &ehci->
regs->command);
785 case GetHubDescriptor:
795 if (!wIndex || wIndex > ports)
799 temp = ehci_readl(ehci, status_reg);
807 if ((temp &
PORT_OCC) && !ignore_oc){
821 temp = ehci_readl(ehci, status_reg);
846 temp = ehci_readl(ehci, status_reg);
852 PORT_RESUME, 0, 2000 );
855 "port %d resume error %d\n",
859 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
864 if ((temp & PORT_RESET)
878 PORT_RESET, 0, 1000);
880 ehci_err (ehci,
"port %d reset error %d\n",
886 temp = check_reset_complete (ehci, wIndex, status_reg,
887 ehci_readl(ehci, status_reg));
890 if (!(temp & (PORT_RESUME|PORT_RESET))) {
896 if ((temp & PORT_CONNECT) &&
900 ehci_writel(ehci, temp, status_reg);
901 ehci_dbg(ehci,
"port %d --> companion\n", wIndex + 1);
902 temp = ehci_readl(ehci, status_reg);
911 if (temp & PORT_CONNECT) {
915 temp1 = ehci_readl(ehci, hostpc_reg);
924 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
936 if (temp & PORT_RESET)
943 #ifndef VERBOSE_DEBUG
944 if (status & ~0xffff)
946 dbg_port (ehci,
"GetStatus", wIndex + 1, temp);
960 selector = wIndex >> 8;
971 if (!wIndex || wIndex > ports)
974 temp = ehci_readl(ehci, status_reg);
975 if (temp & PORT_OWNER)
983 if ((temp & PORT_PE) == 0
984 || (temp & PORT_RESET) != 0)
993 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
995 spin_unlock_irqrestore(&ehci->
lock, flags);
998 temp1 = ehci_readl(ehci, hostpc_reg);
1001 temp1 = ehci_readl(ehci, hostpc_reg);
1002 ehci_dbg(ehci,
"Port%d phy low pwr mode %s\n",
1004 "succeeded" :
"failed");
1010 ehci_writel(ehci, temp | PORT_POWER,
1014 if (temp & PORT_RESUME)
1020 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1024 "port %d low speed --> companion\n",
1028 ehci_vdbg (ehci,
"port %d reset\n", wIndex + 1);
1039 ehci_writel(ehci, temp, status_reg);
1049 if (!selector || selector > 5)
1051 spin_unlock_irqrestore(&ehci->
lock, flags);
1058 &ehci->
regs->port_status[ports];
1062 ehci_writel(ehci, temp | PORT_SUSPEND,
1066 spin_unlock_irqrestore(&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);
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);
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);
1109 reg = &ehci->
regs->port_status[portnum - 1];