aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-hub.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/ehci-hub.c')
-rw-r--r--drivers/usb/host/ehci-hub.c129
1 files changed, 71 insertions, 58 deletions
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index fc9e7cc6ac9b..c7880223738a 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -59,6 +59,7 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
59 /* Give the connections some time to appear */ 59 /* Give the connections some time to appear */
60 msleep(20); 60 msleep(20);
61 61
62 spin_lock_irq(&ehci->lock);
62 port = HCS_N_PORTS(ehci->hcs_params); 63 port = HCS_N_PORTS(ehci->hcs_params);
63 while (port--) { 64 while (port--) {
64 if (test_bit(port, &ehci->owned_ports)) { 65 if (test_bit(port, &ehci->owned_ports)) {
@@ -70,23 +71,30 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
70 clear_bit(port, &ehci->owned_ports); 71 clear_bit(port, &ehci->owned_ports);
71 else if (test_bit(port, &ehci->companion_ports)) 72 else if (test_bit(port, &ehci->companion_ports))
72 ehci_writel(ehci, status & ~PORT_PE, reg); 73 ehci_writel(ehci, status & ~PORT_PE, reg);
73 else 74 else {
75 spin_unlock_irq(&ehci->lock);
74 ehci_hub_control(hcd, SetPortFeature, 76 ehci_hub_control(hcd, SetPortFeature,
75 USB_PORT_FEAT_RESET, port + 1, 77 USB_PORT_FEAT_RESET, port + 1,
76 NULL, 0); 78 NULL, 0);
79 spin_lock_irq(&ehci->lock);
80 }
77 } 81 }
78 } 82 }
83 spin_unlock_irq(&ehci->lock);
79 84
80 if (!ehci->owned_ports) 85 if (!ehci->owned_ports)
81 return; 86 return;
82 msleep(90); /* Wait for resets to complete */ 87 msleep(90); /* Wait for resets to complete */
83 88
89 spin_lock_irq(&ehci->lock);
84 port = HCS_N_PORTS(ehci->hcs_params); 90 port = HCS_N_PORTS(ehci->hcs_params);
85 while (port--) { 91 while (port--) {
86 if (test_bit(port, &ehci->owned_ports)) { 92 if (test_bit(port, &ehci->owned_ports)) {
93 spin_unlock_irq(&ehci->lock);
87 ehci_hub_control(hcd, GetPortStatus, 94 ehci_hub_control(hcd, GetPortStatus,
88 0, port + 1, 95 0, port + 1,
89 (char *) &buf, sizeof(buf)); 96 (char *) &buf, sizeof(buf));
97 spin_lock_irq(&ehci->lock);
90 98
91 /* The companion should now own the port, 99 /* The companion should now own the port,
92 * but if something went wrong the port must not 100 * but if something went wrong the port must not
@@ -105,9 +113,10 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
105 } 113 }
106 114
107 ehci->owned_ports = 0; 115 ehci->owned_ports = 0;
116 spin_unlock_irq(&ehci->lock);
108} 117}
109 118
110static int __maybe_unused ehci_port_change(struct ehci_hcd *ehci) 119static int ehci_port_change(struct ehci_hcd *ehci)
111{ 120{
112 int i = HCS_N_PORTS(ehci->hcs_params); 121 int i = HCS_N_PORTS(ehci->hcs_params);
113 122
@@ -128,12 +137,11 @@ static int __maybe_unused ehci_port_change(struct ehci_hcd *ehci)
128 return 0; 137 return 0;
129} 138}
130 139
131static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 140static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
132 bool suspending, bool do_wakeup) 141 bool suspending, bool do_wakeup)
133{ 142{
134 int port; 143 int port;
135 u32 temp; 144 u32 temp;
136 unsigned long flags;
137 145
138 /* If remote wakeup is enabled for the root hub but disabled 146 /* If remote wakeup is enabled for the root hub but disabled
139 * for the controller, we must adjust all the port wakeup flags 147 * for the controller, we must adjust all the port wakeup flags
@@ -143,22 +151,20 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
143 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup) 151 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
144 return; 152 return;
145 153
146 spin_lock_irqsave(&ehci->lock, flags); 154 spin_lock_irq(&ehci->lock);
147 155
148 /* clear phy low-power mode before changing wakeup flags */ 156 /* clear phy low-power mode before changing wakeup flags */
149 if (ehci->has_hostpc) { 157 if (ehci->has_hostpc) {
150 port = HCS_N_PORTS(ehci->hcs_params); 158 port = HCS_N_PORTS(ehci->hcs_params);
151 while (port--) { 159 while (port--) {
152 u32 __iomem *hostpc_reg; 160 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
153 161
154 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
155 + HOSTPC0 + 4 * port);
156 temp = ehci_readl(ehci, hostpc_reg); 162 temp = ehci_readl(ehci, hostpc_reg);
157 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg); 163 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
158 } 164 }
159 spin_unlock_irqrestore(&ehci->lock, flags); 165 spin_unlock_irq(&ehci->lock);
160 msleep(5); 166 msleep(5);
161 spin_lock_irqsave(&ehci->lock, flags); 167 spin_lock_irq(&ehci->lock);
162 } 168 }
163 169
164 port = HCS_N_PORTS(ehci->hcs_params); 170 port = HCS_N_PORTS(ehci->hcs_params);
@@ -185,10 +191,8 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
185 if (ehci->has_hostpc) { 191 if (ehci->has_hostpc) {
186 port = HCS_N_PORTS(ehci->hcs_params); 192 port = HCS_N_PORTS(ehci->hcs_params);
187 while (port--) { 193 while (port--) {
188 u32 __iomem *hostpc_reg; 194 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
189 195
190 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
191 + HOSTPC0 + 4 * port);
192 temp = ehci_readl(ehci, hostpc_reg); 196 temp = ehci_readl(ehci, hostpc_reg);
193 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); 197 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
194 } 198 }
@@ -198,7 +202,7 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
198 if (!suspending && ehci_port_change(ehci)) 202 if (!suspending && ehci_port_change(ehci))
199 usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); 203 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
200 204
201 spin_unlock_irqrestore(&ehci->lock, flags); 205 spin_unlock_irq(&ehci->lock);
202} 206}
203 207
204static int ehci_bus_suspend (struct usb_hcd *hcd) 208static int ehci_bus_suspend (struct usb_hcd *hcd)
@@ -212,10 +216,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
212 216
213 if (time_before (jiffies, ehci->next_statechange)) 217 if (time_before (jiffies, ehci->next_statechange))
214 msleep(5); 218 msleep(5);
215 del_timer_sync(&ehci->watchdog); 219
216 del_timer_sync(&ehci->iaa_watchdog); 220 /* stop the schedules */
221 ehci_quiesce(ehci);
217 222
218 spin_lock_irq (&ehci->lock); 223 spin_lock_irq (&ehci->lock);
224 if (ehci->rh_state < EHCI_RH_RUNNING)
225 goto done;
219 226
220 /* Once the controller is stopped, port resumes that are already 227 /* Once the controller is stopped, port resumes that are already
221 * in progress won't complete. Hence if remote wakeup is enabled 228 * in progress won't complete. Hence if remote wakeup is enabled
@@ -230,11 +237,6 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
230 } 237 }
231 } 238 }
232 239
233 /* stop schedules, clean any completed work */
234 if (ehci->rh_state == EHCI_RH_RUNNING)
235 ehci_quiesce (ehci);
236 ehci_work(ehci);
237
238 /* Unlike other USB host controller types, EHCI doesn't have 240 /* Unlike other USB host controller types, EHCI doesn't have
239 * any notion of "global" or bus-wide suspend. The driver has 241 * any notion of "global" or bus-wide suspend. The driver has
240 * to manually suspend all the active unsuspended ports, and 242 * to manually suspend all the active unsuspended ports, and
@@ -285,11 +287,9 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
285 287
286 port = HCS_N_PORTS(ehci->hcs_params); 288 port = HCS_N_PORTS(ehci->hcs_params);
287 while (port--) { 289 while (port--) {
288 u32 __iomem *hostpc_reg; 290 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
289 u32 t3; 291 u32 t3;
290 292
291 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
292 + HOSTPC0 + 4 * port);
293 t3 = ehci_readl(ehci, hostpc_reg); 293 t3 = ehci_readl(ehci, hostpc_reg);
294 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); 294 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
295 t3 = ehci_readl(ehci, hostpc_reg); 295 t3 = ehci_readl(ehci, hostpc_reg);
@@ -298,6 +298,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
298 "succeeded" : "failed"); 298 "succeeded" : "failed");
299 } 299 }
300 } 300 }
301 spin_unlock_irq(&ehci->lock);
301 302
302 /* Apparently some devices need a >= 1-uframe delay here */ 303 /* Apparently some devices need a >= 1-uframe delay here */
303 if (ehci->bus_suspended) 304 if (ehci->bus_suspended)
@@ -305,10 +306,18 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
305 306
306 /* turn off now-idle HC */ 307 /* turn off now-idle HC */
307 ehci_halt (ehci); 308 ehci_halt (ehci);
309
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)
314 goto done;
308 ehci->rh_state = EHCI_RH_SUSPENDED; 315 ehci->rh_state = EHCI_RH_SUSPENDED;
309 316
310 if (ehci->reclaim) 317 end_unlink_async(ehci);
311 end_unlink_async(ehci); 318 unlink_empty_async(ehci);
319 ehci_handle_intr_unlinks(ehci);
320 end_free_itds(ehci);
312 321
313 /* allow remote wakeup */ 322 /* allow remote wakeup */
314 mask = INTR_MASK; 323 mask = INTR_MASK;
@@ -317,13 +326,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
317 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 326 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
318 ehci_readl(ehci, &ehci->regs->intr_enable); 327 ehci_readl(ehci, &ehci->regs->intr_enable);
319 328
329 done:
320 ehci->next_statechange = jiffies + msecs_to_jiffies(10); 330 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
331 ehci->enabled_hrtimer_events = 0;
332 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
321 spin_unlock_irq (&ehci->lock); 333 spin_unlock_irq (&ehci->lock);
322 334
323 /* ehci_work() may have re-enabled the watchdog timer, which we do not 335 hrtimer_cancel(&ehci->hrtimer);
324 * want, and so we must delete any pending watchdog timer events.
325 */
326 del_timer_sync(&ehci->watchdog);
327 return 0; 336 return 0;
328} 337}
329 338
@@ -340,10 +349,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
340 if (time_before (jiffies, ehci->next_statechange)) 349 if (time_before (jiffies, ehci->next_statechange))
341 msleep(5); 350 msleep(5);
342 spin_lock_irq (&ehci->lock); 351 spin_lock_irq (&ehci->lock);
343 if (!HCD_HW_ACCESSIBLE(hcd)) { 352 if (!HCD_HW_ACCESSIBLE(hcd) || ehci->shutdown)
344 spin_unlock_irq(&ehci->lock); 353 goto shutdown;
345 return -ESHUTDOWN;
346 }
347 354
348 if (unlikely(ehci->debug)) { 355 if (unlikely(ehci->debug)) {
349 if (!dbgp_reset_prep()) 356 if (!dbgp_reset_prep())
@@ -382,16 +389,17 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
382 spin_unlock_irq(&ehci->lock); 389 spin_unlock_irq(&ehci->lock);
383 msleep(8); 390 msleep(8);
384 spin_lock_irq(&ehci->lock); 391 spin_lock_irq(&ehci->lock);
392 if (ehci->shutdown)
393 goto shutdown;
385 394
386 /* clear phy low-power mode before resume */ 395 /* clear phy low-power mode before resume */
387 if (ehci->bus_suspended && ehci->has_hostpc) { 396 if (ehci->bus_suspended && ehci->has_hostpc) {
388 i = HCS_N_PORTS(ehci->hcs_params); 397 i = HCS_N_PORTS(ehci->hcs_params);
389 while (i--) { 398 while (i--) {
390 if (test_bit(i, &ehci->bus_suspended)) { 399 if (test_bit(i, &ehci->bus_suspended)) {
391 u32 __iomem *hostpc_reg; 400 u32 __iomem *hostpc_reg =
401 &ehci->regs->hostpc[i];
392 402
393 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
394 + HOSTPC0 + 4 * i);
395 temp = ehci_readl(ehci, hostpc_reg); 403 temp = ehci_readl(ehci, hostpc_reg);
396 ehci_writel(ehci, temp & ~HOSTPC_PHCD, 404 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
397 hostpc_reg); 405 hostpc_reg);
@@ -400,6 +408,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
400 spin_unlock_irq(&ehci->lock); 408 spin_unlock_irq(&ehci->lock);
401 msleep(5); 409 msleep(5);
402 spin_lock_irq(&ehci->lock); 410 spin_lock_irq(&ehci->lock);
411 if (ehci->shutdown)
412 goto shutdown;
403 } 413 }
404 414
405 /* manually resume the ports we suspended during bus_suspend() */ 415 /* manually resume the ports we suspended during bus_suspend() */
@@ -420,6 +430,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
420 spin_unlock_irq(&ehci->lock); 430 spin_unlock_irq(&ehci->lock);
421 msleep(20); 431 msleep(20);
422 spin_lock_irq(&ehci->lock); 432 spin_lock_irq(&ehci->lock);
433 if (ehci->shutdown)
434 goto shutdown;
423 } 435 }
424 436
425 i = HCS_N_PORTS (ehci->hcs_params); 437 i = HCS_N_PORTS (ehci->hcs_params);
@@ -431,27 +443,25 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
431 ehci_vdbg (ehci, "resumed port %d\n", i + 1); 443 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
432 } 444 }
433 } 445 }
434 (void) ehci_readl(ehci, &ehci->regs->command);
435
436 /* maybe re-activate the schedule(s) */
437 temp = 0;
438 if (ehci->async->qh_next.qh)
439 temp |= CMD_ASE;
440 if (ehci->periodic_sched)
441 temp |= CMD_PSE;
442 if (temp) {
443 ehci->command |= temp;
444 ehci_writel(ehci, ehci->command, &ehci->regs->command);
445 }
446 446
447 ehci->next_statechange = jiffies + msecs_to_jiffies(5); 447 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
448 spin_unlock_irq(&ehci->lock);
449
450 ehci_handover_companion_ports(ehci);
448 451
449 /* Now we can safely re-enable irqs */ 452 /* Now we can safely re-enable irqs */
453 spin_lock_irq(&ehci->lock);
454 if (ehci->shutdown)
455 goto shutdown;
450 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); 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);
451 459
452 spin_unlock_irq (&ehci->lock);
453 ehci_handover_companion_ports(ehci);
454 return 0; 460 return 0;
461
462 shutdown:
463 spin_unlock_irq(&ehci->lock);
464 return -ESHUTDOWN;
455} 465}
456 466
457#else 467#else
@@ -667,7 +677,7 @@ static int ehci_hub_control (
667 int ports = HCS_N_PORTS (ehci->hcs_params); 677 int ports = HCS_N_PORTS (ehci->hcs_params);
668 u32 __iomem *status_reg = &ehci->regs->port_status[ 678 u32 __iomem *status_reg = &ehci->regs->port_status[
669 (wIndex & 0xff) - 1]; 679 (wIndex & 0xff) - 1];
670 u32 __iomem *hostpc_reg = NULL; 680 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
671 u32 temp, temp1, status; 681 u32 temp, temp1, status;
672 unsigned long flags; 682 unsigned long flags;
673 int retval = 0; 683 int retval = 0;
@@ -680,9 +690,6 @@ static int ehci_hub_control (
680 * power, "this is the one", etc. EHCI spec supports this. 690 * power, "this is the one", etc. EHCI spec supports this.
681 */ 691 */
682 692
683 if (ehci->has_hostpc)
684 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
685 + HOSTPC0 + 4 * ((wIndex & 0xff) - 1));
686 spin_lock_irqsave (&ehci->lock, flags); 693 spin_lock_irqsave (&ehci->lock, flags);
687 switch (typeReq) { 694 switch (typeReq) {
688 case ClearHubFeature: 695 case ClearHubFeature:
@@ -724,7 +731,7 @@ static int ehci_hub_control (
724#ifdef CONFIG_USB_OTG 731#ifdef CONFIG_USB_OTG
725 if ((hcd->self.otg_port == (wIndex + 1)) 732 if ((hcd->self.otg_port == (wIndex + 1))
726 && hcd->self.b_hnp_enable) { 733 && hcd->self.b_hnp_enable) {
727 otg_start_hnp(ehci->transceiver->otg); 734 otg_start_hnp(hcd->phy->otg);
728 break; 735 break;
729 } 736 }
730#endif 737#endif
@@ -734,7 +741,7 @@ static int ehci_hub_control (
734 goto error; 741 goto error;
735 742
736 /* clear phy low-power mode before resume */ 743 /* clear phy low-power mode before resume */
737 if (hostpc_reg) { 744 if (ehci->has_hostpc) {
738 temp1 = ehci_readl(ehci, hostpc_reg); 745 temp1 = ehci_readl(ehci, hostpc_reg);
739 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD, 746 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
740 hostpc_reg); 747 hostpc_reg);
@@ -984,7 +991,7 @@ static int ehci_hub_control (
984 temp &= ~PORT_WKCONN_E; 991 temp &= ~PORT_WKCONN_E;
985 temp |= PORT_WKDISC_E | PORT_WKOC_E; 992 temp |= PORT_WKDISC_E | PORT_WKOC_E;
986 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 993 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
987 if (hostpc_reg) { 994 if (ehci->has_hostpc) {
988 spin_unlock_irqrestore(&ehci->lock, flags); 995 spin_unlock_irqrestore(&ehci->lock, flags);
989 msleep(5);/* 5ms for HCD enter low pwr mode */ 996 msleep(5);/* 5ms for HCD enter low pwr mode */
990 spin_lock_irqsave(&ehci->lock, flags); 997 spin_lock_irqsave(&ehci->lock, flags);
@@ -1041,7 +1048,9 @@ static int ehci_hub_control (
1041 case USB_PORT_FEAT_TEST: 1048 case USB_PORT_FEAT_TEST:
1042 if (!selector || selector > 5) 1049 if (!selector || selector > 5)
1043 goto error; 1050 goto error;
1051 spin_unlock_irqrestore(&ehci->lock, flags);
1044 ehci_quiesce(ehci); 1052 ehci_quiesce(ehci);
1053 spin_lock_irqsave(&ehci->lock, flags);
1045 1054
1046 /* Put all enabled ports into suspend */ 1055 /* Put all enabled ports into suspend */
1047 while (ports--) { 1056 while (ports--) {
@@ -1053,7 +1062,11 @@ static int ehci_hub_control (
1053 ehci_writel(ehci, temp | PORT_SUSPEND, 1062 ehci_writel(ehci, temp | PORT_SUSPEND,
1054 sreg); 1063 sreg);
1055 } 1064 }
1065
1066 spin_unlock_irqrestore(&ehci->lock, flags);
1056 ehci_halt(ehci); 1067 ehci_halt(ehci);
1068 spin_lock_irqsave(&ehci->lock, flags);
1069
1057 temp = ehci_readl(ehci, status_reg); 1070 temp = ehci_readl(ehci, status_reg);
1058 temp |= selector << 16; 1071 temp |= selector << 16;
1059 ehci_writel(ehci, temp, status_reg); 1072 ehci_writel(ehci, temp, status_reg);