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