2 * URB OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * [ Initialisation is based on Linus' ]
7 * [ uhci code and gregs ohci fragments ]
8 * [ (C) Copyright 1999 Linus Torvalds ]
9 * [ (C) Copyright 1999 Gregory P. Smith]
14 * v5.2 1999/12/07 URB 3rd preview,
15 * v5.1 1999/11/30 URB 2nd preview, cpia, (usb-scsi)
16 * v5.0 1999/11/22 URB Technical preview, Paul Mackerras powerbook susp/resume
17 * i386: HUB, Keyboard, Mouse, Printer
19 * v4.3 1999/10/27 multiple HCs, bulk_request
20 * v4.2 1999/09/05 ISO API alpha, new dev alloc, neg Error-codes
21 * v4.1 1999/08/27 Randy Dunlap's - ISO API first impl.
24 * v2.1 1999/05/09 code clean up
26 * v1.0 1999/04/27 initial release
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/pci.h>
34 #include <linux/kernel.h>
35 #include <linux/delay.h>
36 #include <linux/ioport.h>
37 #include <linux/sched.h>
38 #include <linux/malloc.h>
39 #include <linux/smp_lock.h>
40 #include <linux/errno.h>
41 #include <linux/timer.h>
42 #include <linux/list.h>
43 #include <linux/interrupt.h> /* for in_interrupt() */
45 #include <linux/usb.h>
49 #include <asm/system.h>
50 #include <asm/unaligned.h>
52 #define OHCI_USE_NPS // force NoPowerSwitching mode
57 static int handle_pm_event (struct pm_dev
*dev
, pm_request_t rqst
, void *data
);
59 #ifdef CONFIG_PMAC_PBOOK
60 #include <linux/adb.h>
61 #include <linux/pmu.h>
65 /* For initializing controller (mask in an HCFS mode too) */
66 #define OHCI_CONTROL_INIT \
67 (OHCI_CTRL_CBSR & 0x3) \
68 | OHCI_CTRL_BLE | OHCI_CTRL_CLE | OHCI_CTRL_IE | OHCI_CTRL_PLE
70 static DECLARE_WAIT_QUEUE_HEAD (op_wakeup
);
71 static LIST_HEAD (ohci_hcd_list
);
72 static spinlock_t usb_ed_lock
= SPIN_LOCK_UNLOCKED
;
74 /*-------------------------------------------------------------------------*
75 * URB support functions
76 *-------------------------------------------------------------------------*/
78 /* free the private part of an URB */
80 static void urb_rm_priv (urb_t
* urb
)
82 urb_priv_t
* urb_priv
= urb
->hcpriv
;
85 if (!urb_priv
) return;
87 for (i
= 0; i
< urb_priv
->length
; i
++) {
88 if (urb_priv
->td
[i
]) {
89 OHCI_FREE (urb_priv
->td
[i
]);
97 /*-------------------------------------------------------------------------*/
100 static int sohci_get_current_frame_number (struct usb_device
* dev
);
102 /* debug| print the main components of an URB
103 * small: 0) header + data packets 1) just header */
105 static void urb_print (urb_t
* urb
, char * str
, int small
)
107 unsigned int pipe
= urb
->pipe
;
110 if (!urb
->dev
|| !urb
->dev
->bus
) {
111 dbg("%s URB: no dev", str
);
115 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,flags:%4x,len:%d/%d,stat:%d(%x)",
117 sohci_get_current_frame_number (urb
->dev
),
118 usb_pipedevice (pipe
),
119 usb_pipeendpoint (pipe
),
120 usb_pipeout (pipe
)? 'O': 'I',
121 usb_pipetype (pipe
) < 2? (usb_pipeint (pipe
)? "INTR": "ISOC"):
122 (usb_pipecontrol (pipe
)? "CTRL": "BULK"),
125 urb
->transfer_buffer_length
,
126 urb
->status
, urb
->status
);
128 if (usb_pipecontrol (pipe
)) {
129 printk (KERN_DEBUG __FILE__
": cmd(8):");
130 for (i
= 0; i
< 8 ; i
++)
131 printk (" %02x", ((__u8
*) urb
->setup_packet
) [i
]);
134 if (urb
->transfer_buffer_length
> 0 && urb
->transfer_buffer
) {
135 printk (KERN_DEBUG __FILE__
": data(%d/%d):",
137 urb
->transfer_buffer_length
);
138 len
= usb_pipeout (pipe
)?
139 urb
->transfer_buffer_length
: urb
->actual_length
;
140 for (i
= 0; i
< 16 && i
< len
; i
++)
141 printk (" %02x", ((__u8
*) urb
->transfer_buffer
) [i
]);
142 printk ("%s stat:%d\n", i
< len
? "...": "", urb
->status
);
147 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
148 void ep_print_int_eds (ohci_t
* ohci
, char * str
) {
151 for (i
= 0; i
< 32; i
++) {
153 ed_p
= &(ohci
->hcca
.int_table
[i
]);
156 printk (KERN_DEBUG __FILE__
": %s branch int %2d(%2x):", str
, i
, i
);
157 while (*ed_p
!= 0 && j
--) {
158 ed_t
*ed
= (ed_t
*) bus_to_virt(le32_to_cpup(ed_p
));
159 printk (" ed: %4x;", ed
->hwINFO
);
160 ed_p
= &ed
->hwNextED
;
167 static void ohci_dump_intr_mask (char *label
, __u32 mask
)
169 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
172 (mask
& OHCI_INTR_MIE
) ? " MIE" : "",
173 (mask
& OHCI_INTR_OC
) ? " OC" : "",
174 (mask
& OHCI_INTR_RHSC
) ? " RHSC" : "",
175 (mask
& OHCI_INTR_FNO
) ? " FNO" : "",
176 (mask
& OHCI_INTR_UE
) ? " UE" : "",
177 (mask
& OHCI_INTR_RD
) ? " RD" : "",
178 (mask
& OHCI_INTR_SF
) ? " SF" : "",
179 (mask
& OHCI_INTR_WDH
) ? " WDH" : "",
180 (mask
& OHCI_INTR_SO
) ? " SO" : ""
184 static void maybe_print_eds (char *label
, __u32 value
)
187 dbg ("%s %08x", label
, value
);
190 static char *hcfs2string (int state
)
193 case OHCI_USB_RESET
: return "reset";
194 case OHCI_USB_RESUME
: return "resume";
195 case OHCI_USB_OPER
: return "operational";
196 case OHCI_USB_SUSPEND
: return "suspend";
201 // dump control and status registers
202 static void ohci_dump_status (ohci_t
*controller
)
204 struct ohci_regs
*regs
= controller
->regs
;
207 temp
= readl (®s
->revision
) & 0xff;
209 dbg ("spec %d.%d", (temp
>> 4), (temp
& 0x0f));
211 temp
= readl (®s
->control
);
212 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp
,
213 (temp
& OHCI_CTRL_RWE
) ? " RWE" : "",
214 (temp
& OHCI_CTRL_RWC
) ? " RWC" : "",
215 (temp
& OHCI_CTRL_IR
) ? " IR" : "",
216 hcfs2string (temp
& OHCI_CTRL_HCFS
),
217 (temp
& OHCI_CTRL_BLE
) ? " BLE" : "",
218 (temp
& OHCI_CTRL_CLE
) ? " CLE" : "",
219 (temp
& OHCI_CTRL_IE
) ? " IE" : "",
220 (temp
& OHCI_CTRL_PLE
) ? " PLE" : "",
221 temp
& OHCI_CTRL_CBSR
224 temp
= readl (®s
->cmdstatus
);
225 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp
,
226 (temp
& OHCI_SOC
) >> 16,
227 (temp
& OHCI_OCR
) ? " OCR" : "",
228 (temp
& OHCI_BLF
) ? " BLF" : "",
229 (temp
& OHCI_CLF
) ? " CLF" : "",
230 (temp
& OHCI_HCR
) ? " HCR" : ""
233 ohci_dump_intr_mask ("intrstatus", readl (®s
->intrstatus
));
234 ohci_dump_intr_mask ("intrenable", readl (®s
->intrenable
));
235 // intrdisable always same as intrenable
236 // ohci_dump_intr_mask ("intrdisable", readl (®s->intrdisable));
238 maybe_print_eds ("ed_periodcurrent", readl (®s
->ed_periodcurrent
));
240 maybe_print_eds ("ed_controlhead", readl (®s
->ed_controlhead
));
241 maybe_print_eds ("ed_controlcurrent", readl (®s
->ed_controlcurrent
));
243 maybe_print_eds ("ed_bulkhead", readl (®s
->ed_bulkhead
));
244 maybe_print_eds ("ed_bulkcurrent", readl (®s
->ed_bulkcurrent
));
246 maybe_print_eds ("donehead", readl (®s
->donehead
));
249 static void ohci_dump_roothub (ohci_t
*controller
, int verbose
)
251 struct ohci_regs
*regs
= controller
->regs
;
254 temp
= readl (®s
->roothub
.a
);
255 ndp
= (temp
& RH_A_NDP
);
258 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp
,
259 ((temp
& RH_A_POTPGT
) >> 24) & 0xff,
260 (temp
& RH_A_NOCP
) ? " NOCP" : "",
261 (temp
& RH_A_OCPM
) ? " OCPM" : "",
262 (temp
& RH_A_DT
) ? " DT" : "",
263 (temp
& RH_A_NPS
) ? " NPS" : "",
264 (temp
& RH_A_PSM
) ? " PSM" : "",
267 temp
= readl (®s
->roothub
.b
);
268 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
270 (temp
& RH_B_PPCM
) >> 16,
273 temp
= readl (®s
->roothub
.status
);
274 dbg ("roothub.status: %08x%s%s%s%s%s%s",
276 (temp
& RH_HS_CRWE
) ? " CRWE" : "",
277 (temp
& RH_HS_OCIC
) ? " OCIC" : "",
278 (temp
& RH_HS_LPSC
) ? " LPSC" : "",
279 (temp
& RH_HS_DRWE
) ? " DRWE" : "",
280 (temp
& RH_HS_OCI
) ? " OCI" : "",
281 (temp
& RH_HS_LPS
) ? " LPS" : ""
285 for (i
= 0; i
< ndp
; i
++) {
286 temp
= readl (®s
->roothub
.portstatus
[i
]);
287 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
290 (temp
& RH_PS_PRSC
) ? " PRSC" : "",
291 (temp
& RH_PS_OCIC
) ? " OCIC" : "",
292 (temp
& RH_PS_PSSC
) ? " PSSC" : "",
293 (temp
& RH_PS_PESC
) ? " PESC" : "",
294 (temp
& RH_PS_CSC
) ? " CSC" : "",
296 (temp
& RH_PS_LSDA
) ? " LSDA" : "",
297 (temp
& RH_PS_PPS
) ? " PPS" : "",
298 (temp
& RH_PS_PRS
) ? " PRS" : "",
299 (temp
& RH_PS_POCI
) ? " POCI" : "",
300 (temp
& RH_PS_PSS
) ? " PSS" : "",
302 (temp
& RH_PS_PES
) ? " PES" : "",
303 (temp
& RH_PS_CCS
) ? " CCS" : ""
308 static void ohci_dump (ohci_t
*controller
, int verbose
)
310 dbg ("OHCI controller %s state", controller
->ohci_dev
->slot_name
);
312 // dumps some of the state we know about
313 ohci_dump_status (controller
);
315 ep_print_int_eds (controller
, "hcca");
316 dbg ("hcca frame #%04x", controller
->hcca
.frame_no
);
317 ohci_dump_roothub (controller
, 1);
323 /*-------------------------------------------------------------------------*
324 * Interface functions (URB)
325 *-------------------------------------------------------------------------*/
327 /* return a request to the completion handler */
329 static int sohci_return_urb (urb_t
* urb
)
331 urb_priv_t
* urb_priv
= urb
->hcpriv
;
336 /* just to be sure */
337 if (!urb
->complete
) {
339 usb_dec_dev_use (urb
->dev
);
343 if (!urb_priv
) return -1; /* urb already unlinked */
346 urb_print (urb
, "RET", usb_pipeout (urb
->pipe
));
349 switch (usb_pipetype (urb
->pipe
)) {
351 urb
->complete (urb
); /* call complete and requeue URB */
352 urb
->actual_length
= 0;
353 urb
->status
= USB_ST_URB_PENDING
;
354 if (urb_priv
->state
!= URB_DEL
)
358 case PIPE_ISOCHRONOUS
:
359 for (urbt
= urb
->next
; urbt
&& (urbt
!= urb
); urbt
= urbt
->next
);
360 if (urbt
) { /* send the reply and requeue URB */
363 spin_lock_irqsave (&usb_ed_lock
, flags
);
364 urb
->actual_length
= 0;
365 urb
->status
= USB_ST_URB_PENDING
;
366 urb
->start_frame
= urb_priv
->ed
->last_iso
+ 1;
367 if (urb_priv
->state
!= URB_DEL
) {
368 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
369 urb
->iso_frame_desc
[i
].actual_length
= 0;
370 urb
->iso_frame_desc
[i
].status
= -EXDEV
;
374 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
376 } else { /* unlink URB, call complete */
378 usb_dec_dev_use (urb
->dev
);
384 case PIPE_CONTROL
: /* unlink URB, call complete */
386 usb_dec_dev_use (urb
->dev
);
393 /*-------------------------------------------------------------------------*/
395 /* get a transfer request */
397 static int sohci_submit_urb (urb_t
* urb
)
401 urb_priv_t
* urb_priv
;
402 unsigned int pipe
= urb
->pipe
;
406 if (!urb
->dev
|| !urb
->dev
->bus
) return -EINVAL
;
408 if (urb
->hcpriv
) return -EINVAL
; /* urb already in use */
410 // if(usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)))
413 usb_inc_dev_use (urb
->dev
);
414 ohci
= (ohci_t
*) urb
->dev
->bus
->hcpriv
;
417 urb_print (urb
, "SUB", usb_pipein (pipe
));
420 /* a request to the virtual root hub */
421 if (usb_pipedevice (pipe
) == ohci
->rh
.devnum
)
422 return rh_submit_urb (urb
);
424 /* when controller's hung, permit only hub cleanup attempts
425 * such as powering down ports */
429 /* every endpoint has a ed, locate and fill it */
430 if (!(ed
= ep_add_ed (urb
->dev
, pipe
, urb
->interval
, 1))) {
431 usb_dec_dev_use (urb
->dev
);
435 /* for the private part of the URB we need the number of TDs (size) */
436 switch (usb_pipetype (pipe
)) {
437 case PIPE_BULK
: /* one TD for every 4096 Byte */
438 size
= (urb
->transfer_buffer_length
- 1) / 4096 + 1;
440 case PIPE_ISOCHRONOUS
: /* number of packets from URB */
441 size
= urb
->number_of_packets
;
442 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
443 urb
->iso_frame_desc
[i
].actual_length
= 0;
444 urb
->iso_frame_desc
[i
].status
= -EXDEV
;
447 case PIPE_CONTROL
: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
448 size
= (urb
->transfer_buffer_length
== 0)? 2:
449 (urb
->transfer_buffer_length
- 1) / 4096 + 3;
451 case PIPE_INTERRUPT
: /* one TD */
457 /* allocate the private part or the URB */
458 urb_priv
= kmalloc (sizeof (urb_priv_t
) + size
* sizeof (td_t
*),
459 in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
);
461 usb_dec_dev_use (urb
->dev
);
464 memset (urb_priv
, 0, sizeof (urb_priv_t
) + size
* sizeof (td_t
*));
466 /* fill the private part of the URB */
467 urb
->hcpriv
= urb_priv
;
468 urb_priv
->length
= size
;
469 urb_priv
->td_cnt
= 0;
473 /* allocate the TDs */
474 for (i
= 0; i
< size
; i
++) {
475 OHCI_ALLOC (urb_priv
->td
[i
], sizeof (td_t
));
476 if (!urb_priv
->td
[i
]) {
477 usb_dec_dev_use (urb
->dev
);
482 spin_lock_irqsave (&usb_ed_lock
, flags
);
483 if (ed
->state
== ED_NEW
|| (ed
->state
& ED_DEL
)) {
485 usb_dec_dev_use (urb
->dev
);
486 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
490 /* for ISOC transfers calculate start frame index */
491 if (urb
->transfer_flags
& USB_ISO_ASAP
) {
492 urb
->start_frame
= ((ed
->state
== ED_OPER
)? (ed
->last_iso
+ 1):
493 (le16_to_cpu (ohci
->hcca
.frame_no
) + 10)) & 0xffff;
495 urb
->status
= USB_ST_URB_PENDING
;
496 urb
->actual_length
= 0;
498 if (ed
->state
!= ED_OPER
) /* link the ed into a chain if is not already */
501 urb
->status
= USB_ST_URB_PENDING
;
502 td_submit_urb (urb
); /* fill the TDs and link it to the ed */
504 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
509 /*-------------------------------------------------------------------------*/
511 /* deactivate all TDs and remove the private part of the URB */
513 static int sohci_unlink_urb (urb_t
* urb
)
517 DECLARE_WAITQUEUE (wait
, current
);
519 if (!urb
) /* just to be sure */
522 if (!urb
->dev
|| !urb
->dev
->bus
)
525 ohci
= (ohci_t
*) urb
->dev
->bus
->hcpriv
;
528 urb_print (urb
, "UNLINK", 1);
531 if (usb_pipedevice (urb
->pipe
) == ohci
->rh
.devnum
) {
532 usb_dec_dev_use(urb
->dev
);
533 return rh_unlink_urb (urb
); /* a request to the virtual root hub */
538 if (urb
->status
== USB_ST_URB_PENDING
&& !ohci
->disabled
) {
539 urb_priv_t
* urb_priv
= urb
->hcpriv
;
540 urb_priv
->state
= URB_DEL
;
542 /* we want to delete the TDs of an URB from an ed
543 * request the deletion, it will be handled at the
546 spin_lock_irqsave (&usb_ed_lock
, flags
);
547 ep_rm_ed (urb
->dev
, urb_priv
->ed
);
548 urb_priv
->ed
->state
|= ED_URB_DEL
;
549 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
550 if (!(urb
->transfer_flags
& USB_ASYNC_UNLINK
)) {
551 usb_dec_dev_use (urb
->dev
);
552 add_wait_queue (&op_wakeup
, &wait
);
553 current
->state
= TASK_UNINTERRUPTIBLE
;
554 if (!schedule_timeout (HZ
/ 10)) /* wait until all TDs are deleted */
555 err("unlink URB timeout!");
556 remove_wait_queue (&op_wakeup
, &wait
);
557 urb
->status
= -ENOENT
;
559 /* usb_dec_dev_use done in dl_del_list() */
560 urb
->status
= -EINPROGRESS
;
563 usb_dec_dev_use (urb
->dev
);
565 if (urb
->complete
&& (urb
->transfer_flags
& USB_ASYNC_UNLINK
)) {
569 urb
->status
= -ENOENT
;
575 /*-------------------------------------------------------------------------*/
577 /* allocate private data space for a usb device */
579 static int sohci_alloc_dev (struct usb_device
*usb_dev
)
581 struct ohci_device
* dev
;
583 dev
= kmalloc (sizeof (*dev
), GFP_KERNEL
);
587 memset (dev
, 0, sizeof (*dev
));
589 usb_dev
->hcpriv
= dev
;
594 /*-------------------------------------------------------------------------*/
596 /* free private data space of usb device */
598 static int sohci_free_dev (struct usb_device
* usb_dev
)
603 DECLARE_WAITQUEUE (wait
, current
);
604 struct ohci_device
* dev
= usb_to_ohci (usb_dev
);
605 ohci_t
* ohci
= usb_dev
->bus
->hcpriv
;
609 if (usb_dev
->devnum
>= 0) {
611 /* delete all TDs of all EDs */
612 spin_lock_irqsave (&usb_ed_lock
, flags
);
613 for(i
= 0; i
< NUM_EDS
; i
++) {
615 if (ed
->state
!= ED_NEW
) {
616 if (ed
->state
== ED_OPER
) ep_unlink (ohci
, ed
);
617 ep_rm_ed (usb_dev
, ed
);
622 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
625 add_wait_queue (&op_wakeup
, &wait
);
626 current
->state
= TASK_UNINTERRUPTIBLE
;
627 schedule_timeout (HZ
/ 10);
628 remove_wait_queue (&op_wakeup
, &wait
);
636 /*-------------------------------------------------------------------------*/
638 /* tell us the current USB frame number */
640 static int sohci_get_current_frame_number (struct usb_device
*usb_dev
)
642 ohci_t
* ohci
= usb_dev
->bus
->hcpriv
;
644 return le16_to_cpu (ohci
->hcca
.frame_no
);
647 /*-------------------------------------------------------------------------*/
649 struct usb_operations sohci_device_operations
= {
652 sohci_get_current_frame_number
,
657 /*-------------------------------------------------------------------------*
658 * ED handling functions
659 *-------------------------------------------------------------------------*/
661 /* search for the right branch to insert an interrupt ed into the int tree
662 * do some load ballancing;
663 * returns the branch and
664 * sets the interval to interval = 2^integer (ld (interval)) */
666 static int ep_int_ballance (ohci_t
* ohci
, int interval
, int load
)
670 /* search for the least loaded interrupt endpoint branch of all 32 branches */
671 for (i
= 0; i
< 32; i
++)
672 if (ohci
->ohci_int_load
[branch
] > ohci
->ohci_int_load
[i
]) branch
= i
;
674 branch
= branch
% interval
;
675 for (i
= branch
; i
< 32; i
+= interval
) ohci
->ohci_int_load
[i
] += load
;
680 /*-------------------------------------------------------------------------*/
682 /* 2^int( ld (inter)) */
684 static int ep_2_n_interval (int inter
)
687 for (i
= 0; ((inter
>> i
) > 1 ) && (i
< 5); i
++);
691 /*-------------------------------------------------------------------------*/
693 /* the int tree is a binary tree
694 * in order to process it sequentially the indexes of the branches have to be mapped
695 * the mapping reverses the bits of a word of num_bits length */
697 static int ep_rev (int num_bits
, int word
)
701 for (i
= 0; i
< num_bits
; i
++) wout
|= (((word
>> i
) & 1) << (num_bits
- i
- 1));
705 /*-------------------------------------------------------------------------*/
707 /* link an ed into one of the HC chains */
709 static int ep_link (ohci_t
* ohci
, ed_t
* edi
)
717 volatile ed_t
* ed
= edi
;
724 if (ohci
->ed_controltail
== NULL
) {
725 writel (virt_to_bus (ed
), &ohci
->regs
->ed_controlhead
);
727 ohci
->ed_controltail
->hwNextED
= cpu_to_le32 (virt_to_bus (ed
));
729 ed
->ed_prev
= ohci
->ed_controltail
;
730 ohci
->ed_controltail
= edi
;
735 if (ohci
->ed_bulktail
== NULL
) {
736 writel (virt_to_bus (ed
), &ohci
->regs
->ed_bulkhead
);
738 ohci
->ed_bulktail
->hwNextED
= cpu_to_le32 (virt_to_bus (ed
));
740 ed
->ed_prev
= ohci
->ed_bulktail
;
741 ohci
->ed_bulktail
= edi
;
746 interval
= ep_2_n_interval (ed
->int_period
);
747 ed
->int_interval
= interval
;
748 int_branch
= ep_int_ballance (ohci
, interval
, load
);
749 ed
->int_branch
= int_branch
;
751 for (i
= 0; i
< ep_rev (6, interval
); i
+= inter
) {
753 for (ed_p
= &(ohci
->hcca
.int_table
[ep_rev (5, i
) + int_branch
]);
754 (*ed_p
!= 0) && (((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->int_interval
>= interval
);
755 ed_p
= &(((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->hwNextED
))
756 inter
= ep_rev (6, ((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->int_interval
);
757 ed
->hwNextED
= *ed_p
;
758 *ed_p
= cpu_to_le32 (virt_to_bus (ed
));
761 ep_print_int_eds (ohci
, "LINK_INT");
767 ed
->int_interval
= 1;
768 if (ohci
->ed_isotail
!= NULL
) {
769 ohci
->ed_isotail
->hwNextED
= cpu_to_le32 (virt_to_bus (ed
));
770 ed
->ed_prev
= ohci
->ed_isotail
;
772 for ( i
= 0; i
< 32; i
+= inter
) {
774 for (ed_p
= &(ohci
->hcca
.int_table
[ep_rev (5, i
)]);
776 ed_p
= &(((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->hwNextED
))
777 inter
= ep_rev (6, ((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->int_interval
);
778 *ed_p
= cpu_to_le32 (virt_to_bus (ed
));
782 ohci
->ed_isotail
= edi
;
784 ep_print_int_eds (ohci
, "LINK_ISO");
791 /*-------------------------------------------------------------------------*/
793 /* unlink an ed from one of the HC chains.
794 * just the link to the ed is unlinked.
795 * the link from the ed still points to another operational ed or 0
796 * so the HC can eventually finish the processing of the unlinked ed */
798 static int ep_unlink (ohci_t
* ohci
, ed_t
* ed
)
809 if (ed
->ed_prev
== NULL
) {
810 writel (le32_to_cpup (&ed
->hwNextED
), &ohci
->regs
->ed_controlhead
);
812 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
814 if(ohci
->ed_controltail
== ed
) {
815 ohci
->ed_controltail
= ed
->ed_prev
;
817 ((ed_t
*) bus_to_virt (le32_to_cpup (&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
822 if (ed
->ed_prev
== NULL
) {
823 writel (le32_to_cpup (&ed
->hwNextED
), &ohci
->regs
->ed_bulkhead
);
825 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
827 if (ohci
->ed_bulktail
== ed
) {
828 ohci
->ed_bulktail
= ed
->ed_prev
;
830 ((ed_t
*) bus_to_virt (le32_to_cpup (&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
835 int_branch
= ed
->int_branch
;
836 interval
= ed
->int_interval
;
838 for (i
= 0; i
< ep_rev (6, interval
); i
+= inter
) {
839 for (ed_p
= &(ohci
->hcca
.int_table
[ep_rev (5, i
) + int_branch
]), inter
= 1;
840 (*ed_p
!= 0) && (*ed_p
!= ed
->hwNextED
);
841 ed_p
= &(((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->hwNextED
),
842 inter
= ep_rev (6, ((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->int_interval
)) {
843 if(((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
))) == ed
) {
844 *ed_p
= ed
->hwNextED
;
849 for (i
= int_branch
; i
< 32; i
+= interval
)
850 ohci
->ohci_int_load
[i
] -= ed
->int_load
;
852 ep_print_int_eds (ohci
, "UNLINK_INT");
857 if (ohci
->ed_isotail
== ed
)
858 ohci
->ed_isotail
= ed
->ed_prev
;
859 if (ed
->hwNextED
!= 0)
860 ((ed_t
*) bus_to_virt (le32_to_cpup (&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
862 if (ed
->ed_prev
!= NULL
) {
863 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
865 for (i
= 0; i
< 32; i
+= inter
) {
867 for (ed_p
= &(ohci
->hcca
.int_table
[ep_rev (5, i
)]);
869 ed_p
= &(((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->hwNextED
)) {
870 inter
= ep_rev (6, ((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
)))->int_interval
);
871 if(((ed_t
*) bus_to_virt (le32_to_cpup (ed_p
))) == ed
) {
872 *ed_p
= ed
->hwNextED
;
879 ep_print_int_eds (ohci
, "UNLINK_ISO");
883 ed
->state
= ED_UNLINK
;
888 /*-------------------------------------------------------------------------*/
890 /* add/reinit an endpoint; this should be done once at the usb_set_configuration command,
891 * but the USB stack is a little bit stateless so we do it at every transaction
892 * if the state of the ed is ED_NEW then a dummy td is added and the state is changed to ED_UNLINK
893 * in all other cases the state is left unchanged
894 * the ed info fields are setted anyway even though most of them should not change */
896 static ed_t
* ep_add_ed (struct usb_device
* usb_dev
, unsigned int pipe
, int interval
, int load
)
898 ohci_t
* ohci
= usb_dev
->bus
->hcpriv
;
904 spin_lock (&usb_ed_lock
);
906 ed
= ed_ret
= &(usb_to_ohci (usb_dev
)->ed
[(usb_pipeendpoint (pipe
) << 1) |
907 (usb_pipecontrol (pipe
)? 0: usb_pipeout (pipe
))]);
909 if((ed
->state
& ED_DEL
) || (ed
->state
& ED_URB_DEL
))
910 return NULL
; /* pending delete request */
912 if (ed
->state
== ED_NEW
) {
913 ed
->hwINFO
= cpu_to_le32 (OHCI_ED_SKIP
); /* skip ed */
914 OHCI_ALLOC (td
, sizeof (*td
)); /* dummy td; end of td list for ed */
915 if(!td
) return NULL
; /* out of memory */
916 ed
->hwTailP
= cpu_to_le32 (virt_to_bus (td
));
917 ed
->hwHeadP
= ed
->hwTailP
;
918 ed
->state
= ED_UNLINK
;
919 ed
->type
= usb_pipetype (pipe
);
920 usb_to_ohci (usb_dev
)->ed_cnt
++;
923 ohci
->dev
[usb_pipedevice (pipe
)] = usb_dev
;
925 ed
->hwINFO
= cpu_to_le32 (usb_pipedevice (pipe
)
926 | usb_pipeendpoint (pipe
) << 7
927 | (usb_pipeisoc (pipe
)? 0x8000: 0)
928 | (usb_pipecontrol (pipe
)? 0: (usb_pipeout (pipe
)? 0x800: 0x1000))
929 | usb_pipeslow (pipe
) << 13
930 | usb_maxpacket (usb_dev
, pipe
, usb_pipeout (pipe
)) << 16);
932 if (ed
->type
== INT
&& ed
->state
== ED_UNLINK
) {
933 ed
->int_period
= interval
;
937 spin_unlock(&usb_ed_lock
);
941 /*-------------------------------------------------------------------------*/
943 /* request the removal of an endpoint
944 * put the ep on the rm_list and request a stop of the bulk or ctrl list
945 * real removal is done at the next start of frame (SOF) hardware interrupt */
947 static void ep_rm_ed (struct usb_device
* usb_dev
, ed_t
* ed
)
950 ohci_t
* ohci
= usb_dev
->bus
->hcpriv
;
952 if ((ed
->state
& ED_DEL
) || (ed
->state
& ED_URB_DEL
)) return;
954 ed
->hwINFO
|= cpu_to_le32 (OHCI_ED_SKIP
);
956 writel (OHCI_INTR_SF
, &ohci
->regs
->intrstatus
);
957 writel (OHCI_INTR_SF
, &ohci
->regs
->intrenable
); /* enable sof interrupt */
959 frame
= le16_to_cpu (ohci
->hcca
.frame_no
) & 0x1;
960 ed
->ed_rm_list
= ohci
->ed_rm_list
[frame
];
961 ohci
->ed_rm_list
[frame
] = ed
;
964 case CTRL
: /* stop CTRL list */
965 writel (ohci
->hc_control
&= ~OHCI_CTRL_CLE
, &ohci
->regs
->control
);
967 case BULK
: /* stop BULK list */
968 writel (ohci
->hc_control
&= ~OHCI_CTRL_BLE
, &ohci
->regs
->control
);
973 /*-------------------------------------------------------------------------*
974 * TD handling functions
975 *-------------------------------------------------------------------------*/
979 static void td_fill (unsigned int info
, void * data
, int len
, urb_t
* urb
, int index
)
981 volatile td_t
* td
, * td_pt
;
982 urb_priv_t
* urb_priv
= urb
->hcpriv
;
984 if (index
>= urb_priv
->length
) {
985 err("internal OHCI error: TD index > length");
989 td_pt
= urb_priv
->td
[index
];
990 /* fill the old dummy TD */
991 td
= urb_priv
->td
[index
] = (td_t
*) bus_to_virt (le32_to_cpup (&urb_priv
->ed
->hwTailP
) & 0xfffffff0);
992 td
->ed
= urb_priv
->ed
;
995 td
->hwINFO
= cpu_to_le32 (info
);
996 if ((td
->ed
->type
& 3) == PIPE_ISOCHRONOUS
) {
997 td
->hwCBP
= cpu_to_le32 (((!data
|| !len
)?
998 0 : virt_to_bus (data
)) & 0xFFFFF000);
999 td
->ed
->last_iso
= info
& 0xffff;
1001 td
->hwCBP
= cpu_to_le32 (((!data
|| !len
)? 0 : virt_to_bus (data
)));
1003 td
->hwBE
= cpu_to_le32 ((!data
|| !len
)? 0: virt_to_bus (data
+ len
- 1));
1004 td
->hwNextTD
= cpu_to_le32 (virt_to_bus (td_pt
));
1005 td
->hwPSW
[0] = cpu_to_le16 ((virt_to_bus (data
) & 0x0FFF) | 0xE000);
1006 td_pt
->hwNextTD
= 0;
1007 td
->ed
->hwTailP
= td
->hwNextTD
;
1009 td
->next_dl_td
= NULL
; //td_pt;
1012 /*-------------------------------------------------------------------------*/
1014 /* prepare all TDs of a transfer */
1016 static void td_submit_urb (urb_t
* urb
)
1018 urb_priv_t
* urb_priv
= urb
->hcpriv
;
1019 ohci_t
* ohci
= (ohci_t
*) urb
->dev
->bus
->hcpriv
;
1020 void * ctrl
= urb
->setup_packet
;
1021 void * data
= urb
->transfer_buffer
;
1022 int data_len
= urb
->transfer_buffer_length
;
1025 unsigned int toggle
= 0;
1027 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
1028 if(usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
))) {
1029 toggle
= TD_T_TOGGLE
;
1031 toggle
= TD_T_DATA0
;
1032 usb_settoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
), 1);
1035 urb_priv
->td_cnt
= 0;
1037 switch (usb_pipetype (urb
->pipe
)) {
1039 info
= usb_pipeout (urb
->pipe
)?
1040 TD_CC
| TD_DP_OUT
: TD_CC
| TD_DP_IN
;
1041 while(data_len
> 4096) {
1042 td_fill (info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, 4096, urb
, cnt
);
1043 data
+= 4096; data_len
-= 4096; cnt
++;
1045 info
= usb_pipeout (urb
->pipe
)?
1046 TD_CC
| TD_DP_OUT
: TD_CC
| TD_R
| TD_DP_IN
;
1047 td_fill (info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, data_len
, urb
, cnt
);
1049 writel (OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
1052 case PIPE_INTERRUPT
:
1053 info
= usb_pipeout (urb
->pipe
)?
1054 TD_CC
| TD_DP_OUT
| toggle
: TD_CC
| TD_R
| TD_DP_IN
| toggle
;
1055 td_fill (info
, data
, data_len
, urb
, cnt
++);
1059 info
= TD_CC
| TD_DP_SETUP
| TD_T_DATA0
;
1060 td_fill (info
, ctrl
, 8, urb
, cnt
++);
1062 info
= usb_pipeout (urb
->pipe
)?
1063 TD_CC
| TD_R
| TD_DP_OUT
| TD_T_DATA1
: TD_CC
| TD_R
| TD_DP_IN
| TD_T_DATA1
;
1064 td_fill (info
, data
, data_len
, urb
, cnt
++);
1066 info
= usb_pipeout (urb
->pipe
)?
1067 TD_CC
| TD_DP_IN
| TD_T_DATA1
: TD_CC
| TD_DP_OUT
| TD_T_DATA1
;
1068 td_fill (info
, NULL
, 0, urb
, cnt
++);
1069 writel (OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
1072 case PIPE_ISOCHRONOUS
:
1073 for (cnt
= 0; cnt
< urb
->number_of_packets
; cnt
++) {
1074 td_fill (TD_CC
|TD_ISO
| ((urb
->start_frame
+ cnt
) & 0xffff),
1075 (__u8
*) data
+ urb
->iso_frame_desc
[cnt
].offset
,
1076 urb
->iso_frame_desc
[cnt
].length
, urb
, cnt
);
1080 if (urb_priv
->length
!= cnt
)
1081 dbg("TD LENGTH %d != CNT %d", urb_priv
->length
, cnt
);
1084 /*-------------------------------------------------------------------------*
1085 * Done List handling functions
1086 *-------------------------------------------------------------------------*/
1089 /* calculate the transfer length and update the urb */
1091 static void dl_transfer_length(td_t
* td
)
1093 __u32 tdINFO
, tdBE
, tdCBP
;
1095 urb_t
* urb
= td
->urb
;
1096 urb_priv_t
* urb_priv
= urb
->hcpriv
;
1100 tdINFO
= le32_to_cpup (&td
->hwINFO
);
1101 tdBE
= le32_to_cpup (&td
->hwBE
);
1102 tdCBP
= le32_to_cpup (&td
->hwCBP
);
1105 if (tdINFO
& TD_ISO
) {
1106 tdPSW
= le16_to_cpu (td
->hwPSW
[0]);
1107 cc
= (tdPSW
>> 12) & 0xF;
1109 if (usb_pipeout(urb
->pipe
)) {
1110 dlen
= urb
->iso_frame_desc
[td
->index
].length
;
1112 dlen
= tdPSW
& 0x3ff;
1114 urb
->actual_length
+= dlen
;
1115 urb
->iso_frame_desc
[td
->index
].actual_length
= dlen
;
1116 if (!(urb
->transfer_flags
& USB_DISABLE_SPD
) && (cc
== TD_DATAUNDERRUN
))
1119 urb
->iso_frame_desc
[td
->index
].status
= cc_to_error
[cc
];
1121 } else { /* BULK, INT, CONTROL DATA */
1122 if (!(usb_pipetype (urb
->pipe
) == PIPE_CONTROL
&&
1123 ((td
->index
== 0) || (td
->index
== urb_priv
->length
- 1)))) {
1126 urb
->actual_length
= bus_to_virt (tdBE
) - urb
->transfer_buffer
+ 1;
1128 urb
->actual_length
= bus_to_virt (tdCBP
) - urb
->transfer_buffer
;
1134 /*-------------------------------------------------------------------------*/
1136 /* replies to the request have to be on a FIFO basis so
1137 * we reverse the reversed done-list */
1139 static td_t
* dl_reverse_done_list (ohci_t
* ohci
)
1142 td_t
* td_rev
= NULL
;
1143 td_t
* td_list
= NULL
;
1144 urb_priv_t
* urb_priv
= NULL
;
1145 unsigned long flags
;
1147 spin_lock_irqsave (&usb_ed_lock
, flags
);
1149 td_list_hc
= le32_to_cpup (&ohci
->hcca
.done_head
) & 0xfffffff0;
1150 ohci
->hcca
.done_head
= 0;
1152 while (td_list_hc
) {
1153 td_list
= (td_t
*) bus_to_virt (td_list_hc
);
1155 if (TD_CC_GET (le32_to_cpup (&td_list
->hwINFO
))) {
1156 urb_priv
= (urb_priv_t
*) td_list
->urb
->hcpriv
;
1157 dbg(" USB-error/status: %x : %p",
1158 TD_CC_GET (le32_to_cpup (&td_list
->hwINFO
)), td_list
);
1159 if (td_list
->ed
->hwHeadP
& cpu_to_le32 (0x1)) {
1160 if (urb_priv
&& ((td_list
->index
+ 1) < urb_priv
->length
)) {
1161 td_list
->ed
->hwHeadP
=
1162 (urb_priv
->td
[urb_priv
->length
- 1]->hwNextTD
& cpu_to_le32 (0xfffffff0)) |
1163 (td_list
->ed
->hwHeadP
& cpu_to_le32 (0x2));
1164 urb_priv
->td_cnt
+= urb_priv
->length
- td_list
->index
- 1;
1166 td_list
->ed
->hwHeadP
&= cpu_to_le32 (0xfffffff2);
1170 td_list
->next_dl_td
= td_rev
;
1172 td_list_hc
= le32_to_cpup (&td_list
->hwNextTD
) & 0xfffffff0;
1174 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
1178 /*-------------------------------------------------------------------------*/
1180 /* there are some pending requests to remove
1181 * - some of the eds (if ed->state & ED_DEL (set by sohci_free_dev)
1182 * - some URBs/TDs if urb_priv->state == URB_DEL */
1184 static void dl_del_list (ohci_t
* ohci
, unsigned int frame
)
1186 unsigned long flags
;
1190 td_t
* td
= NULL
, * td_next
= NULL
, * tdHeadP
= NULL
, * tdTailP
;
1192 int ctrl
= 0, bulk
= 0;
1194 spin_lock_irqsave (&usb_ed_lock
, flags
);
1195 for (ed
= ohci
->ed_rm_list
[frame
]; ed
!= NULL
; ed
= ed
->ed_rm_list
) {
1197 tdTailP
= bus_to_virt (le32_to_cpup (&ed
->hwTailP
) & 0xfffffff0);
1198 tdHeadP
= bus_to_virt (le32_to_cpup (&ed
->hwHeadP
) & 0xfffffff0);
1199 edINFO
= le32_to_cpup (&ed
->hwINFO
);
1200 td_p
= &ed
->hwHeadP
;
1202 for (td
= tdHeadP
; td
!= tdTailP
; td
= td_next
) {
1203 urb_t
* urb
= td
->urb
;
1204 urb_priv_t
* urb_priv
= td
->urb
->hcpriv
;
1206 td_next
= bus_to_virt (le32_to_cpup (&td
->hwNextTD
) & 0xfffffff0);
1207 if ((urb_priv
->state
== URB_DEL
) || (ed
->state
& ED_DEL
)) {
1208 tdINFO
= le32_to_cpup (&td
->hwINFO
);
1209 if (TD_CC_GET (tdINFO
) < 0xE) dl_transfer_length (td
);
1210 *td_p
= td
->hwNextTD
| (*td_p
& cpu_to_le32 (0x3));
1211 if(++ (urb_priv
->td_cnt
) == urb_priv
->length
)
1213 if (urb
->transfer_flags
& USB_ASYNC_UNLINK
) {
1214 usb_dec_dev_use (urb
->dev
);
1215 urb
->status
= -ECONNRESET
;
1216 urb
->complete (urb
);
1218 wake_up (&op_wakeup
);
1221 td_p
= &td
->hwNextTD
;
1225 if (ed
->state
& ED_DEL
) { /* set by sohci_free_dev */
1226 struct ohci_device
* dev
= usb_to_ohci (ohci
->dev
[edINFO
& 0x7F]);
1227 OHCI_FREE (tdTailP
); /* free dummy td */
1228 ed
->hwINFO
= cpu_to_le32 (OHCI_ED_SKIP
);
1230 /* if all eds are removed wake up sohci_free_dev */
1232 wake_up (&op_wakeup
);
1235 ed
->state
&= ~ED_URB_DEL
;
1236 ed
->hwINFO
&= ~cpu_to_le32 (OHCI_ED_SKIP
);
1239 if ((ed
->type
& 3) == CTRL
) ctrl
|= 1;
1240 if ((ed
->type
& 3) == BULK
) bulk
|= 1;
1243 if (ctrl
) writel (0, &ohci
->regs
->ed_controlcurrent
); /* reset CTRL list */
1244 if (bulk
) writel (0, &ohci
->regs
->ed_bulkcurrent
); /* reset BULK list */
1245 if (!ohci
->ed_rm_list
[!frame
]) { /* enable CTRL and BULK lists */
1246 ohci
->hc_control
|= OHCI_CTRL_CLE
| OHCI_CTRL_BLE
;
1247 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1249 ohci
->ed_rm_list
[frame
] = NULL
;
1251 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
1256 /*-------------------------------------------------------------------------*/
1260 static void dl_done_list (ohci_t
* ohci
, td_t
* td_list
)
1262 td_t
* td_list_next
= NULL
;
1266 urb_priv_t
* urb_priv
;
1267 __u32 tdINFO
, edHeadP
, edTailP
;
1269 unsigned long flags
;
1272 td_list_next
= td_list
->next_dl_td
;
1275 urb_priv
= urb
->hcpriv
;
1276 tdINFO
= le32_to_cpup (&td_list
->hwINFO
);
1280 dl_transfer_length(td_list
);
1282 /* error code of transfer */
1283 cc
= TD_CC_GET (tdINFO
);
1284 if( cc
== TD_CC_STALL
) usb_endpoint_halt(urb
->dev
, usb_pipeendpoint(urb
->pipe
), usb_pipeout(urb
->pipe
));
1286 if (!(urb
->transfer_flags
& USB_DISABLE_SPD
) && (cc
== TD_DATAUNDERRUN
))
1288 if (++(urb_priv
->td_cnt
) == urb_priv
->length
) {
1289 if (urb_priv
->state
!= URB_DEL
&& !(ed
->state
& ED_DEL
) && ed
->state
!= ED_NEW
) {
1290 urb
->status
= cc_to_error
[cc
];
1291 sohci_return_urb (urb
);
1297 spin_lock_irqsave (&usb_ed_lock
, flags
);
1298 if (ed
->state
!= ED_NEW
) {
1299 edHeadP
= le32_to_cpup (&ed
->hwHeadP
) & 0xfffffff0;
1300 edTailP
= le32_to_cpup (&ed
->hwTailP
);
1302 if((edHeadP
== edTailP
) && (ed
->state
== ED_OPER
))
1303 ep_unlink (ohci
, ed
); /* unlink eds if they are not busy */
1306 spin_unlock_irqrestore (&usb_ed_lock
, flags
);
1308 td_list
= td_list_next
;
1315 /*-------------------------------------------------------------------------*
1317 *-------------------------------------------------------------------------*/
1319 /* Device descriptor */
1320 static __u8 root_hub_dev_des
[] =
1322 0x12, /* __u8 bLength; */
1323 0x01, /* __u8 bDescriptorType; Device */
1324 0x10, /* __u16 bcdUSB; v1.1 */
1326 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1327 0x00, /* __u8 bDeviceSubClass; */
1328 0x00, /* __u8 bDeviceProtocol; */
1329 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1330 0x00, /* __u16 idVendor; */
1332 0x00, /* __u16 idProduct; */
1334 0x00, /* __u16 bcdDevice; */
1336 0x00, /* __u8 iManufacturer; */
1337 0x02, /* __u8 iProduct; */
1338 0x01, /* __u8 iSerialNumber; */
1339 0x01 /* __u8 bNumConfigurations; */
1343 /* Configuration descriptor */
1344 static __u8 root_hub_config_des
[] =
1346 0x09, /* __u8 bLength; */
1347 0x02, /* __u8 bDescriptorType; Configuration */
1348 0x19, /* __u16 wTotalLength; */
1350 0x01, /* __u8 bNumInterfaces; */
1351 0x01, /* __u8 bConfigurationValue; */
1352 0x00, /* __u8 iConfiguration; */
1353 0x40, /* __u8 bmAttributes;
1354 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
1355 0x00, /* __u8 MaxPower; */
1358 0x09, /* __u8 if_bLength; */
1359 0x04, /* __u8 if_bDescriptorType; Interface */
1360 0x00, /* __u8 if_bInterfaceNumber; */
1361 0x00, /* __u8 if_bAlternateSetting; */
1362 0x01, /* __u8 if_bNumEndpoints; */
1363 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1364 0x00, /* __u8 if_bInterfaceSubClass; */
1365 0x00, /* __u8 if_bInterfaceProtocol; */
1366 0x00, /* __u8 if_iInterface; */
1369 0x07, /* __u8 ep_bLength; */
1370 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1371 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1372 0x03, /* __u8 ep_bmAttributes; Interrupt */
1373 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
1375 0xff /* __u8 ep_bInterval; 255 ms */
1378 /* Hub class-specific descriptor is constructed dynamically */
1381 /*-------------------------------------------------------------------------*/
1383 /* prepare Interrupt pipe data; HUB INTERRUPT ENDPOINT */
1385 static int rh_send_irq (ohci_t
* ohci
, void * rh_data
, int rh_len
)
1394 num_ports
= readl (&ohci
->regs
->roothub
.a
) & RH_A_NDP
;
1395 if (num_ports
> MAX_ROOT_PORTS
) {
1396 err ("bogus NDP=%d for OHCI %s", num_ports
,
1397 ohci
->ohci_dev
->slot_name
);
1398 err ("rereads as NDP=%d",
1399 readl (&ohci
->regs
->roothub
.a
) & RH_A_NDP
);
1400 /* retry later; "should not happen" */
1403 *(__u8
*) data
= (readl (&ohci
->regs
->roothub
.status
) & (RH_HS_LPSC
| RH_HS_OCIC
))
1405 ret
= *(__u8
*) data
;
1407 for ( i
= 0; i
< num_ports
; i
++) {
1408 *(__u8
*) (data
+ (i
+ 1) / 8) |=
1409 ((readl (&ohci
->regs
->roothub
.portstatus
[i
]) &
1410 (RH_PS_CSC
| RH_PS_PESC
| RH_PS_PSSC
| RH_PS_OCIC
| RH_PS_PRSC
))
1411 ? 1: 0) << ((i
+ 1) % 8);
1412 ret
+= *(__u8
*) (data
+ (i
+ 1) / 8);
1417 memcpy (rh_data
, data
, min (len
, min (rh_len
, sizeof(data
))));
1423 /*-------------------------------------------------------------------------*/
1425 /* Virtual Root Hub INTs are polled by this timer every "interval" ms */
1427 static void rh_int_timer_do (unsigned long ptr
)
1431 urb_t
* urb
= (urb_t
*) ptr
;
1432 ohci_t
* ohci
= urb
->dev
->bus
->hcpriv
;
1437 /* ignore timers firing during PM suspend, etc */
1438 if ((ohci
->hc_control
& OHCI_CTRL_HCFS
) != OHCI_USB_OPER
)
1442 len
= rh_send_irq (ohci
, urb
->transfer_buffer
, urb
->transfer_buffer_length
);
1444 urb
->actual_length
= len
;
1446 urb_print (urb
, "RET-t(rh)", usb_pipeout (urb
->pipe
));
1448 if (urb
->complete
) urb
->complete (urb
);
1451 rh_init_int_timer (urb
);
1454 /*-------------------------------------------------------------------------*/
1456 /* Root Hub INTs are polled by this timer */
1458 static int rh_init_int_timer (urb_t
* urb
)
1460 ohci_t
* ohci
= urb
->dev
->bus
->hcpriv
;
1462 ohci
->rh
.interval
= urb
->interval
;
1463 init_timer (&ohci
->rh
.rh_int_timer
);
1464 ohci
->rh
.rh_int_timer
.function
= rh_int_timer_do
;
1465 ohci
->rh
.rh_int_timer
.data
= (unsigned long) urb
;
1466 ohci
->rh
.rh_int_timer
.expires
=
1467 jiffies
+ (HZ
* (urb
->interval
< 30? 30: urb
->interval
)) / 1000;
1468 add_timer (&ohci
->rh
.rh_int_timer
);
1473 /*-------------------------------------------------------------------------*/
1475 #define OK(x) len = (x); break
1476 #define WR_RH_STAT(x) writel((x), &ohci->regs->roothub.status)
1477 #define WR_RH_PORTSTAT(x) writel((x), &ohci->regs->roothub.portstatus[wIndex-1])
1478 #define RD_RH_STAT readl(&ohci->regs->roothub.status)
1479 #define RD_RH_PORTSTAT readl(&ohci->regs->roothub.portstatus[wIndex-1])
1481 /* request to virtual root hub */
1483 static int rh_submit_urb (urb_t
* urb
)
1485 struct usb_device
* usb_dev
= urb
->dev
;
1486 ohci_t
* ohci
= usb_dev
->bus
->hcpriv
;
1487 unsigned int pipe
= urb
->pipe
;
1488 devrequest
* cmd
= (devrequest
*) urb
->setup_packet
;
1489 void * data
= urb
->transfer_buffer
;
1490 int leni
= urb
->transfer_buffer_length
;
1492 int status
= TD_CC_NOERROR
;
1495 __u8
* data_buf
= (__u8
*) datab
;
1502 if (usb_pipeint(pipe
)) {
1506 ohci
->rh
.interval
= urb
->interval
;
1507 rh_init_int_timer(urb
);
1508 urb
->status
= cc_to_error
[TD_CC_NOERROR
];
1513 bmRType_bReq
= cmd
->requesttype
| (cmd
->request
<< 8);
1514 wValue
= le16_to_cpu (cmd
->value
);
1515 wIndex
= le16_to_cpu (cmd
->index
);
1516 wLength
= le16_to_cpu (cmd
->length
);
1518 dbg ("rh_submit_urb, req = %d(%x) len=%d", bmRType_bReq
,
1519 bmRType_bReq
, wLength
);
1521 switch (bmRType_bReq
) {
1522 /* Request Destination:
1523 without flags: Device,
1524 RH_INTERFACE: interface,
1525 RH_ENDPOINT: endpoint,
1526 RH_CLASS means HUB here,
1527 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1531 *(__u16
*) data_buf
= cpu_to_le16 (1); OK (2);
1532 case RH_GET_STATUS
| RH_INTERFACE
:
1533 *(__u16
*) data_buf
= cpu_to_le16 (0); OK (2);
1534 case RH_GET_STATUS
| RH_ENDPOINT
:
1535 *(__u16
*) data_buf
= cpu_to_le16 (0); OK (2);
1536 case RH_GET_STATUS
| RH_CLASS
:
1537 *(__u32
*) data_buf
= cpu_to_le32 (
1538 RD_RH_STAT
& ~(RH_HS_CRWE
| RH_HS_DRWE
));
1540 case RH_GET_STATUS
| RH_OTHER
| RH_CLASS
:
1541 *(__u32
*) data_buf
= cpu_to_le32 (RD_RH_PORTSTAT
); OK (4);
1543 case RH_CLEAR_FEATURE
| RH_ENDPOINT
:
1545 case (RH_ENDPOINT_STALL
): OK (0);
1549 case RH_CLEAR_FEATURE
| RH_CLASS
:
1551 case RH_C_HUB_LOCAL_POWER
:
1553 case (RH_C_HUB_OVER_CURRENT
):
1554 WR_RH_STAT(RH_HS_OCIC
); OK (0);
1558 case RH_CLEAR_FEATURE
| RH_OTHER
| RH_CLASS
:
1560 case (RH_PORT_ENABLE
):
1561 WR_RH_PORTSTAT (RH_PS_CCS
); OK (0);
1562 case (RH_PORT_SUSPEND
):
1563 WR_RH_PORTSTAT (RH_PS_POCI
); OK (0);
1564 case (RH_PORT_POWER
):
1565 WR_RH_PORTSTAT (RH_PS_LSDA
); OK (0);
1566 case (RH_C_PORT_CONNECTION
):
1567 WR_RH_PORTSTAT (RH_PS_CSC
); OK (0);
1568 case (RH_C_PORT_ENABLE
):
1569 WR_RH_PORTSTAT (RH_PS_PESC
); OK (0);
1570 case (RH_C_PORT_SUSPEND
):
1571 WR_RH_PORTSTAT (RH_PS_PSSC
); OK (0);
1572 case (RH_C_PORT_OVER_CURRENT
):
1573 WR_RH_PORTSTAT (RH_PS_OCIC
); OK (0);
1574 case (RH_C_PORT_RESET
):
1575 WR_RH_PORTSTAT (RH_PS_PRSC
); OK (0);
1579 case RH_SET_FEATURE
| RH_OTHER
| RH_CLASS
:
1581 case (RH_PORT_SUSPEND
):
1582 WR_RH_PORTSTAT (RH_PS_PSS
); OK (0);
1583 case (RH_PORT_RESET
): /* BUG IN HUP CODE *********/
1584 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
1585 WR_RH_PORTSTAT (RH_PS_PRS
);
1587 case (RH_PORT_POWER
):
1588 WR_RH_PORTSTAT (RH_PS_PPS
); OK (0);
1589 case (RH_PORT_ENABLE
): /* BUG IN HUP CODE *********/
1590 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
1591 WR_RH_PORTSTAT (RH_PS_PES
);
1596 case RH_SET_ADDRESS
: ohci
->rh
.devnum
= wValue
; OK(0);
1598 case RH_GET_DESCRIPTOR
:
1599 switch ((wValue
& 0xff00) >> 8) {
1600 case (0x01): /* device descriptor */
1601 len
= min (leni
, min (sizeof (root_hub_dev_des
), wLength
));
1602 data_buf
= root_hub_dev_des
; OK(len
);
1603 case (0x02): /* configuration descriptor */
1604 len
= min (leni
, min (sizeof (root_hub_config_des
), wLength
));
1605 data_buf
= root_hub_config_des
; OK(len
);
1606 case (0x03): /* string descriptors */
1607 len
= usb_root_hub_string (wValue
& 0xff,
1608 (int)(long) ohci
->regs
, "OHCI",
1612 OK (min (leni
, len
));
1616 status
= TD_CC_STALL
;
1620 case RH_GET_DESCRIPTOR
| RH_CLASS
:
1622 __u32 temp
= readl (&ohci
->regs
->roothub
.a
);
1624 data_buf
[0] = 9; // min length;
1625 data_buf
[1] = 0x29;
1626 data_buf
[2] = temp
& RH_A_NDP
;
1628 if (temp
& RH_A_PSM
) /* per-port power switching? */
1629 data_buf
[3] |= 0x1;
1630 if (temp
& RH_A_NOCP
) /* no overcurrent reporting? */
1631 data_buf
[3] |= 0x10;
1632 else if (temp
& RH_A_OCPM
) /* per-port overcurrent reporting? */
1633 data_buf
[3] |= 0x8;
1636 data_buf
[5] = (temp
& RH_A_POTPGT
) >> 24;
1637 temp
= readl (&ohci
->regs
->roothub
.b
);
1638 data_buf
[7] = temp
& RH_B_DR
;
1639 if (data_buf
[2] < 7) {
1640 data_buf
[8] = 0xff;
1643 data_buf
[8] = (temp
& RH_B_DR
) >> 8;
1644 data_buf
[10] = data_buf
[9] = 0xff;
1647 len
= min (leni
, min (data_buf
[0], wLength
));
1651 case RH_GET_CONFIGURATION
: *(__u8
*) data_buf
= 0x01; OK (1);
1653 case RH_SET_CONFIGURATION
: WR_RH_STAT (0x10000); OK (0);
1656 dbg ("unsupported root hub command");
1657 status
= TD_CC_STALL
;
1661 ohci_dump_roothub (ohci
, 0);
1664 len
= min(len
, leni
);
1665 if (data
!= data_buf
)
1666 memcpy (data
, data_buf
, len
);
1667 urb
->actual_length
= len
;
1668 urb
->status
= cc_to_error
[status
];
1671 urb_print (urb
, "RET(rh)", usb_pipeout (urb
->pipe
));
1674 if (urb
->complete
) urb
->complete (urb
);
1678 /*-------------------------------------------------------------------------*/
1680 static int rh_unlink_urb (urb_t
* urb
)
1682 ohci_t
* ohci
= urb
->dev
->bus
->hcpriv
;
1684 if (ohci
->rh
.urb
== urb
) {
1686 del_timer (&ohci
->rh
.rh_int_timer
);
1691 /*-------------------------------------------------------------------------*
1693 *-------------------------------------------------------------------------*/
1695 /* reset the HC and BUS */
1697 static int hc_reset (ohci_t
* ohci
)
1700 int smm_timeout
= 50; /* 0,5 sec */
1702 if (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) { /* SMM owns the HC */
1703 writel (OHCI_OCR
, &ohci
->regs
->cmdstatus
); /* request ownership */
1704 dbg("USB HC TakeOver from SMM");
1705 while (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) {
1707 if (--smm_timeout
== 0) {
1708 err("USB HC TakeOver failed!");
1714 /* Disable HC interrupts */
1715 writel (OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
1717 dbg("USB HC reset_hc %s: ctrl = %x ;",
1718 ohci
->ohci_dev
->slot_name
,
1719 readl (&ohci
->regs
->control
));
1721 /* Reset USB (needed by some controllers) */
1722 writel (0, &ohci
->regs
->control
);
1724 /* HC Reset requires max 10 ms delay */
1725 writel (OHCI_HCR
, &ohci
->regs
->cmdstatus
);
1726 while ((readl (&ohci
->regs
->cmdstatus
) & OHCI_HCR
) != 0) {
1727 if (--timeout
== 0) {
1728 err("USB HC reset timed out!");
1737 /*-------------------------------------------------------------------------*/
1739 /* Start an OHCI controller, set the BUS operational
1741 * connect the virtual root hub */
1743 static int hc_start (ohci_t
* ohci
)
1746 unsigned int fminterval
;
1747 struct usb_device
* usb_dev
;
1748 struct ohci_device
* dev
;
1750 /* Tell the controller where the control and bulk lists are
1751 * The lists are empty now. */
1753 writel (0, &ohci
->regs
->ed_controlhead
);
1754 writel (0, &ohci
->regs
->ed_bulkhead
);
1756 writel (virt_to_bus (&ohci
->hcca
), &ohci
->regs
->hcca
); /* a reset clears this */
1758 fminterval
= 0x2edf;
1759 writel ((fminterval
* 9) / 10, &ohci
->regs
->periodicstart
);
1760 fminterval
|= ((((fminterval
- 210) * 6) / 7) << 16);
1761 writel (fminterval
, &ohci
->regs
->fminterval
);
1762 writel (0x628, &ohci
->regs
->lsthresh
);
1764 /* start controller operations */
1765 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
1766 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1768 /* Choose the interrupts we care about now, others later on demand */
1769 mask
= OHCI_INTR_MIE
| OHCI_INTR_UE
| OHCI_INTR_WDH
| OHCI_INTR_SO
;
1770 writel (mask
, &ohci
->regs
->intrenable
);
1771 writel (mask
, &ohci
->regs
->intrstatus
);
1774 writel ((readl(&ohci
->regs
->roothub
.a
) | RH_A_NPS
) & ~RH_A_PSM
,
1775 &ohci
->regs
->roothub
.a
);
1776 writel (RH_HS_LPSC
, &ohci
->regs
->roothub
.status
);
1777 // POTPGT delay is bits 24-31, in 2 ms units.
1778 mdelay ((readl(&ohci
->regs
->roothub
.a
) >> 23) & 0x1fe);
1779 #endif /* OHCI_USE_NPS */
1781 /* connect the virtual root hub */
1782 ohci
->rh
.devnum
= 0;
1783 usb_dev
= usb_alloc_dev (NULL
, ohci
->bus
);
1787 dev
= usb_to_ohci (usb_dev
);
1788 ohci
->bus
->root_hub
= usb_dev
;
1789 usb_connect (usb_dev
);
1790 if (usb_new_device (usb_dev
) != 0) {
1791 usb_free_dev (usb_dev
);
1798 /*-------------------------------------------------------------------------*/
1800 /* an interrupt happens */
1802 static void hc_interrupt (int irq
, void * __ohci
, struct pt_regs
* r
)
1804 ohci_t
* ohci
= __ohci
;
1805 struct ohci_regs
* regs
= ohci
->regs
;
1808 if ((ohci
->hcca
.done_head
!= 0) && !(le32_to_cpup (&ohci
->hcca
.done_head
) & 0x01)) {
1809 ints
= OHCI_INTR_WDH
;
1810 } else if ((ints
= (readl (®s
->intrstatus
) & readl (®s
->intrenable
))) == 0) {
1814 // dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca.frame_no));
1816 if (ints
& OHCI_INTR_UE
) {
1818 err ("OHCI Unrecoverable Error, controller %s disabled",
1819 ohci
->ohci_dev
->slot_name
);
1820 // e.g. due to PCI Master/Target Abort
1823 // FIXME: be optimistic, hope that bug won't repeat often.
1824 // Make some non-interrupt context restart the controller.
1825 // Count and limit the retries though; either hardware or
1826 // software errors can go forever...
1830 if (ints
& OHCI_INTR_WDH
) {
1831 writel (OHCI_INTR_WDH
, ®s
->intrdisable
);
1832 dl_done_list (ohci
, dl_reverse_done_list (ohci
));
1833 writel (OHCI_INTR_WDH
, ®s
->intrenable
);
1836 if (ints
& OHCI_INTR_SO
) {
1837 dbg("USB Schedule overrun");
1838 writel (OHCI_INTR_SO
, ®s
->intrenable
);
1841 if (ints
& OHCI_INTR_SF
) {
1842 unsigned int frame
= le16_to_cpu (ohci
->hcca
.frame_no
) & 1;
1843 writel (OHCI_INTR_SF
, ®s
->intrdisable
);
1844 if (ohci
->ed_rm_list
[!frame
] != NULL
) {
1845 dl_del_list (ohci
, !frame
);
1847 if (ohci
->ed_rm_list
[frame
] != NULL
)
1848 writel (OHCI_INTR_SF
, ®s
->intrenable
);
1850 writel (ints
, ®s
->intrstatus
);
1851 writel (OHCI_INTR_MIE
, ®s
->intrenable
);
1854 /*-------------------------------------------------------------------------*/
1856 /* reinitialize after controller reset */
1858 static void hc_reinit_ohci (ohci_t
*ohci
)
1862 /* for load balancing of the interrupt branches */
1863 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->ohci_int_load
[i
] = 0;
1864 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->hcca
.int_table
[i
] = 0;
1866 ohci
->ed_rm_list
[0] = NULL
;
1867 ohci
->ed_rm_list
[1] = NULL
;
1869 /* end of control and bulk lists */
1870 ohci
->ed_isotail
= NULL
;
1871 ohci
->ed_controltail
= NULL
;
1872 ohci
->ed_bulktail
= NULL
;
1877 static ohci_t
* hc_alloc_ohci (void * mem_base
)
1880 struct usb_bus
* bus
;
1882 ohci
= (ohci_t
*) __get_free_pages (GFP_KERNEL
, 1);
1886 memset (ohci
, 0, sizeof (ohci_t
));
1889 ohci
->regs
= mem_base
;
1891 bus
= usb_alloc_bus (&sohci_device_operations
);
1893 free_pages ((unsigned long) ohci
, 1);
1898 bus
->hcpriv
= (void *) ohci
;
1904 /*-------------------------------------------------------------------------*/
1906 /* De-allocate all resources.. */
1908 static void hc_release_ohci (ohci_t
* ohci
)
1910 dbg ("USB HC release ohci %s", ohci
->ohci_dev
->slot_name
);
1912 /* disconnect all devices */
1913 if (ohci
->bus
->root_hub
)
1914 usb_disconnect (&ohci
->bus
->root_hub
);
1916 if (!ohci
->disabled
)
1919 if (ohci
->irq
>= 0) {
1920 free_irq (ohci
->irq
, ohci
);
1923 ohci
->ohci_dev
->driver_data
= 0;
1925 usb_deregister_bus (ohci
->bus
);
1926 usb_free_bus (ohci
->bus
);
1928 /* unmap the IO address space */
1929 iounmap (ohci
->regs
);
1931 free_pages ((unsigned long) ohci
, 1);
1934 /*-------------------------------------------------------------------------*/
1936 /* Increment the module usage count, start the control thread and
1937 * return success. */
1939 static int hc_found_ohci (struct pci_dev
*dev
, int irq
, void * mem_base
)
1942 char buf
[8], *bufp
= buf
;
1945 sprintf(buf
, "%d", irq
);
1947 bufp
= __irq_itoa(irq
);
1949 printk(KERN_INFO __FILE__
": USB OHCI at membase 0x%lx, IRQ %s\n",
1950 (unsigned long) mem_base
, bufp
);
1951 printk(KERN_INFO __FILE__
": pci slot %s, %s\n", dev
->slot_name
, dev
->name
);
1953 ohci
= hc_alloc_ohci (mem_base
);
1958 ohci
->ohci_dev
= dev
;
1959 dev
->driver_data
= ohci
;
1960 INIT_LIST_HEAD (&ohci
->ohci_hcd_list
);
1961 list_add (&ohci
->ohci_hcd_list
, &ohci_hcd_list
);
1963 if (hc_reset (ohci
) < 0) {
1964 hc_release_ohci (ohci
);
1968 writel (ohci
->hc_control
= OHCI_USB_RESET
, &ohci
->regs
->control
);
1970 usb_register_bus (ohci
->bus
);
1972 if (request_irq (irq
, hc_interrupt
, SA_SHIRQ
, "usb-ohci", ohci
) == 0) {
1973 struct pm_dev
*pmdev
;
1978 pmdev
= pm_register (PM_PCI_DEV
,
1985 ohci_dump (ohci
, 1);
1989 err("request interrupt %d failed", irq
);
1990 hc_release_ohci (ohci
);
1994 /*-------------------------------------------------------------------------*/
1996 static int hc_start_ohci (struct pci_dev
* dev
)
1998 unsigned long mem_base
;
2000 if (pci_enable_device(dev
) < 0)
2003 pci_set_master (dev
);
2004 mem_base
= pci_resource_start(dev
, 0);
2005 mem_base
= (unsigned long) ioremap_nocache (mem_base
, 4096);
2008 err("Error mapping OHCI memory");
2011 return hc_found_ohci (dev
, dev
->irq
, (void *) mem_base
);
2014 /*-------------------------------------------------------------------------*/
2016 #ifdef CONFIG_PMAC_PBOOK
2018 /* On Powerbooks, put the controller into suspend mode when going
2019 * to sleep, and do a resume when waking up. */
2021 static int ohci_sleep_notify (struct pmu_sleep_notifier
* self
, int when
)
2023 struct list_head
* ohci_l
;
2026 for (ohci_l
= ohci_hcd_list
.next
; ohci_l
!= &ohci_hcd_list
; ohci_l
= ohci_l
->next
) {
2027 ohci
= list_entry (ohci_l
, ohci_t
, ohci_hcd_list
);
2030 case PBOOK_SLEEP_NOW
:
2031 disable_irq (ohci
->irq
);
2032 writel (ohci
->hc_control
= OHCI_USB_SUSPEND
, &ohci
->regs
->control
);
2036 writel (ohci
->hc_control
= OHCI_USB_RESUME
, &ohci
->regs
->control
);
2038 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
2039 writel (ohci
->hc_control
, &ohci
->regs
->control
);
2040 enable_irq (ohci
->irq
);
2044 return PBOOK_SLEEP_OK
;
2047 static struct pmu_sleep_notifier ohci_sleep_notifier
= {
2048 ohci_sleep_notify
, SLEEP_LEVEL_MISC
,
2050 #endif /* CONFIG_PMAC_PBOOK */
2052 /*-------------------------------------------------------------------------*/
2054 static int handle_pm_event (struct pm_dev
*dev
, pm_request_t rqst
, void *data
)
2056 ohci_t
* ohci
= (ohci_t
*) dev
->data
;
2062 /* act as if usb suspend can always be used */
2063 dbg("USB suspend: %s", ohci
->ohci_dev
->slot_name
);
2064 ohci
->hc_control
= OHCI_USB_SUSPEND
;
2065 writel (ohci
->hc_control
, &ohci
->regs
->control
);
2070 /* did we suspend, or were we powered off? */
2071 ohci
->hc_control
= readl (&ohci
->regs
->control
);
2072 temp
= ohci
->hc_control
& OHCI_CTRL_HCFS
;
2075 case OHCI_USB_RESET
: // lost power
2076 dbg("USB reset: %s", ohci
->ohci_dev
->slot_name
);
2078 if (ohci
->bus
->root_hub
)
2079 usb_disconnect (&ohci
->bus
->root_hub
);
2080 hc_reinit_ohci (ohci
);
2081 if ((temp
= hc_reset (ohci
)) < 0
2082 || (temp
= hc_start (ohci
)) < 0) {
2084 err ("can't restart %s, %d",
2085 ohci
->ohci_dev
->slot_name
,
2091 case OHCI_USB_SUSPEND
: // host wakeup
2092 case OHCI_USB_RESUME
: // remote wakeup
2093 dbg("USB resume: %s", ohci
->ohci_dev
->slot_name
);
2094 ohci
->hc_control
= OHCI_USB_RESUME
;
2095 writel (ohci
->hc_control
, &ohci
->regs
->control
);
2098 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
2099 writel (ohci
->hc_control
, &ohci
->regs
->control
);
2103 warn ("odd PM_RESUME");
2111 /*-------------------------------------------------------------------------*/
2113 #define PCI_CLASS_SERIAL_USB_OHCI 0x0C0310
2115 int ohci_hcd_init (void)
2118 struct pci_dev
* dev
= NULL
;
2120 while ((dev
= pci_find_class (PCI_CLASS_SERIAL_USB_OHCI
, dev
))) {
2121 if (hc_start_ohci(dev
) >= 0) ret
= 0;
2124 #ifdef CONFIG_PMAC_PBOOK
2125 pmu_register_sleep_notifier (&ohci_sleep_notifier
);
2130 /*-------------------------------------------------------------------------*/
2133 int init_module (void)
2135 return ohci_hcd_init ();
2138 /*-------------------------------------------------------------------------*/
2140 void cleanup_module (void)
2144 pm_unregister_all (handle_pm_event
);
2146 #ifdef CONFIG_PMAC_PBOOK
2147 pmu_unregister_sleep_notifier (&ohci_sleep_notifier
);
2150 while (!list_empty (&ohci_hcd_list
)) {
2151 ohci
= list_entry (ohci_hcd_list
.next
, ohci_t
, ohci_hcd_list
);
2152 list_del (&ohci
->ohci_hcd_list
);
2153 INIT_LIST_HEAD (&ohci
->ohci_hcd_list
);
2154 hc_release_ohci (ohci
);