1 #if 0 2 3 /* 4 * OHCI HCD (Host Controller Driver) for USB. 5 * 6 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 7 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 8 * 9 * This file is licenced under GPL 10 */ 11 12 /*-------------------------------------------------------------------------*/ 13 14 /* 15 * OHCI Root Hub ... the nonsharable stuff 16 */ 17 18 #define dbg_port(hc,label,num,value) \ 19 ohci_dbg (hc, \ 20 "%s roothub.portstatus [%d] " \ 21 "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \ 22 label, num, temp, \ 23 (temp & RH_PS_PRSC) ? " PRSC" : "", \ 24 (temp & RH_PS_OCIC) ? " OCIC" : "", \ 25 (temp & RH_PS_PSSC) ? " PSSC" : "", \ 26 (temp & RH_PS_PESC) ? " PESC" : "", \ 27 (temp & RH_PS_CSC) ? " CSC" : "", \ 28 \ 29 (temp & RH_PS_LSDA) ? " LSDA" : "", \ 30 (temp & RH_PS_PPS) ? " PPS" : "", \ 31 (temp & RH_PS_PRS) ? " PRS" : "", \ 32 (temp & RH_PS_POCI) ? " POCI" : "", \ 33 (temp & RH_PS_PSS) ? " PSS" : "", \ 34 \ 35 (temp & RH_PS_PES) ? " PES" : "", \ 36 (temp & RH_PS_CCS) ? " CCS" : "" \ 37 ); 38 39 /*-------------------------------------------------------------------------*/ 40 41 #define OHCI_SCHED_ENABLES \ 42 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 43 44 static void update_done_list(struct ohci_hcd *); 45 static void ohci_work(struct ohci_hcd *); 46 47 #ifdef CONFIG_PM 48 static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) 49 __releases(ohci->lock) 50 __acquires(ohci->lock) 51 { 52 int status = 0; 53 54 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 55 switch (ohci->hc_control & OHCI_CTRL_HCFS) { 56 case OHCI_USB_RESUME: 57 ohci_dbg (ohci, "resume/suspend?\n"); 58 ohci->hc_control &= ~OHCI_CTRL_HCFS; 59 ohci->hc_control |= OHCI_USB_RESET; 60 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 61 (void) ohci_readl (ohci, &ohci->regs->control); 62 /* FALL THROUGH */ 63 case OHCI_USB_RESET: 64 status = -EBUSY; 65 ohci_dbg (ohci, "needs reinit!\n"); 66 goto done; 67 case OHCI_USB_SUSPEND: 68 if (!ohci->autostop) { 69 ohci_dbg (ohci, "already suspended\n"); 70 goto done; 71 } 72 } 73 ohci_dbg (ohci, "%s root hub\n", 74 autostop ? "auto-stop" : "suspend"); 75 76 /* First stop any processing */ 77 if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) { 78 ohci->hc_control &= ~OHCI_SCHED_ENABLES; 79 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 80 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 81 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus); 82 83 /* sched disables take effect on the next frame, 84 * then the last WDH could take 6+ msec 85 */ 86 ohci_dbg (ohci, "stopping schedules ...\n"); 87 ohci->autostop = 0; 88 spin_unlock_irq (&ohci->lock); 89 msleep (8); 90 spin_lock_irq (&ohci->lock); 91 } 92 update_done_list(ohci); 93 ohci_work(ohci); 94 95 /* 96 * Some controllers don't handle "global" suspend properly if 97 * there are unsuspended ports. For these controllers, put all 98 * the enabled ports into suspend before suspending the root hub. 99 */ 100 if (ohci->flags & OHCI_QUIRK_GLOBAL_SUSPEND) { 101 __hc32 __iomem *portstat = ohci->regs->roothub.portstatus; 102 int i; 103 unsigned temp; 104 105 for (i = 0; i < ohci->num_ports; (++i, ++portstat)) { 106 temp = ohci_readl(ohci, portstat); 107 if ((temp & (RH_PS_PES | RH_PS_PSS)) == 108 RH_PS_PES) 109 ohci_writel(ohci, RH_PS_PSS, portstat); 110 } 111 } 112 113 /* maybe resume can wake root hub */ 114 if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) { 115 ohci->hc_control |= OHCI_CTRL_RWE; 116 } else { 117 ohci_writel(ohci, OHCI_INTR_RHSC | OHCI_INTR_RD, 118 &ohci->regs->intrdisable); 119 ohci->hc_control &= ~OHCI_CTRL_RWE; 120 } 121 122 /* Suspend hub ... this is the "global (to this bus) suspend" mode, 123 * which doesn't imply ports will first be individually suspended. 124 */ 125 ohci->hc_control &= ~OHCI_CTRL_HCFS; 126 ohci->hc_control |= OHCI_USB_SUSPEND; 127 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 128 (void) ohci_readl (ohci, &ohci->regs->control); 129 130 /* no resumes until devices finish suspending */ 131 if (!autostop) { 132 ohci->next_statechange = jiffies + msecs_to_jiffies (5); 133 ohci->autostop = 0; 134 ohci->rh_state = OHCI_RH_SUSPENDED; 135 } 136 137 done: 138 return status; 139 } 140 141 static inline struct ed *find_head (struct ed *ed) 142 { 143 /* for bulk and control lists */ 144 while (ed->ed_prev) 145 ed = ed->ed_prev; 146 return ed; 147 } 148 149 /* caller has locked the root hub */ 150 static int ohci_rh_resume (struct ohci_hcd *ohci) 151 __releases(ohci->lock) 152 __acquires(ohci->lock) 153 { 154 struct usb_hcd *hcd = ohci_to_hcd (ohci); 155 u32 temp, enables; 156 int status = -EINPROGRESS; 157 int autostopped = ohci->autostop; 158 159 ohci->autostop = 0; 160 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 161 162 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 163 /* this can happen after resuming a swsusp snapshot */ 164 if (ohci->rh_state != OHCI_RH_RUNNING) { 165 ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", 166 ohci->hc_control); 167 status = -EBUSY; 168 /* this happens when pmcore resumes HC then root */ 169 } else { 170 ohci_dbg (ohci, "duplicate resume\n"); 171 status = 0; 172 } 173 } else switch (ohci->hc_control & OHCI_CTRL_HCFS) { 174 case OHCI_USB_SUSPEND: 175 ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES); 176 ohci->hc_control |= OHCI_USB_RESUME; 177 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 178 (void) ohci_readl (ohci, &ohci->regs->control); 179 ohci_dbg (ohci, "%s root hub\n", 180 autostopped ? "auto-start" : "resume"); 181 break; 182 case OHCI_USB_RESUME: 183 /* HCFS changes sometime after INTR_RD */ 184 ohci_dbg(ohci, "%swakeup root hub\n", 185 autostopped ? "auto-" : ""); 186 break; 187 case OHCI_USB_OPER: 188 /* this can happen after resuming a swsusp snapshot */ 189 ohci_dbg (ohci, "snapshot resume? reinit\n"); 190 status = -EBUSY; 191 break; 192 default: /* RESET, we lost power */ 193 ohci_dbg (ohci, "lost power\n"); 194 status = -EBUSY; 195 } 196 if (status == -EBUSY) { 197 if (!autostopped) { 198 spin_unlock_irq (&ohci->lock); 199 status = ohci_restart (ohci); 200 201 usb_root_hub_lost_power(hcd->self.root_hub); 202 203 spin_lock_irq (&ohci->lock); 204 } 205 return status; 206 } 207 if (status != -EINPROGRESS) 208 return status; 209 if (autostopped) 210 goto skip_resume; 211 spin_unlock_irq (&ohci->lock); 212 213 /* Some controllers (lucent erratum) need extra-long delays */ 214 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1); 215 216 temp = ohci_readl (ohci, &ohci->regs->control); 217 temp &= OHCI_CTRL_HCFS; 218 if (temp != OHCI_USB_RESUME) { 219 ohci_err (ohci, "controller won't resume\n"); 220 spin_lock_irq(&ohci->lock); 221 return -EBUSY; 222 } 223 224 /* disable old schedule state, reinit from scratch */ 225 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); 226 ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); 227 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); 228 ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); 229 ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent); 230 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); 231 232 /* Sometimes PCI D3 suspend trashes frame timings ... */ 233 periodic_reinit (ohci); 234 235 /* 236 * The following code is executed with ohci->lock held and 237 * irqs disabled if and only if autostopped is true. This 238 * will cause sparse to warn about a "context imbalance". 239 */ 240 skip_resume: 241 /* interrupts might have been disabled */ 242 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 243 if (ohci->ed_rm_list) 244 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); 245 246 /* Then re-enable operations */ 247 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); 248 (void) ohci_readl (ohci, &ohci->regs->control); 249 if (!autostopped) 250 msleep (3); 251 252 temp = ohci->hc_control; 253 temp &= OHCI_CTRL_RWC; 254 temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 255 ohci->hc_control = temp; 256 ohci_writel (ohci, temp, &ohci->regs->control); 257 (void) ohci_readl (ohci, &ohci->regs->control); 258 259 /* TRSMRCY */ 260 if (!autostopped) { 261 msleep (10); 262 spin_lock_irq (&ohci->lock); 263 } 264 /* now ohci->lock is always held and irqs are always disabled */ 265 266 /* keep it alive for more than ~5x suspend + resume costs */ 267 ohci->next_statechange = jiffies + STATECHANGE_DELAY; 268 269 /* maybe turn schedules back on */ 270 enables = 0; 271 temp = 0; 272 if (!ohci->ed_rm_list) { 273 if (ohci->ed_controltail) { 274 ohci_writel (ohci, 275 find_head (ohci->ed_controltail)->dma, 276 &ohci->regs->ed_controlhead); 277 enables |= OHCI_CTRL_CLE; 278 temp |= OHCI_CLF; 279 } 280 if (ohci->ed_bulktail) { 281 ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma, 282 &ohci->regs->ed_bulkhead); 283 enables |= OHCI_CTRL_BLE; 284 temp |= OHCI_BLF; 285 } 286 } 287 if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs) 288 enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE; 289 if (enables) { 290 ohci_dbg (ohci, "restarting schedules ... %08x\n", enables); 291 ohci->hc_control |= enables; 292 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 293 if (temp) 294 ohci_writel (ohci, temp, &ohci->regs->cmdstatus); 295 (void) ohci_readl (ohci, &ohci->regs->control); 296 } 297 298 ohci->rh_state = OHCI_RH_RUNNING; 299 return 0; 300 } 301 302 static int ohci_bus_suspend (struct usb_hcd *hcd) 303 { 304 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 305 int rc; 306 307 spin_lock_irq (&ohci->lock); 308 309 if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 310 rc = -ESHUTDOWN; 311 else 312 rc = ohci_rh_suspend (ohci, 0); 313 spin_unlock_irq (&ohci->lock); 314 315 if (rc == 0) { 316 del_timer_sync(&ohci->io_watchdog); 317 ohci->prev_frame_no = IO_WATCHDOG_OFF; 318 } 319 return rc; 320 } 321 322 static int ohci_bus_resume (struct usb_hcd *hcd) 323 { 324 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 325 int rc; 326 327 if (time_before (jiffies, ohci->next_statechange)) 328 msleep(5); 329 330 spin_lock_irq (&ohci->lock); 331 332 if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 333 rc = -ESHUTDOWN; 334 else 335 rc = ohci_rh_resume (ohci); 336 spin_unlock_irq (&ohci->lock); 337 338 /* poll until we know a device is connected or we autostop */ 339 if (rc == 0) 340 usb_hcd_poll_rh_status(hcd); 341 return rc; 342 } 343 344 /* Carry out polling-, autostop-, and autoresume-related state changes */ 345 static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 346 int any_connected, int rhsc_status) 347 { 348 int poll_rh = 1; 349 int rhsc_enable; 350 351 /* Some broken controllers never turn off RHSC in the interrupt 352 * status register. For their sake we won't re-enable RHSC 353 * interrupts if the interrupt bit is already active. 354 */ 355 rhsc_enable = ohci_readl(ohci, &ohci->regs->intrenable) & 356 OHCI_INTR_RHSC; 357 358 switch (ohci->hc_control & OHCI_CTRL_HCFS) { 359 case OHCI_USB_OPER: 360 /* If no status changes are pending, enable RHSC interrupts. */ 361 if (!rhsc_enable && !rhsc_status && !changed) { 362 rhsc_enable = OHCI_INTR_RHSC; 363 ohci_writel(ohci, rhsc_enable, &ohci->regs->intrenable); 364 } 365 366 /* Keep on polling until we know a device is connected 367 * and RHSC is enabled, or until we autostop. 368 */ 369 if (!ohci->autostop) { 370 if (any_connected || 371 !device_may_wakeup(&ohci_to_hcd(ohci) 372 ->self.root_hub->dev)) { 373 if (rhsc_enable) 374 poll_rh = 0; 375 } else { 376 ohci->autostop = 1; 377 ohci->next_statechange = jiffies + HZ; 378 } 379 380 /* if no devices have been attached for one second, autostop */ 381 } else { 382 if (changed || any_connected) { 383 ohci->autostop = 0; 384 ohci->next_statechange = jiffies + 385 STATECHANGE_DELAY; 386 } else if (time_after_eq(jiffies, 387 ohci->next_statechange) 388 && !ohci->ed_rm_list 389 && !(ohci->hc_control & 390 OHCI_SCHED_ENABLES)) { 391 ohci_rh_suspend(ohci, 1); 392 if (rhsc_enable) 393 poll_rh = 0; 394 } 395 } 396 break; 397 398 case OHCI_USB_SUSPEND: 399 case OHCI_USB_RESUME: 400 /* if there is a port change, autostart or ask to be resumed */ 401 if (changed) { 402 if (ohci->autostop) 403 ohci_rh_resume(ohci); 404 else 405 usb_hcd_resume_root_hub(ohci_to_hcd(ohci)); 406 407 /* If remote wakeup is disabled, stop polling */ 408 } else if (!ohci->autostop && 409 !ohci_to_hcd(ohci)->self.root_hub-> 410 do_remote_wakeup) { 411 poll_rh = 0; 412 413 } else { 414 /* If no status changes are pending, 415 * enable RHSC interrupts 416 */ 417 if (!rhsc_enable && !rhsc_status) { 418 rhsc_enable = OHCI_INTR_RHSC; 419 ohci_writel(ohci, rhsc_enable, 420 &ohci->regs->intrenable); 421 } 422 /* Keep polling until RHSC is enabled */ 423 if (rhsc_enable) 424 poll_rh = 0; 425 } 426 break; 427 } 428 return poll_rh; 429 } 430 431 #else /* CONFIG_PM */ 432 433 static inline int ohci_rh_resume(struct ohci_hcd *ohci) 434 { 435 return 0; 436 } 437 438 /* Carry out polling-related state changes. 439 * autostop isn't used when CONFIG_PM is turned off. 440 */ 441 static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 442 int any_connected, int rhsc_status) 443 { 444 /* If RHSC is enabled, don't poll */ 445 if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) 446 return 0; 447 448 /* If status changes are pending, continue polling. 449 * Conversely, if no status changes are pending but the RHSC 450 * status bit was set, then RHSC may be broken so continue polling. 451 */ 452 if (changed || rhsc_status) 453 return 1; 454 455 /* It's safe to re-enable RHSC interrupts */ 456 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); 457 return 0; 458 } 459 460 #endif /* CONFIG_PM */ 461 462 /*-------------------------------------------------------------------------*/ 463 464 /* build "status change" packet (one or two bytes) from HC registers */ 465 466 int ohci_hub_status_data(struct usb_hcd *hcd, char *buf) 467 { 468 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 469 int i, changed = 0, length = 1; 470 int any_connected = 0; 471 int rhsc_status; 472 unsigned long flags; 473 474 spin_lock_irqsave (&ohci->lock, flags); 475 if (!HCD_HW_ACCESSIBLE(hcd)) 476 goto done; 477 478 /* undocumented erratum seen on at least rev D */ 479 if ((ohci->flags & OHCI_QUIRK_AMD756) 480 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { 481 ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n", 482 ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); 483 /* retry later; "should not happen" */ 484 goto done; 485 } 486 487 /* init status */ 488 if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC)) 489 buf [0] = changed = 1; 490 else 491 buf [0] = 0; 492 if (ohci->num_ports > 7) { 493 buf [1] = 0; 494 length++; 495 } 496 497 /* Clear the RHSC status flag before reading the port statuses */ 498 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrstatus); 499 rhsc_status = ohci_readl(ohci, &ohci->regs->intrstatus) & 500 OHCI_INTR_RHSC; 501 502 /* look at each port */ 503 for (i = 0; i < ohci->num_ports; i++) { 504 u32 status = roothub_portstatus (ohci, i); 505 506 /* can't autostop if ports are connected */ 507 any_connected |= (status & RH_PS_CCS); 508 509 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 510 | RH_PS_OCIC | RH_PS_PRSC)) { 511 changed = 1; 512 if (i < 7) 513 buf [0] |= 1 << (i + 1); 514 else 515 buf [1] |= 1 << (i - 7); 516 } 517 } 518 519 if (ohci_root_hub_state_changes(ohci, changed, 520 any_connected, rhsc_status)) 521 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 522 else 523 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 524 525 526 done: 527 spin_unlock_irqrestore (&ohci->lock, flags); 528 529 return changed ? length : 0; 530 } 531 EXPORT_SYMBOL_GPL(ohci_hub_status_data); 532 533 /*-------------------------------------------------------------------------*/ 534 535 static void 536 ohci_hub_descriptor ( 537 struct ohci_hcd *ohci, 538 struct usb_hub_descriptor *desc 539 ) { 540 u32 rh = roothub_a (ohci); 541 u16 temp; 542 543 desc->bDescriptorType = USB_DT_HUB; 544 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; 545 desc->bHubContrCurrent = 0; 546 547 desc->bNbrPorts = ohci->num_ports; 548 temp = 1 + (ohci->num_ports / 8); 549 desc->bDescLength = 7 + 2 * temp; 550 551 temp = HUB_CHAR_COMMON_LPSM | HUB_CHAR_COMMON_OCPM; 552 if (rh & RH_A_NPS) /* no power switching? */ 553 temp |= HUB_CHAR_NO_LPSM; 554 if (rh & RH_A_PSM) /* per-port power switching? */ 555 temp |= HUB_CHAR_INDV_PORT_LPSM; 556 if (rh & RH_A_NOCP) /* no overcurrent reporting? */ 557 temp |= HUB_CHAR_NO_OCPM; 558 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ 559 temp |= HUB_CHAR_INDV_PORT_OCPM; 560 desc->wHubCharacteristics = cpu_to_le16(temp); 561 562 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 563 rh = roothub_b (ohci); 564 memset(desc->u.hs.DeviceRemovable, 0xff, 565 sizeof(desc->u.hs.DeviceRemovable)); 566 desc->u.hs.DeviceRemovable[0] = rh & RH_B_DR; 567 if (ohci->num_ports > 7) { 568 desc->u.hs.DeviceRemovable[1] = (rh & RH_B_DR) >> 8; 569 desc->u.hs.DeviceRemovable[2] = 0xff; 570 } else 571 desc->u.hs.DeviceRemovable[1] = 0xff; 572 } 573 574 /*-------------------------------------------------------------------------*/ 575 576 #ifdef CONFIG_USB_OTG 577 578 static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) 579 { 580 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 581 u32 status; 582 583 if (!port) 584 return -EINVAL; 585 port--; 586 587 /* start port reset before HNP protocol times out */ 588 status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); 589 if (!(status & RH_PS_CCS)) 590 return -ENODEV; 591 592 /* hub_wq will finish the reset later */ 593 ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); 594 return 0; 595 } 596 597 #else 598 599 #define ohci_start_port_reset NULL 600 601 #endif 602 603 /*-------------------------------------------------------------------------*/ 604 605 606 /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, 607 * not necessarily continuous ... to guard against resume signaling. 608 */ 609 #define PORT_RESET_MSEC 10 610 611 /* this timer value might be vendor-specific ... */ 612 #define PORT_RESET_HW_MSEC 10 613 614 /* wrap-aware logic morphed from <linux/jiffies.h> */ 615 #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 616 617 /* called from some task, normally hub_wq */ 618 static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) 619 { 620 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 621 u32 temp = 0; 622 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); 623 u16 reset_done = now + PORT_RESET_MSEC; 624 int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC); 625 626 /* build a "continuous enough" reset signal, with up to 627 * 3msec gap between pulses. scheduler HZ==100 must work; 628 * this might need to be deadline-scheduled. 629 */ 630 do { 631 int limit_2; 632 633 /* spin until any current reset finishes */ 634 limit_2 = PORT_RESET_HW_MSEC * 2; 635 while (--limit_2 >= 0) { 636 temp = ohci_readl (ohci, portstat); 637 /* handle e.g. CardBus eject */ 638 if (temp == ~(u32)0) 639 return -ESHUTDOWN; 640 if (!(temp & RH_PS_PRS)) 641 break; 642 udelay (500); 643 } 644 645 /* timeout (a hardware error) has been observed when 646 * EHCI sets CF while this driver is resetting a port; 647 * presumably other disconnect paths might do it too. 648 */ 649 if (limit_2 < 0) { 650 ohci_dbg(ohci, 651 "port[%d] reset timeout, stat %08x\n", 652 port, temp); 653 break; 654 } 655 656 if (!(temp & RH_PS_CCS)) 657 break; 658 if (temp & RH_PS_PRSC) 659 ohci_writel (ohci, RH_PS_PRSC, portstat); 660 661 /* start the next reset, sleep till it's probably done */ 662 ohci_writel (ohci, RH_PS_PRS, portstat); 663 msleep(PORT_RESET_HW_MSEC); 664 now = ohci_readl(ohci, &ohci->regs->fmnumber); 665 } while (tick_before(now, reset_done) && --limit_1 >= 0); 666 667 /* caller synchronizes using PRSC ... and handles PRS 668 * still being set when this returns. 669 */ 670 671 return 0; 672 } 673 674 int ohci_hub_control( 675 struct usb_hcd *hcd, 676 u16 typeReq, 677 u16 wValue, 678 u16 wIndex, 679 char *buf, 680 u16 wLength 681 ) { 682 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 683 int ports = ohci->num_ports; 684 u32 temp; 685 int retval = 0; 686 687 if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 688 return -ESHUTDOWN; 689 690 switch (typeReq) { 691 case ClearHubFeature: 692 switch (wValue) { 693 case C_HUB_OVER_CURRENT: 694 ohci_writel (ohci, RH_HS_OCIC, 695 &ohci->regs->roothub.status); 696 case C_HUB_LOCAL_POWER: 697 break; 698 default: 699 goto error; 700 } 701 break; 702 case ClearPortFeature: 703 if (!wIndex || wIndex > ports) 704 goto error; 705 wIndex--; 706 707 switch (wValue) { 708 case USB_PORT_FEAT_ENABLE: 709 temp = RH_PS_CCS; 710 break; 711 case USB_PORT_FEAT_C_ENABLE: 712 temp = RH_PS_PESC; 713 break; 714 case USB_PORT_FEAT_SUSPEND: 715 temp = RH_PS_POCI; 716 break; 717 case USB_PORT_FEAT_C_SUSPEND: 718 temp = RH_PS_PSSC; 719 break; 720 case USB_PORT_FEAT_POWER: 721 temp = RH_PS_LSDA; 722 break; 723 case USB_PORT_FEAT_C_CONNECTION: 724 temp = RH_PS_CSC; 725 break; 726 case USB_PORT_FEAT_C_OVER_CURRENT: 727 temp = RH_PS_OCIC; 728 break; 729 case USB_PORT_FEAT_C_RESET: 730 temp = RH_PS_PRSC; 731 break; 732 default: 733 goto error; 734 } 735 ohci_writel (ohci, temp, 736 &ohci->regs->roothub.portstatus [wIndex]); 737 // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]); 738 break; 739 case GetHubDescriptor: 740 ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf); 741 break; 742 case GetHubStatus: 743 temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE); 744 put_unaligned_le32(temp, buf); 745 break; 746 case GetPortStatus: 747 if (!wIndex || wIndex > ports) 748 goto error; 749 wIndex--; 750 temp = roothub_portstatus (ohci, wIndex); 751 put_unaligned_le32(temp, buf); 752 753 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 754 dbg_port(ohci, "GetStatus", wIndex, temp); 755 break; 756 case SetHubFeature: 757 switch (wValue) { 758 case C_HUB_OVER_CURRENT: 759 // FIXME: this can be cleared, yes? 760 case C_HUB_LOCAL_POWER: 761 break; 762 default: 763 goto error; 764 } 765 break; 766 case SetPortFeature: 767 if (!wIndex || wIndex > ports) 768 goto error; 769 wIndex--; 770 switch (wValue) { 771 case USB_PORT_FEAT_SUSPEND: 772 #ifdef CONFIG_USB_OTG 773 if (hcd->self.otg_port == (wIndex + 1) 774 && hcd->self.b_hnp_enable) 775 ohci->start_hnp(ohci); 776 else 777 #endif 778 ohci_writel (ohci, RH_PS_PSS, 779 &ohci->regs->roothub.portstatus [wIndex]); 780 break; 781 case USB_PORT_FEAT_POWER: 782 ohci_writel (ohci, RH_PS_PPS, 783 &ohci->regs->roothub.portstatus [wIndex]); 784 break; 785 case USB_PORT_FEAT_RESET: 786 retval = root_port_reset (ohci, wIndex); 787 break; 788 default: 789 goto error; 790 } 791 break; 792 793 default: 794 error: 795 /* "protocol stall" on error */ 796 retval = -EPIPE; 797 } 798 return retval; 799 } 800 EXPORT_SYMBOL_GPL(ohci_hub_control); 801 802 #endif 803