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