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