]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/usb/host/ohci-hub.c
usb: usbmixer free kill urb cleanup
[mirror_ubuntu-jammy-kernel.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
1da177e4 207 /* Some controllers (lucent erratum) need extra-long delays */
f197b2c5 208 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
1da177e4
LT
209
210 temp = ohci_readl (ohci, &ohci->regs->control);
211 temp &= OHCI_CTRL_HCFS;
212 if (temp != OHCI_USB_RESUME) {
213 ohci_err (ohci, "controller won't resume\n");
565402ba 214 spin_lock_irq(&ohci->lock);
1da177e4
LT
215 return -EBUSY;
216 }
217
218 /* disable old schedule state, reinit from scratch */
219 ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
220 ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
221 ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
222 ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
223 ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent);
224 ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
225
226 /* Sometimes PCI D3 suspend trashes frame timings ... */
227 periodic_reinit (ohci);
228
8d1a243b
AS
229 /* the following code is executed with ohci->lock held and
230 * irqs disabled if and only if autostopped is true
231 */
232
233skip_resume:
1da177e4
LT
234 /* interrupts might have been disabled */
235 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
236 if (ohci->ed_rm_list)
237 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
1da177e4
LT
238
239 /* Then re-enable operations */
240 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
241 (void) ohci_readl (ohci, &ohci->regs->control);
8d1a243b
AS
242 if (!autostopped)
243 msleep (3);
1da177e4 244
6a9062f3
DB
245 temp = ohci->hc_control;
246 temp &= OHCI_CTRL_RWC;
247 temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
1da177e4
LT
248 ohci->hc_control = temp;
249 ohci_writel (ohci, temp, &ohci->regs->control);
250 (void) ohci_readl (ohci, &ohci->regs->control);
251
252 /* TRSMRCY */
8d1a243b
AS
253 if (!autostopped) {
254 msleep (10);
255 spin_lock_irq (&ohci->lock);
256 }
257 /* now ohci->lock is always held and irqs are always disabled */
1da177e4 258
d413984a
DB
259 /* keep it alive for more than ~5x suspend + resume costs */
260 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
1da177e4
LT
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
8d1a243b
AS
294#ifdef CONFIG_PM
295
296static int ohci_bus_suspend (struct usb_hcd *hcd)
297{
298 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
299 int rc;
300
301 spin_lock_irq (&ohci->lock);
302
303 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
304 rc = -ESHUTDOWN;
305 else
306 rc = ohci_rh_suspend (ohci, 0);
307 spin_unlock_irq (&ohci->lock);
308 return rc;
309}
310
311static int ohci_bus_resume (struct usb_hcd *hcd)
312{
313 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
314 int rc;
315
316 if (time_before (jiffies, ohci->next_statechange))
317 msleep(5);
318
319 spin_lock_irq (&ohci->lock);
320
321 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
322 rc = -ESHUTDOWN;
323 else
324 rc = ohci_rh_resume (ohci);
325 spin_unlock_irq (&ohci->lock);
326
327 /* poll until we know a device is connected or we autostop */
328 if (rc == 0)
329 usb_hcd_poll_rh_status(hcd);
330 return rc;
331}
332
8ad7fe16 333#endif /* CONFIG_PM */
1da177e4
LT
334
335/*-------------------------------------------------------------------------*/
336
337/* build "status change" packet (one or two bytes) from HC registers */
338
339static int
340ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
341{
342 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
fdd13b36 343 int i, changed = 0, length = 1;
052ac01a 344 int any_connected = 0;
1da177e4
LT
345 unsigned long flags;
346
347 spin_lock_irqsave (&ohci->lock, flags);
348
fdd13b36
DB
349 /* undocumented erratum seen on at least rev D */
350 if ((ohci->flags & OHCI_QUIRK_AMD756)
351 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
352 ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n",
1da177e4
LT
353 ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
354 /* retry later; "should not happen" */
355 goto done;
356 }
357
358 /* init status */
359 if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
360 buf [0] = changed = 1;
361 else
362 buf [0] = 0;
fdd13b36 363 if (ohci->num_ports > 7) {
1da177e4
LT
364 buf [1] = 0;
365 length++;
366 }
367
368 /* look at each port */
fdd13b36 369 for (i = 0; i < ohci->num_ports; i++) {
1da177e4
LT
370 u32 status = roothub_portstatus (ohci, i);
371
8d1a243b
AS
372 /* can't autostop if ports are connected */
373 any_connected |= (status & RH_PS_CCS);
374
1da177e4
LT
375 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
376 | RH_PS_OCIC | RH_PS_PRSC)) {
377 changed = 1;
378 if (i < 7)
379 buf [0] |= 1 << (i + 1);
380 else
381 buf [1] |= 1 << (i - 7);
1da177e4 382 }
d413984a 383 }
1da177e4 384
8d1a243b
AS
385 hcd->poll_rh = 1;
386
387 /* carry out appropriate state changes */
388 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
389
390 case OHCI_USB_OPER:
391 /* keep on polling until we know a device is connected
392 * and RHSC is enabled */
393 if (!ohci->autostop) {
394 if (any_connected) {
052ac01a
AS
395 if (ohci_readl(ohci, &ohci->regs->intrenable) &
396 OHCI_INTR_RHSC)
8d1a243b
AS
397 hcd->poll_rh = 0;
398 } else {
399 ohci->autostop = 1;
400 ohci->next_statechange = jiffies + HZ;
401 }
402
403 /* if no devices have been attached for one second, autostop */
404 } else {
405 if (changed || any_connected) {
406 ohci->autostop = 0;
407 ohci->next_statechange = jiffies +
408 STATECHANGE_DELAY;
3da2495c
AS
409 } else if (device_may_wakeup(&hcd->self.root_hub->dev)
410 && time_after_eq(jiffies,
8d1a243b
AS
411 ohci->next_statechange)
412 && !ohci->ed_rm_list
413 && !(ohci->hc_control &
414 OHCI_SCHED_ENABLES)) {
415 ohci_rh_suspend (ohci, 1);
416 }
417 }
418 break;
419
420 /* if there is a port change, autostart or ask to be resumed */
421 case OHCI_USB_SUSPEND:
422 case OHCI_USB_RESUME:
423 if (changed) {
424 if (ohci->autostop)
425 ohci_rh_resume (ohci);
426 else
427 usb_hcd_resume_root_hub (hcd);
428 } else {
429 /* everything is idle, no need for polling */
430 hcd->poll_rh = 0;
431 }
432 break;
433 }
d413984a 434
1da177e4
LT
435done:
436 spin_unlock_irqrestore (&ohci->lock, flags);
437
1da177e4
LT
438 return changed ? length : 0;
439}
440
441/*-------------------------------------------------------------------------*/
442
443static void
444ohci_hub_descriptor (
445 struct ohci_hcd *ohci,
446 struct usb_hub_descriptor *desc
447) {
448 u32 rh = roothub_a (ohci);
1da177e4
LT
449 u16 temp;
450
451 desc->bDescriptorType = 0x29;
452 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
453 desc->bHubContrCurrent = 0;
454
fdd13b36
DB
455 desc->bNbrPorts = ohci->num_ports;
456 temp = 1 + (ohci->num_ports / 8);
1da177e4
LT
457 desc->bDescLength = 7 + 2 * temp;
458
459 temp = 0;
460 if (rh & RH_A_NPS) /* no power switching? */
461 temp |= 0x0002;
462 if (rh & RH_A_PSM) /* per-port power switching? */
463 temp |= 0x0001;
464 if (rh & RH_A_NOCP) /* no overcurrent reporting? */
465 temp |= 0x0010;
466 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */
467 temp |= 0x0008;
468 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
469
470 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
471 rh = roothub_b (ohci);
b2134bcd 472 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
1da177e4 473 desc->bitmap [0] = rh & RH_B_DR;
fdd13b36 474 if (ohci->num_ports > 7) {
1da177e4 475 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
b2134bcd 476 desc->bitmap [2] = 0xff;
1da177e4
LT
477 } else
478 desc->bitmap [1] = 0xff;
479}
480
481/*-------------------------------------------------------------------------*/
482
483#ifdef CONFIG_USB_OTG
484
485static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
486{
487 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
488 u32 status;
489
490 if (!port)
491 return -EINVAL;
492 port--;
493
494 /* start port reset before HNP protocol times out */
495 status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]);
496 if (!(status & RH_PS_CCS))
497 return -ENODEV;
498
499 /* khubd will finish the reset later */
500 ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]);
501 return 0;
502}
503
504static void start_hnp(struct ohci_hcd *ohci);
505
506#else
507
508#define ohci_start_port_reset NULL
509
510#endif
511
512/*-------------------------------------------------------------------------*/
513
514
515/* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
516 * not necessarily continuous ... to guard against resume signaling.
517 * The short timeout is safe for non-root hubs, and is backward-compatible
518 * with earlier Linux hosts.
519 */
520#ifdef CONFIG_USB_SUSPEND
521#define PORT_RESET_MSEC 50
522#else
523#define PORT_RESET_MSEC 10
524#endif
525
526/* this timer value might be vendor-specific ... */
527#define PORT_RESET_HW_MSEC 10
528
529/* wrap-aware logic morphed from <linux/jiffies.h> */
530#define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
531
532/* called from some task, normally khubd */
533static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
534{
535 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
536 u32 temp;
537 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
538 u16 reset_done = now + PORT_RESET_MSEC;
539
540 /* build a "continuous enough" reset signal, with up to
541 * 3msec gap between pulses. scheduler HZ==100 must work;
542 * this might need to be deadline-scheduled.
543 */
544 do {
545 /* spin until any current reset finishes */
546 for (;;) {
547 temp = ohci_readl (ohci, portstat);
548 if (!(temp & RH_PS_PRS))
549 break;
550 udelay (500);
551 }
552
553 if (!(temp & RH_PS_CCS))
554 break;
555 if (temp & RH_PS_PRSC)
556 ohci_writel (ohci, RH_PS_PRSC, portstat);
557
558 /* start the next reset, sleep till it's probably done */
559 ohci_writel (ohci, RH_PS_PRS, portstat);
560 msleep(PORT_RESET_HW_MSEC);
561 now = ohci_readl(ohci, &ohci->regs->fmnumber);
562 } while (tick_before(now, reset_done));
563 /* caller synchronizes using PRSC */
564}
565
566static int ohci_hub_control (
567 struct usb_hcd *hcd,
568 u16 typeReq,
569 u16 wValue,
570 u16 wIndex,
571 char *buf,
572 u16 wLength
573) {
574 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
575 int ports = hcd_to_bus (hcd)->root_hub->maxchild;
576 u32 temp;
577 int retval = 0;
578
8de98402
BH
579 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
580 return -ESHUTDOWN;
581
1da177e4
LT
582 switch (typeReq) {
583 case ClearHubFeature:
584 switch (wValue) {
585 case C_HUB_OVER_CURRENT:
586 ohci_writel (ohci, RH_HS_OCIC,
587 &ohci->regs->roothub.status);
588 case C_HUB_LOCAL_POWER:
589 break;
590 default:
591 goto error;
592 }
593 break;
594 case ClearPortFeature:
595 if (!wIndex || wIndex > ports)
596 goto error;
597 wIndex--;
598
599 switch (wValue) {
600 case USB_PORT_FEAT_ENABLE:
601 temp = RH_PS_CCS;
602 break;
603 case USB_PORT_FEAT_C_ENABLE:
604 temp = RH_PS_PESC;
605 break;
606 case USB_PORT_FEAT_SUSPEND:
607 temp = RH_PS_POCI;
1da177e4
LT
608 break;
609 case USB_PORT_FEAT_C_SUSPEND:
610 temp = RH_PS_PSSC;
611 break;
612 case USB_PORT_FEAT_POWER:
613 temp = RH_PS_LSDA;
614 break;
615 case USB_PORT_FEAT_C_CONNECTION:
616 temp = RH_PS_CSC;
617 break;
618 case USB_PORT_FEAT_C_OVER_CURRENT:
619 temp = RH_PS_OCIC;
620 break;
621 case USB_PORT_FEAT_C_RESET:
622 temp = RH_PS_PRSC;
623 break;
624 default:
625 goto error;
626 }
627 ohci_writel (ohci, temp,
628 &ohci->regs->roothub.portstatus [wIndex]);
629 // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]);
630 break;
631 case GetHubDescriptor:
632 ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf);
633 break;
634 case GetHubStatus:
635 temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
92164c5d 636 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
1da177e4
LT
637 break;
638 case GetPortStatus:
639 if (!wIndex || wIndex > ports)
640 goto error;
641 wIndex--;
642 temp = roothub_portstatus (ohci, wIndex);
92164c5d 643 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
1da177e4
LT
644
645#ifndef OHCI_VERBOSE_DEBUG
646 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
647#endif
648 dbg_port (ohci, "GetStatus", wIndex, temp);
649 break;
650 case SetHubFeature:
651 switch (wValue) {
652 case C_HUB_OVER_CURRENT:
653 // FIXME: this can be cleared, yes?
654 case C_HUB_LOCAL_POWER:
655 break;
656 default:
657 goto error;
658 }
659 break;
660 case SetPortFeature:
661 if (!wIndex || wIndex > ports)
662 goto error;
663 wIndex--;
664 switch (wValue) {
665 case USB_PORT_FEAT_SUSPEND:
666#ifdef CONFIG_USB_OTG
667 if (hcd->self.otg_port == (wIndex + 1)
668 && hcd->self.b_hnp_enable)
669 start_hnp(ohci);
670 else
671#endif
672 ohci_writel (ohci, RH_PS_PSS,
673 &ohci->regs->roothub.portstatus [wIndex]);
674 break;
675 case USB_PORT_FEAT_POWER:
676 ohci_writel (ohci, RH_PS_PPS,
677 &ohci->regs->roothub.portstatus [wIndex]);
678 break;
679 case USB_PORT_FEAT_RESET:
680 root_port_reset (ohci, wIndex);
681 break;
682 default:
683 goto error;
684 }
685 break;
686
687 default:
688error:
689 /* "protocol stall" on error */
690 retval = -EPIPE;
691 }
692 return retval;
693}
694