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