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