RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / usb / host / ohci-hub.c
blobf43e6ecacf467f4b8ddb995f84c10bcf5d2ec84c
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under GPL
8 */
10 /*-------------------------------------------------------------------------*/
13 * OHCI Root Hub ... the nonsharable stuff
16 #define dbg_port(hc,label,num,value) \
17 ohci_dbg (hc, \
18 "%s roothub.portstatus [%d] " \
19 "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
20 label, num, temp, \
21 (temp & RH_PS_PRSC) ? " PRSC" : "", \
22 (temp & RH_PS_OCIC) ? " OCIC" : "", \
23 (temp & RH_PS_PSSC) ? " PSSC" : "", \
24 (temp & RH_PS_PESC) ? " PESC" : "", \
25 (temp & RH_PS_CSC) ? " CSC" : "", \
27 (temp & RH_PS_LSDA) ? " LSDA" : "", \
28 (temp & RH_PS_PPS) ? " PPS" : "", \
29 (temp & RH_PS_PRS) ? " PRS" : "", \
30 (temp & RH_PS_POCI) ? " POCI" : "", \
31 (temp & RH_PS_PSS) ? " PSS" : "", \
33 (temp & RH_PS_PES) ? " PES" : "", \
34 (temp & RH_PS_CCS) ? " CCS" : "" \
37 /*-------------------------------------------------------------------------*/
39 /* hcd->hub_irq_enable() */
40 static void ohci_rhsc_enable (struct usb_hcd *hcd)
42 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
44 spin_lock_irq(&ohci->lock);
45 if (!ohci->autostop)
46 del_timer(&hcd->rh_timer); /* Prevent next poll */
47 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable);
48 spin_unlock_irq(&ohci->lock);
51 #define OHCI_SCHED_ENABLES \
52 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
54 static void dl_done_list (struct ohci_hcd *);
55 static void finish_unlinks (struct ohci_hcd *, u16);
57 #ifdef CONFIG_PM
58 static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop)
59 __releases(ohci->lock)
60 __acquires(ohci->lock)
62 int status = 0;
64 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
65 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
66 case OHCI_USB_RESUME:
67 ohci_dbg (ohci, "resume/suspend?\n");
68 ohci->hc_control &= ~OHCI_CTRL_HCFS;
69 ohci->hc_control |= OHCI_USB_RESET;
70 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
71 (void) ohci_readl (ohci, &ohci->regs->control);
72 /* FALL THROUGH */
73 case OHCI_USB_RESET:
74 status = -EBUSY;
75 ohci_dbg (ohci, "needs reinit!\n");
76 goto done;
77 case OHCI_USB_SUSPEND:
78 if (!ohci->autostop) {
79 ohci_dbg (ohci, "already suspended\n");
80 goto done;
83 ohci_dbg (ohci, "%s root hub\n",
84 autostop ? "auto-stop" : "suspend");
86 /* First stop any processing */
87 if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) {
88 ohci->hc_control &= ~OHCI_SCHED_ENABLES;
89 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
90 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
91 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
93 /* sched disables take effect on the next frame,
94 * then the last WDH could take 6+ msec
96 ohci_dbg (ohci, "stopping schedules ...\n");
97 ohci->autostop = 0;
98 spin_unlock_irq (&ohci->lock);
99 msleep (8);
100 spin_lock_irq (&ohci->lock);
102 dl_done_list (ohci);
103 finish_unlinks (ohci, ohci_frame_no(ohci));
105 /* maybe resume can wake root hub */
106 if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) {
107 ohci->hc_control |= OHCI_CTRL_RWE;
108 } else {
109 ohci_writel(ohci, OHCI_INTR_RHSC | OHCI_INTR_RD,
110 &ohci->regs->intrdisable);
111 ohci->hc_control &= ~OHCI_CTRL_RWE;
114 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
115 * which doesn't imply ports will first be individually suspended.
117 ohci->hc_control &= ~OHCI_CTRL_HCFS;
118 ohci->hc_control |= OHCI_USB_SUSPEND;
119 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
120 (void) ohci_readl (ohci, &ohci->regs->control);
122 /* no resumes until devices finish suspending */
123 if (!autostop) {
124 ohci->next_statechange = jiffies + msecs_to_jiffies (5);
125 ohci->autostop = 0;
128 done:
129 return status;
132 static inline struct ed *find_head (struct ed *ed)
134 /* for bulk and control lists */
135 while (ed->ed_prev)
136 ed = ed->ed_prev;
137 return ed;
140 /* caller has locked the root hub */
141 static int ohci_rh_resume (struct ohci_hcd *ohci)
142 __releases(ohci->lock)
143 __acquires(ohci->lock)
145 struct usb_hcd *hcd = ohci_to_hcd (ohci);
146 u32 temp, enables;
147 int status = -EINPROGRESS;
148 int autostopped = ohci->autostop;
150 ohci->autostop = 0;
151 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
153 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
154 /* this can happen after resuming a swsusp snapshot */
155 if (hcd->state == HC_STATE_RESUMING) {
156 ohci_dbg (ohci, "BIOS/SMM active, control %03x\n",
157 ohci->hc_control);
158 status = -EBUSY;
159 /* this happens when pmcore resumes HC then root */
160 } else {
161 ohci_dbg (ohci, "duplicate resume\n");
162 status = 0;
164 } else switch (ohci->hc_control & OHCI_CTRL_HCFS) {
165 case OHCI_USB_SUSPEND:
166 ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES);
167 ohci->hc_control |= OHCI_USB_RESUME;
168 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
169 (void) ohci_readl (ohci, &ohci->regs->control);
170 ohci_dbg (ohci, "%s root hub\n",
171 autostopped ? "auto-start" : "resume");
172 break;
173 case OHCI_USB_RESUME:
174 /* HCFS changes sometime after INTR_RD */
175 ohci_dbg(ohci, "%swakeup root hub\n",
176 autostopped ? "auto-" : "");
177 break;
178 case OHCI_USB_OPER:
179 /* this can happen after resuming a swsusp snapshot */
180 ohci_dbg (ohci, "snapshot resume? reinit\n");
181 status = -EBUSY;
182 break;
183 default: /* RESET, we lost power */
184 ohci_dbg (ohci, "lost power\n");
185 status = -EBUSY;
187 if (status == -EBUSY) {
188 if (!autostopped) {
189 spin_unlock_irq (&ohci->lock);
190 (void) ohci_init (ohci);
191 status = ohci_restart (ohci);
193 usb_root_hub_lost_power(hcd->self.root_hub);
195 spin_lock_irq (&ohci->lock);
197 return status;
199 if (status != -EINPROGRESS)
200 return status;
201 if (autostopped)
202 goto skip_resume;
203 spin_unlock_irq (&ohci->lock);
205 /* Some controllers (lucent erratum) need extra-long delays */
206 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
208 temp = ohci_readl (ohci, &ohci->regs->control);
209 temp &= OHCI_CTRL_HCFS;
210 if (temp != OHCI_USB_RESUME) {
211 ohci_err (ohci, "controller won't resume\n");
212 spin_lock_irq(&ohci->lock);
213 return -EBUSY;
216 /* disable old schedule state, reinit from scratch */
217 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
218 ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
219 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
220 ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
221 ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent);
222 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
224 /* Sometimes PCI D3 suspend trashes frame timings ... */
225 periodic_reinit (ohci);
227 /* the following code is executed with ohci->lock held and
228 * irqs disabled if and only if autostopped is true
231 skip_resume:
232 /* interrupts might have been disabled */
233 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
234 if (ohci->ed_rm_list)
235 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
237 /* Then re-enable operations */
238 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
239 (void) ohci_readl (ohci, &ohci->regs->control);
240 if (!autostopped)
241 msleep (3);
243 temp = ohci->hc_control;
244 temp &= OHCI_CTRL_RWC;
245 temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
246 ohci->hc_control = temp;
247 ohci_writel (ohci, temp, &ohci->regs->control);
248 (void) ohci_readl (ohci, &ohci->regs->control);
250 /* TRSMRCY */
251 if (!autostopped) {
252 msleep (10);
253 spin_lock_irq (&ohci->lock);
255 /* now ohci->lock is always held and irqs are always disabled */
257 /* keep it alive for more than ~5x suspend + resume costs */
258 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
260 /* maybe turn schedules back on */
261 enables = 0;
262 temp = 0;
263 if (!ohci->ed_rm_list) {
264 if (ohci->ed_controltail) {
265 ohci_writel (ohci,
266 find_head (ohci->ed_controltail)->dma,
267 &ohci->regs->ed_controlhead);
268 enables |= OHCI_CTRL_CLE;
269 temp |= OHCI_CLF;
271 if (ohci->ed_bulktail) {
272 ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma,
273 &ohci->regs->ed_bulkhead);
274 enables |= OHCI_CTRL_BLE;
275 temp |= OHCI_BLF;
278 if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs)
279 enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE;
280 if (enables) {
281 ohci_dbg (ohci, "restarting schedules ... %08x\n", enables);
282 ohci->hc_control |= enables;
283 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
284 if (temp)
285 ohci_writel (ohci, temp, &ohci->regs->cmdstatus);
286 (void) ohci_readl (ohci, &ohci->regs->control);
289 return 0;
292 static int ohci_bus_suspend (struct usb_hcd *hcd)
294 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
295 int rc;
297 spin_lock_irq (&ohci->lock);
299 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
300 rc = -ESHUTDOWN;
301 else
302 rc = ohci_rh_suspend (ohci, 0);
303 spin_unlock_irq (&ohci->lock);
304 return rc;
307 static int ohci_bus_resume (struct usb_hcd *hcd)
309 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
310 int rc;
312 if (time_before (jiffies, ohci->next_statechange))
313 msleep(5);
315 spin_lock_irq (&ohci->lock);
317 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
318 rc = -ESHUTDOWN;
319 else
320 rc = ohci_rh_resume (ohci);
321 spin_unlock_irq (&ohci->lock);
323 /* poll until we know a device is connected or we autostop */
324 if (rc == 0)
325 usb_hcd_poll_rh_status(hcd);
326 return rc;
329 /* Carry out the final steps of resuming the controller device */
330 static void ohci_finish_controller_resume(struct usb_hcd *hcd)
332 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
333 int port;
334 bool need_reinit = false;
336 /* See if the controller is already running or has been reset */
337 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
338 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
339 need_reinit = true;
340 } else {
341 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
342 case OHCI_USB_OPER:
343 case OHCI_USB_RESET:
344 need_reinit = true;
348 /* If needed, reinitialize and suspend the root hub */
349 if (need_reinit) {
350 spin_lock_irq(&ohci->lock);
351 hcd->state = HC_STATE_RESUMING;
352 ohci_rh_resume(ohci);
353 hcd->state = HC_STATE_QUIESCING;
354 ohci_rh_suspend(ohci, 0);
355 hcd->state = HC_STATE_SUSPENDED;
356 spin_unlock_irq(&ohci->lock);
359 /* Normally just turn on port power and enable interrupts */
360 else {
361 ohci_dbg(ohci, "powerup ports\n");
362 for (port = 0; port < ohci->num_ports; port++)
363 ohci_writel(ohci, RH_PS_PPS,
364 &ohci->regs->roothub.portstatus[port]);
366 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
367 ohci_readl(ohci, &ohci->regs->intrenable);
368 msleep(20);
372 /* Carry out polling-, autostop-, and autoresume-related state changes */
373 static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
374 int any_connected)
376 int poll_rh = 1;
378 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
380 case OHCI_USB_OPER:
381 /* keep on polling until we know a device is connected
382 * and RHSC is enabled */
383 if (!ohci->autostop) {
384 if (any_connected ||
385 !device_may_wakeup(&ohci_to_hcd(ohci)
386 ->self.root_hub->dev)) {
387 if (ohci_readl(ohci, &ohci->regs->intrenable) &
388 OHCI_INTR_RHSC)
389 poll_rh = 0;
390 } else {
391 ohci->autostop = 1;
392 ohci->next_statechange = jiffies + HZ;
395 /* if no devices have been attached for one second, autostop */
396 } else {
397 if (changed || any_connected) {
398 ohci->autostop = 0;
399 ohci->next_statechange = jiffies +
400 STATECHANGE_DELAY;
401 } else if (time_after_eq(jiffies,
402 ohci->next_statechange)
403 && !ohci->ed_rm_list
404 && !(ohci->hc_control &
405 OHCI_SCHED_ENABLES)) {
406 ohci_rh_suspend(ohci, 1);
409 break;
411 /* if there is a port change, autostart or ask to be resumed */
412 case OHCI_USB_SUSPEND:
413 case OHCI_USB_RESUME:
414 if (changed) {
415 if (ohci->autostop)
416 ohci_rh_resume(ohci);
417 else
418 usb_hcd_resume_root_hub(ohci_to_hcd(ohci));
419 } else {
420 /* everything is idle, no need for polling */
421 poll_rh = 0;
423 break;
425 return poll_rh;
428 #else /* CONFIG_PM */
430 static inline int ohci_rh_resume(struct ohci_hcd *ohci)
432 return 0;
435 /* Carry out polling-related state changes.
436 * autostop isn't used when CONFIG_PM is turned off.
438 static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
439 int any_connected)
441 int poll_rh = 1;
443 /* keep on polling until RHSC is enabled */
444 if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC)
445 poll_rh = 0;
446 return poll_rh;
449 #endif /* CONFIG_PM */
451 /*-------------------------------------------------------------------------*/
453 /* build "status change" packet (one or two bytes) from HC registers */
455 static int
456 ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
458 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
459 int i, changed = 0, length = 1;
460 int any_connected = 0;
461 unsigned long flags;
463 spin_lock_irqsave (&ohci->lock, flags);
464 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
465 goto done;
467 /* undocumented erratum seen on at least rev D */
468 if ((ohci->flags & OHCI_QUIRK_AMD756)
469 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
470 ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n",
471 ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
472 /* retry later; "should not happen" */
473 goto done;
476 /* init status */
477 if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
478 buf [0] = changed = 1;
479 else
480 buf [0] = 0;
481 if (ohci->num_ports > 7) {
482 buf [1] = 0;
483 length++;
486 /* Some broken controllers never turn off RHCS in the interrupt
487 * status register. For their sake we won't re-enable RHSC
488 * interrupts if the flag is already set.
490 if (ohci_readl(ohci, &ohci->regs->intrstatus) & OHCI_INTR_RHSC)
491 changed = 1;
493 /* look at each port */
494 for (i = 0; i < ohci->num_ports; i++) {
495 u32 status = roothub_portstatus (ohci, i);
497 /* can't autostop if ports are connected */
498 any_connected |= (status & RH_PS_CCS);
500 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
501 | RH_PS_OCIC | RH_PS_PRSC)) {
502 changed = 1;
503 if (i < 7)
504 buf [0] |= 1 << (i + 1);
505 else
506 buf [1] |= 1 << (i - 7);
510 hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed,
511 any_connected);
513 done:
514 spin_unlock_irqrestore (&ohci->lock, flags);
516 return changed ? length : 0;
519 /*-------------------------------------------------------------------------*/
521 static void
522 ohci_hub_descriptor (
523 struct ohci_hcd *ohci,
524 struct usb_hub_descriptor *desc
526 u32 rh = roothub_a (ohci);
527 u16 temp;
529 desc->bDescriptorType = 0x29;
530 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
531 desc->bHubContrCurrent = 0;
533 desc->bNbrPorts = ohci->num_ports;
534 temp = 1 + (ohci->num_ports / 8);
535 desc->bDescLength = 7 + 2 * temp;
537 temp = 0;
538 if (rh & RH_A_NPS) /* no power switching? */
539 temp |= 0x0002;
540 if (rh & RH_A_PSM) /* per-port power switching? */
541 temp |= 0x0001;
542 if (rh & RH_A_NOCP) /* no overcurrent reporting? */
543 temp |= 0x0010;
544 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */
545 temp |= 0x0008;
546 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
548 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
549 rh = roothub_b (ohci);
550 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
551 desc->bitmap [0] = rh & RH_B_DR;
552 if (ohci->num_ports > 7) {
553 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
554 desc->bitmap [2] = 0xff;
555 } else
556 desc->bitmap [1] = 0xff;
559 /*-------------------------------------------------------------------------*/
561 #ifdef CONFIG_USB_OTG
563 static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
565 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
566 u32 status;
568 if (!port)
569 return -EINVAL;
570 port--;
572 /* start port reset before HNP protocol times out */
573 status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]);
574 if (!(status & RH_PS_CCS))
575 return -ENODEV;
577 /* khubd will finish the reset later */
578 ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]);
579 return 0;
582 static void start_hnp(struct ohci_hcd *ohci);
584 #else
586 #define ohci_start_port_reset NULL
588 #endif
590 /*-------------------------------------------------------------------------*/
593 /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
594 * not necessarily continuous ... to guard against resume signaling.
595 * The short timeout is safe for non-root hubs, and is backward-compatible
596 * with earlier Linux hosts.
598 #ifdef CONFIG_USB_SUSPEND
599 #define PORT_RESET_MSEC 50
600 #else
601 #define PORT_RESET_MSEC 10
602 #endif
604 /* this timer value might be vendor-specific ... */
605 #define PORT_RESET_HW_MSEC 10
607 /* wrap-aware logic morphed from <linux/jiffies.h> */
608 #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
610 /* called from some task, normally khubd */
611 static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
613 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
614 u32 temp = 0;
615 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
616 u16 reset_done = now + PORT_RESET_MSEC;
617 int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC);
619 /* build a "continuous enough" reset signal, with up to
620 * 3msec gap between pulses. scheduler HZ==100 must work;
621 * this might need to be deadline-scheduled.
623 do {
624 int limit_2;
626 /* spin until any current reset finishes */
627 limit_2 = PORT_RESET_HW_MSEC * 2;
628 while (--limit_2 >= 0) {
629 temp = ohci_readl (ohci, portstat);
630 /* handle e.g. CardBus eject */
631 if (temp == ~(u32)0)
632 return -ESHUTDOWN;
633 if (!(temp & RH_PS_PRS))
634 break;
635 udelay (500);
638 /* timeout (a hardware error) has been observed when
639 * EHCI sets CF while this driver is resetting a port;
640 * presumably other disconnect paths might do it too.
642 if (limit_2 < 0) {
643 ohci_dbg(ohci,
644 "port[%d] reset timeout, stat %08x\n",
645 port, temp);
646 break;
649 if (!(temp & RH_PS_CCS))
650 break;
651 if (temp & RH_PS_PRSC)
652 ohci_writel (ohci, RH_PS_PRSC, portstat);
654 /* start the next reset, sleep till it's probably done */
655 ohci_writel (ohci, RH_PS_PRS, portstat);
656 msleep(PORT_RESET_HW_MSEC);
657 now = ohci_readl(ohci, &ohci->regs->fmnumber);
658 } while (tick_before(now, reset_done) && --limit_1 >= 0);
660 /* caller synchronizes using PRSC ... and handles PRS
661 * still being set when this returns.
664 return 0;
667 static int ohci_hub_control (
668 struct usb_hcd *hcd,
669 u16 typeReq,
670 u16 wValue,
671 u16 wIndex,
672 char *buf,
673 u16 wLength
675 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
676 int ports = ohci->num_ports;
677 u32 temp;
678 int retval = 0;
680 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
681 return -ESHUTDOWN;
683 switch (typeReq) {
684 case ClearHubFeature:
685 switch (wValue) {
686 case C_HUB_OVER_CURRENT:
687 ohci_writel (ohci, RH_HS_OCIC,
688 &ohci->regs->roothub.status);
689 case C_HUB_LOCAL_POWER:
690 break;
691 default:
692 goto error;
694 break;
695 case ClearPortFeature:
696 if (!wIndex || wIndex > ports)
697 goto error;
698 wIndex--;
700 switch (wValue) {
701 case USB_PORT_FEAT_ENABLE:
702 temp = RH_PS_CCS;
703 break;
704 case USB_PORT_FEAT_C_ENABLE:
705 temp = RH_PS_PESC;
706 break;
707 case USB_PORT_FEAT_SUSPEND:
708 temp = RH_PS_POCI;
709 break;
710 case USB_PORT_FEAT_C_SUSPEND:
711 temp = RH_PS_PSSC;
712 break;
713 case USB_PORT_FEAT_POWER:
714 temp = RH_PS_LSDA;
715 break;
716 case USB_PORT_FEAT_C_CONNECTION:
717 temp = RH_PS_CSC;
718 break;
719 case USB_PORT_FEAT_C_OVER_CURRENT:
720 temp = RH_PS_OCIC;
721 break;
722 case USB_PORT_FEAT_C_RESET:
723 temp = RH_PS_PRSC;
724 break;
725 default:
726 goto error;
728 ohci_writel (ohci, temp,
729 &ohci->regs->roothub.portstatus [wIndex]);
730 // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
731 break;
732 case GetHubDescriptor:
733 ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
734 break;
735 case GetHubStatus:
736 temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
737 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
738 break;
739 case GetPortStatus:
740 if (!wIndex || wIndex > ports)
741 goto error;
742 wIndex--;
743 temp = roothub_portstatus (ohci, wIndex);
744 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
746 #ifndef OHCI_VERBOSE_DEBUG
747 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
748 #endif
749 dbg_port (ohci, "GetStatus", wIndex, temp);
750 break;
751 case SetHubFeature:
752 switch (wValue) {
753 case C_HUB_OVER_CURRENT:
754 // FIXME: this can be cleared, yes?
755 case C_HUB_LOCAL_POWER:
756 break;
757 default:
758 goto error;
760 break;
761 case SetPortFeature:
762 if (!wIndex || wIndex > ports)
763 goto error;
764 wIndex--;
765 switch (wValue) {
766 case USB_PORT_FEAT_SUSPEND:
767 #ifdef CONFIG_USB_OTG
768 if (hcd->self.otg_port == (wIndex + 1)
769 && hcd->self.b_hnp_enable)
770 start_hnp(ohci);
771 else
772 #endif
773 ohci_writel (ohci, RH_PS_PSS,
774 &ohci->regs->roothub.portstatus [wIndex]);
775 break;
776 case USB_PORT_FEAT_POWER:
777 ohci_writel (ohci, RH_PS_PPS,
778 &ohci->regs->roothub.portstatus [wIndex]);
779 break;
780 case USB_PORT_FEAT_RESET:
781 retval = root_port_reset (ohci, wIndex);
782 break;
783 default:
784 goto error;
786 break;
788 default:
789 error:
790 /* "protocol stall" on error */
791 retval = -EPIPE;
793 return retval;