Pull video into release branch
[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_rh_suspend (struct ohci_hcd *ohci, int autostop)
59 __releases(ohci->lock)
60 __acquires(ohci->lock)
61 {
62         int                     status = 0;
63
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;
81                 }
82         }
83         ohci_dbg (ohci, "%s root hub\n",
84                         autostop ? "auto-stop" : "suspend");
85
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);
92
93                 /* sched disables take effect on the next frame,
94                  * then the last WDH could take 6+ msec
95                  */
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);
101         }
102         dl_done_list (ohci);
103         finish_unlinks (ohci, ohci_frame_no(ohci));
104
105         /* maybe resume can wake root hub */
106         if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) ||
107                         autostop)
108                 ohci->hc_control |= OHCI_CTRL_RWE;
109         else {
110                 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
111                 ohci->hc_control &= ~OHCI_CTRL_RWE;
112         }
113
114         /* Suspend hub ... this is the "global (to this bus) suspend" mode,
115          * which doesn't imply ports will first be individually suspended.
116          */
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);
121
122         /* no resumes until devices finish suspending */
123         if (!autostop) {
124                 ohci->next_statechange = jiffies + msecs_to_jiffies (5);
125                 ohci->autostop = 0;
126         }
127
128 done:
129         return status;
130 }
131
132 static inline struct ed *find_head (struct ed *ed)
133 {
134         /* for bulk and control lists */
135         while (ed->ed_prev)
136                 ed = ed->ed_prev;
137         return ed;
138 }
139
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)
144 {
145         struct usb_hcd          *hcd = ohci_to_hcd (ohci);
146         u32                     temp, enables;
147         int                     status = -EINPROGRESS;
148         int                     autostopped = ohci->autostop;
149
150         ohci->autostop = 0;
151         ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
152
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;
163                 }
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;
186         }
187         if (status == -EBUSY) {
188                 if (!autostopped) {
189                         spin_unlock_irq (&ohci->lock);
190                         (void) ohci_init (ohci);
191                         status = ohci_restart (ohci);
192
193                         usb_root_hub_lost_power(hcd->self.root_hub);
194
195                         spin_lock_irq (&ohci->lock);
196                 }
197                 return status;
198         }
199         if (status != -EINPROGRESS)
200                 return status;
201         if (autostopped)
202                 goto skip_resume;
203         spin_unlock_irq (&ohci->lock);
204
205         /* Some controllers (lucent erratum) need extra-long delays */
206         msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
207
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;
214         }
215
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);
223
224         /* Sometimes PCI D3 suspend trashes frame timings ... */
225         periodic_reinit (ohci);
226
227         /* the following code is executed with ohci->lock held and
228          * irqs disabled if and only if autostopped is true
229          */
230
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);
236
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);
242
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);
249
250         /* TRSMRCY */
251         if (!autostopped) {
252                 msleep (10);
253                 spin_lock_irq (&ohci->lock);
254         }
255         /* now ohci->lock is always held and irqs are always disabled */
256
257         /* keep it alive for more than ~5x suspend + resume costs */
258         ohci->next_statechange = jiffies + STATECHANGE_DELAY;
259
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;
270                 }
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;
276                 }
277         }
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);
287         }
288
289         return 0;
290 }
291
292 static int ohci_bus_suspend (struct usb_hcd *hcd)
293 {
294         struct ohci_hcd         *ohci = hcd_to_ohci (hcd);
295         int                     rc;
296
297         spin_lock_irq (&ohci->lock);
298
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;
305 }
306
307 static int ohci_bus_resume (struct usb_hcd *hcd)
308 {
309         struct ohci_hcd         *ohci = hcd_to_ohci (hcd);
310         int                     rc;
311
312         if (time_before (jiffies, ohci->next_statechange))
313                 msleep(5);
314
315         spin_lock_irq (&ohci->lock);
316
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);
322
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;
327 }
328
329 /* Carry out polling-, autostop-, and autoresume-related state changes */
330 static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
331                 int any_connected)
332 {
333         int     poll_rh = 1;
334
335         switch (ohci->hc_control & OHCI_CTRL_HCFS) {
336
337         case OHCI_USB_OPER:
338                 /* keep on polling until we know a device is connected
339                  * and RHSC is enabled */
340                 if (!ohci->autostop) {
341                         if (any_connected ||
342                                         !device_may_wakeup(&ohci_to_hcd(ohci)
343                                                 ->self.root_hub->dev)) {
344                                 if (ohci_readl(ohci, &ohci->regs->intrenable) &
345                                                 OHCI_INTR_RHSC)
346                                         poll_rh = 0;
347                         } else {
348                                 ohci->autostop = 1;
349                                 ohci->next_statechange = jiffies + HZ;
350                         }
351
352                 /* if no devices have been attached for one second, autostop */
353                 } else {
354                         if (changed || any_connected) {
355                                 ohci->autostop = 0;
356                                 ohci->next_statechange = jiffies +
357                                                 STATECHANGE_DELAY;
358                         } else if (time_after_eq(jiffies,
359                                                 ohci->next_statechange)
360                                         && !ohci->ed_rm_list
361                                         && !(ohci->hc_control &
362                                                 OHCI_SCHED_ENABLES)) {
363                                 ohci_rh_suspend(ohci, 1);
364                         }
365                 }
366                 break;
367
368         /* if there is a port change, autostart or ask to be resumed */
369         case OHCI_USB_SUSPEND:
370         case OHCI_USB_RESUME:
371                 if (changed) {
372                         if (ohci->autostop)
373                                 ohci_rh_resume(ohci);
374                         else
375                                 usb_hcd_resume_root_hub(ohci_to_hcd(ohci));
376                 } else {
377                         /* everything is idle, no need for polling */
378                         poll_rh = 0;
379                 }
380                 break;
381         }
382         return poll_rh;
383 }
384
385 #else   /* CONFIG_PM */
386
387 static inline int ohci_rh_resume(struct ohci_hcd *ohci)
388 {
389         return 0;
390 }
391
392 /* Carry out polling-related state changes.
393  * autostop isn't used when CONFIG_PM is turned off.
394  */
395 static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
396                 int any_connected)
397 {
398         int     poll_rh = 1;
399
400         /* keep on polling until RHSC is enabled */
401         if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC)
402                 poll_rh = 0;
403         return poll_rh;
404 }
405
406 #endif  /* CONFIG_PM */
407
408 /*-------------------------------------------------------------------------*/
409
410 /* build "status change" packet (one or two bytes) from HC registers */
411
412 static int
413 ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
414 {
415         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
416         int             i, changed = 0, length = 1;
417         int             any_connected = 0;
418         unsigned long   flags;
419
420         spin_lock_irqsave (&ohci->lock, flags);
421         if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
422                 goto done;
423
424         /* undocumented erratum seen on at least rev D */
425         if ((ohci->flags & OHCI_QUIRK_AMD756)
426                         && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
427                 ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n",
428                           ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
429                 /* retry later; "should not happen" */
430                 goto done;
431         }
432
433         /* init status */
434         if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
435                 buf [0] = changed = 1;
436         else
437                 buf [0] = 0;
438         if (ohci->num_ports > 7) {
439                 buf [1] = 0;
440                 length++;
441         }
442
443         /* look at each port */
444         for (i = 0; i < ohci->num_ports; i++) {
445                 u32     status = roothub_portstatus (ohci, i);
446
447                 /* can't autostop if ports are connected */
448                 any_connected |= (status & RH_PS_CCS);
449
450                 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
451                                 | RH_PS_OCIC | RH_PS_PRSC)) {
452                         changed = 1;
453                         if (i < 7)
454                             buf [0] |= 1 << (i + 1);
455                         else
456                             buf [1] |= 1 << (i - 7);
457                 }
458         }
459
460         hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed,
461                         any_connected);
462
463 done:
464         spin_unlock_irqrestore (&ohci->lock, flags);
465
466         return changed ? length : 0;
467 }
468
469 /*-------------------------------------------------------------------------*/
470
471 static void
472 ohci_hub_descriptor (
473         struct ohci_hcd                 *ohci,
474         struct usb_hub_descriptor       *desc
475 ) {
476         u32             rh = roothub_a (ohci);
477         u16             temp;
478
479         desc->bDescriptorType = 0x29;
480         desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
481         desc->bHubContrCurrent = 0;
482
483         desc->bNbrPorts = ohci->num_ports;
484         temp = 1 + (ohci->num_ports / 8);
485         desc->bDescLength = 7 + 2 * temp;
486
487         temp = 0;
488         if (rh & RH_A_NPS)              /* no power switching? */
489             temp |= 0x0002;
490         if (rh & RH_A_PSM)              /* per-port power switching? */
491             temp |= 0x0001;
492         if (rh & RH_A_NOCP)             /* no overcurrent reporting? */
493             temp |= 0x0010;
494         else if (rh & RH_A_OCPM)        /* per-port overcurrent reporting? */
495             temp |= 0x0008;
496         desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
497
498         /* two bitmaps:  ports removable, and usb 1.0 legacy PortPwrCtrlMask */
499         rh = roothub_b (ohci);
500         memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
501         desc->bitmap [0] = rh & RH_B_DR;
502         if (ohci->num_ports > 7) {
503                 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
504                 desc->bitmap [2] = 0xff;
505         } else
506                 desc->bitmap [1] = 0xff;
507 }
508
509 /*-------------------------------------------------------------------------*/
510
511 #ifdef  CONFIG_USB_OTG
512
513 static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
514 {
515         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
516         u32                     status;
517
518         if (!port)
519                 return -EINVAL;
520         port--;
521
522         /* start port reset before HNP protocol times out */
523         status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]);
524         if (!(status & RH_PS_CCS))
525                 return -ENODEV;
526
527         /* khubd will finish the reset later */
528         ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]);
529         return 0;
530 }
531
532 static void start_hnp(struct ohci_hcd *ohci);
533
534 #else
535
536 #define ohci_start_port_reset           NULL
537
538 #endif
539
540 /*-------------------------------------------------------------------------*/
541
542
543 /* See usb 7.1.7.5:  root hubs must issue at least 50 msec reset signaling,
544  * not necessarily continuous ... to guard against resume signaling.
545  * The short timeout is safe for non-root hubs, and is backward-compatible
546  * with earlier Linux hosts.
547  */
548 #ifdef  CONFIG_USB_SUSPEND
549 #define PORT_RESET_MSEC         50
550 #else
551 #define PORT_RESET_MSEC         10
552 #endif
553
554 /* this timer value might be vendor-specific ... */
555 #define PORT_RESET_HW_MSEC      10
556
557 /* wrap-aware logic morphed from <linux/jiffies.h> */
558 #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
559
560 /* called from some task, normally khubd */
561 static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
562 {
563         __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
564         u32     temp;
565         u16     now = ohci_readl(ohci, &ohci->regs->fmnumber);
566         u16     reset_done = now + PORT_RESET_MSEC;
567
568         /* build a "continuous enough" reset signal, with up to
569          * 3msec gap between pulses.  scheduler HZ==100 must work;
570          * this might need to be deadline-scheduled.
571          */
572         do {
573                 /* spin until any current reset finishes */
574                 for (;;) {
575                         temp = ohci_readl (ohci, portstat);
576                         /* handle e.g. CardBus eject */
577                         if (temp == ~(u32)0)
578                                 return -ESHUTDOWN;
579                         if (!(temp & RH_PS_PRS))
580                                 break;
581                         udelay (500);
582                 }
583
584                 if (!(temp & RH_PS_CCS))
585                         break;
586                 if (temp & RH_PS_PRSC)
587                         ohci_writel (ohci, RH_PS_PRSC, portstat);
588
589                 /* start the next reset, sleep till it's probably done */
590                 ohci_writel (ohci, RH_PS_PRS, portstat);
591                 msleep(PORT_RESET_HW_MSEC);
592                 now = ohci_readl(ohci, &ohci->regs->fmnumber);
593         } while (tick_before(now, reset_done));
594         /* caller synchronizes using PRSC */
595
596         return 0;
597 }
598
599 static int ohci_hub_control (
600         struct usb_hcd  *hcd,
601         u16             typeReq,
602         u16             wValue,
603         u16             wIndex,
604         char            *buf,
605         u16             wLength
606 ) {
607         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
608         int             ports = hcd_to_bus (hcd)->root_hub->maxchild;
609         u32             temp;
610         int             retval = 0;
611
612         if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
613                 return -ESHUTDOWN;
614
615         switch (typeReq) {
616         case ClearHubFeature:
617                 switch (wValue) {
618                 case C_HUB_OVER_CURRENT:
619                         ohci_writel (ohci, RH_HS_OCIC,
620                                         &ohci->regs->roothub.status);
621                 case C_HUB_LOCAL_POWER:
622                         break;
623                 default:
624                         goto error;
625                 }
626                 break;
627         case ClearPortFeature:
628                 if (!wIndex || wIndex > ports)
629                         goto error;
630                 wIndex--;
631
632                 switch (wValue) {
633                 case USB_PORT_FEAT_ENABLE:
634                         temp = RH_PS_CCS;
635                         break;
636                 case USB_PORT_FEAT_C_ENABLE:
637                         temp = RH_PS_PESC;
638                         break;
639                 case USB_PORT_FEAT_SUSPEND:
640                         temp = RH_PS_POCI;
641                         break;
642                 case USB_PORT_FEAT_C_SUSPEND:
643                         temp = RH_PS_PSSC;
644                         break;
645                 case USB_PORT_FEAT_POWER:
646                         temp = RH_PS_LSDA;
647                         break;
648                 case USB_PORT_FEAT_C_CONNECTION:
649                         temp = RH_PS_CSC;
650                         break;
651                 case USB_PORT_FEAT_C_OVER_CURRENT:
652                         temp = RH_PS_OCIC;
653                         break;
654                 case USB_PORT_FEAT_C_RESET:
655                         temp = RH_PS_PRSC;
656                         break;
657                 default:
658                         goto error;
659                 }
660                 ohci_writel (ohci, temp,
661                                 &ohci->regs->roothub.portstatus [wIndex]);
662                 // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
663                 break;
664         case GetHubDescriptor:
665                 ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
666                 break;
667         case GetHubStatus:
668                 temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
669                 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
670                 break;
671         case GetPortStatus:
672                 if (!wIndex || wIndex > ports)
673                         goto error;
674                 wIndex--;
675                 temp = roothub_portstatus (ohci, wIndex);
676                 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
677
678 #ifndef OHCI_VERBOSE_DEBUG
679         if (*(u16*)(buf+2))     /* only if wPortChange is interesting */
680 #endif
681                 dbg_port (ohci, "GetStatus", wIndex, temp);
682                 break;
683         case SetHubFeature:
684                 switch (wValue) {
685                 case C_HUB_OVER_CURRENT:
686                         // FIXME:  this can be cleared, yes?
687                 case C_HUB_LOCAL_POWER:
688                         break;
689                 default:
690                         goto error;
691                 }
692                 break;
693         case SetPortFeature:
694                 if (!wIndex || wIndex > ports)
695                         goto error;
696                 wIndex--;
697                 switch (wValue) {
698                 case USB_PORT_FEAT_SUSPEND:
699 #ifdef  CONFIG_USB_OTG
700                         if (hcd->self.otg_port == (wIndex + 1)
701                                         && hcd->self.b_hnp_enable)
702                                 start_hnp(ohci);
703                         else
704 #endif
705                         ohci_writel (ohci, RH_PS_PSS,
706                                 &ohci->regs->roothub.portstatus [wIndex]);
707                         break;
708                 case USB_PORT_FEAT_POWER:
709                         ohci_writel (ohci, RH_PS_PPS,
710                                 &ohci->regs->roothub.portstatus [wIndex]);
711                         break;
712                 case USB_PORT_FEAT_RESET:
713                         retval = root_port_reset (ohci, wIndex);
714                         break;
715                 default:
716                         goto error;
717                 }
718                 break;
719
720         default:
721 error:
722                 /* "protocol stall" on error */
723                 retval = -EPIPE;
724         }
725         return retval;
726 }
727