USB: OHCI: disable RHSC inside interrupt handler
[deliverable/linux.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
d413984a
DB
39/* hcd->hub_irq_enable() */
40static void ohci_rhsc_enable (struct usb_hcd *hcd)
41{
42 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
43
052ac01a
AS
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);
d413984a
DB
49}
50
1da177e4
LT
51#define OHCI_SCHED_ENABLES \
52 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
53
7d12e780
DH
54static void dl_done_list (struct ohci_hcd *);
55static void finish_unlinks (struct ohci_hcd *, u16);
1da177e4 56
b1878440
AS
57#ifdef CONFIG_PM
58static int ohci_restart(struct ohci_hcd *ohci);
59#endif
60
8d1a243b
AS
61static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop)
62__releases(ohci->lock)
63__acquires(ohci->lock)
1da177e4 64{
1da177e4 65 int status = 0;
8de98402 66
1da177e4
LT
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:
8d1a243b
AS
81 if (!ohci->autostop) {
82 ohci_dbg (ohci, "already suspended\n");
83 goto done;
84 }
1da177e4 85 }
8d1a243b
AS
86 ohci_dbg (ohci, "%s root hub\n",
87 autostop ? "auto-stop" : "suspend");
1da177e4
LT
88
89 /* First stop any processing */
8d1a243b 90 if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) {
1da177e4
LT
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");
8d1a243b
AS
100 ohci->autostop = 0;
101 spin_unlock_irq (&ohci->lock);
102 msleep (8);
103 spin_lock_irq (&ohci->lock);
1da177e4 104 }
7d12e780
DH
105 dl_done_list (ohci);
106 finish_unlinks (ohci, ohci_frame_no(ohci));
1da177e4
LT
107
108 /* maybe resume can wake root hub */
8d1a243b
AS
109 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) ||
110 autostop)
1da177e4 111 ohci->hc_control |= OHCI_CTRL_RWE;
1f7e1a3b
AS
112 else {
113 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
1da177e4 114 ohci->hc_control &= ~OHCI_CTRL_RWE;
1f7e1a3b 115 }
1da177e4 116
f197b2c5
DB
117 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
118 * which doesn't imply ports will first be individually suspended.
119 */
1da177e4
LT
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 */
8d1a243b
AS
126 if (!autostop) {
127 ohci->next_statechange = jiffies + msecs_to_jiffies (5);
128 ohci->autostop = 0;
129 }
d413984a 130
1da177e4 131done:
1da177e4
LT
132 return status;
133}
134
135static 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 */
8d1a243b
AS
144static int ohci_rh_resume (struct ohci_hcd *ohci)
145__releases(ohci->lock)
146__acquires(ohci->lock)
1da177e4 147{
8d1a243b 148 struct usb_hcd *hcd = ohci_to_hcd (ohci);
1da177e4
LT
149 u32 temp, enables;
150 int status = -EINPROGRESS;
8d1a243b 151 int autostopped = ohci->autostop;
8de98402 152
8d1a243b 153 ohci->autostop = 0;
1da177e4
LT
154 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
155
156 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
f197b2c5 157 /* this can happen after resuming a swsusp snapshot */
1da177e4
LT
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);
8d1a243b
AS
173 ohci_dbg (ohci, "%s root hub\n",
174 autostopped ? "auto-start" : "resume");
1da177e4
LT
175 break;
176 case OHCI_USB_RESUME:
177 /* HCFS changes sometime after INTR_RD */
583ceada
AS
178 ohci_info(ohci, "%swakeup\n",
179 autostopped ? "auto-" : "");
1da177e4
LT
180 break;
181 case OHCI_USB_OPER:
f197b2c5
DB
182 /* this can happen after resuming a swsusp snapshot */
183 ohci_dbg (ohci, "snapshot resume? reinit\n");
184 status = -EBUSY;
1da177e4
LT
185 break;
186 default: /* RESET, we lost power */
f197b2c5 187 ohci_dbg (ohci, "lost power\n");
1da177e4
LT
188 status = -EBUSY;
189 }
8d1a243b 190#ifdef CONFIG_PM
1da177e4 191 if (status == -EBUSY) {
8d1a243b 192 if (!autostopped) {
8d1a243b
AS
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;
1da177e4 199 }
8d1a243b 200#endif
1da177e4
LT
201 if (status != -EINPROGRESS)
202 return status;
8d1a243b
AS
203 if (autostopped)
204 goto skip_resume;
205 spin_unlock_irq (&ohci->lock);
1da177e4 206
fdd13b36 207 temp = ohci->num_ports;
1da177e4
LT
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 */
f197b2c5 220 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
1da177e4
LT
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
8d1a243b
AS
240 /* the following code is executed with ohci->lock held and
241 * irqs disabled if and only if autostopped is true
242 */
243
244skip_resume:
1da177e4
LT
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);
1da177e4
LT
249
250 /* Then re-enable operations */
251 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
252 (void) ohci_readl (ohci, &ohci->regs->control);
8d1a243b
AS
253 if (!autostopped)
254 msleep (3);
1da177e4 255
6a9062f3
DB
256 temp = ohci->hc_control;
257 temp &= OHCI_CTRL_RWC;
258 temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
1da177e4
LT
259 ohci->hc_control = temp;
260 ohci_writel (ohci, temp, &ohci->regs->control);
261 (void) ohci_readl (ohci, &ohci->regs->control);
262
263 /* TRSMRCY */
8d1a243b
AS
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 */
1da177e4 269
d413984a
DB
270 /* keep it alive for more than ~5x suspend + resume costs */
271 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
1da177e4
LT
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
1da177e4
LT
302 return 0;
303}
304
8d1a243b
AS
305#ifdef CONFIG_PM
306
307static 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
322static 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
8ad7fe16 344#endif /* CONFIG_PM */
1da177e4
LT
345
346/*-------------------------------------------------------------------------*/
347
348/* build "status change" packet (one or two bytes) from HC registers */
349
350static int
351ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
352{
353 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
fdd13b36 354 int i, changed = 0, length = 1;
052ac01a 355 int any_connected = 0;
1da177e4
LT
356 unsigned long flags;
357
358 spin_lock_irqsave (&ohci->lock, flags);
359
fdd13b36
DB
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",
1da177e4
LT
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;
fdd13b36 374 if (ohci->num_ports > 7) {
1da177e4
LT
375 buf [1] = 0;
376 length++;
377 }
378
379 /* look at each port */
fdd13b36 380 for (i = 0; i < ohci->num_ports; i++) {
1da177e4
LT
381 u32 status = roothub_portstatus (ohci, i);
382
8d1a243b
AS
383 /* can't autostop if ports are connected */
384 any_connected |= (status & RH_PS_CCS);
385
1da177e4
LT
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);
1da177e4 393 }
d413984a 394 }
1da177e4 395
8d1a243b
AS
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) {
052ac01a
AS
406 if (ohci_readl(ohci, &ohci->regs->intrenable) &
407 OHCI_INTR_RHSC)
8d1a243b
AS
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;
3da2495c
AS
420 } else if (device_may_wakeup(&hcd->self.root_hub->dev)
421 && time_after_eq(jiffies,
8d1a243b
AS
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 }
d413984a 445
1da177e4
LT
446done:
447 spin_unlock_irqrestore (&ohci->lock, flags);
448
1da177e4
LT
449 return changed ? length : 0;
450}
451
452/*-------------------------------------------------------------------------*/
453
454static void
455ohci_hub_descriptor (
456 struct ohci_hcd *ohci,
457 struct usb_hub_descriptor *desc
458) {
459 u32 rh = roothub_a (ohci);
1da177e4
LT
460 u16 temp;
461
462 desc->bDescriptorType = 0x29;
463 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
464 desc->bHubContrCurrent = 0;
465
fdd13b36
DB
466 desc->bNbrPorts = ohci->num_ports;
467 temp = 1 + (ohci->num_ports / 8);
1da177e4
LT
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);
b2134bcd 483 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
1da177e4 484 desc->bitmap [0] = rh & RH_B_DR;
fdd13b36 485 if (ohci->num_ports > 7) {
1da177e4 486 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
b2134bcd 487 desc->bitmap [2] = 0xff;
1da177e4
LT
488 } else
489 desc->bitmap [1] = 0xff;
490}
491
492/*-------------------------------------------------------------------------*/
493
494#ifdef CONFIG_USB_OTG
495
496static 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
515static 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 */
544static 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
577static 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
8de98402
BH
590 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
591 return -ESHUTDOWN;
592
1da177e4
LT
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;
1da177e4
LT
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);
92164c5d 647 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
1da177e4
LT
648 break;
649 case GetPortStatus:
650 if (!wIndex || wIndex > ports)
651 goto error;
652 wIndex--;
653 temp = roothub_portstatus (ohci, wIndex);
92164c5d 654 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
1da177e4
LT
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:
699error:
700 /* "protocol stall" on error */
701 retval = -EPIPE;
702 }
703 return retval;
704}
705
This page took 0.220558 seconds and 5 git commands to generate.