2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * The OHCI HCD layer is a simple but nearly complete implementation of what the
7 * USB people would call a HCD for the OHCI.
8 * (ISO comming soon, Bulk disabled, INT u. CTRL transfers enabled)
9 * The layer on top of it, is for interfacing to the alternate-usb device-drivers.
11 * [ This is based on Linus' UHCI code and gregs OHCI fragments (0.03c source tree). ]
12 * [ Open Host Controller Interface driver for USB. ]
13 * [ (C) Copyright 1999 Linus Torvalds (uhci.c) ]
14 * [ (C) Copyright 1999 Gregory P. Smith <greg@electricrain.com> ]
15 * [ $Log: ohci.c,v $ ]
16 * [ Revision 1.1 1999/04/05 08:32:30 greg ]
19 * v2.1 1999/05/09 ep_addr correction, code clean up
21 * virtual root hub is now an option,
22 * memory allocation based on kmalloc and kfree now, Bus error handling,
23 * INT and CTRL transfers enabled, Bulk included but disabled, ISO needs completion
25 * from Linus Torvalds (uhci.c) (APM not tested; hub, usb_device, bus and related stuff)
26 * from Greg Smith (ohci.c) (reset controller handling, hub)
28 * v1.0 1999/04/27 initial release
32 /* #define OHCI_DBG */ /* printk some debug information */
35 #include <linux/config.h>
36 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/kernel.h>
39 #include <linux/delay.h>
40 #include <linux/ioport.h>
41 #include <linux/sched.h>
42 #include <linux/malloc.h>
43 #include <linux/smp_lock.h>
44 #include <linux/errno.h>
45 #include <linux/timer.h>
47 #include <asm/spinlock.h>
50 #include <asm/system.h>
59 #include <linux/apm_bios.h>
60 static int handle_apm_event(apm_event_t event
);
61 static int apm_resume
= 0;
65 static DECLARE_WAIT_QUEUE_HEAD(bulk_wakeup
);
66 static DECLARE_WAIT_QUEUE_HEAD(control_wakeup
);
67 static DECLARE_WAIT_QUEUE_HEAD(root_hub
);
69 static __u8 cc_to_status
[16] = { /* mapping of the OHCI CC to the UHCI status codes; first guess */
70 /* Activ, Stalled, Data Buffer Err, Babble Detected : NAK recvd, CRC/Timeout, Bitstuff, reservd */
76 /* DevNotResp */ 0x04,
83 /* BufferOver */ 0x20,
85 /* Not Access */ 0x80,
91 **** Interface functions
92 ***********************************************/
94 static int sohci_int_handler(void * ohci_in
, unsigned int ep_addr
, int ctrl_len
, void * ctrl
, void * data
, int data_len
, int status
, __OHCI_BAG lw0
, __OHCI_BAG lw1
)
97 struct ohci
* ohci
= ohci_in
;
98 usb_device_irq handler
=(void *) lw0
;
99 void *dev_id
= (void *) lw1
;
102 OHCI_DEBUG({ int i
; printk("USB HC IRQ <<<: %x: data(%d):", ep_addr
, data_len
);)
103 OHCI_DEBUG( for(i
=0; i
< data_len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
104 OHCI_DEBUG( printk(" ret_status: %x\n", status
); })
106 ret
= handler(cc_to_status
[status
& 0xf], data
, dev_id
);
107 if(ret
== 0) return 0; /* 0 .. do not requeue */
108 if(status
> 0) return -1; /* error occured do not requeue ? */
109 ohci_trans_req(ohci
, ep_addr
, 0, NULL
, data
, 8, (__OHCI_BAG
) handler
, (__OHCI_BAG
) dev_id
); /* requeue int request */
113 static int sohci_ctrl_handler(void * ohci_in
, unsigned int ep_addr
, int ctrl_len
, void * ctrl
, void * data
, int data_len
, int status
, __OHCI_BAG lw0
, __OHCI_BAG lw
)
115 *(int * )lw0
= status
;
116 wake_up(&control_wakeup
);
118 OHCI_DEBUG( { int i
; printk("USB HC CTRL<<<: %x: ctrl(%d):", ep_addr
, ctrl_len
);)
119 OHCI_DEBUG( for(i
=0; i
< 8; i
++ ) printk(" %02x", ((__u8
*) ctrl
)[i
]);)
120 OHCI_DEBUG( printk(" data(%d):", data_len
);)
121 OHCI_DEBUG( for(i
=0; i
< data_len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
122 OHCI_DEBUG( printk(" ret_status: %x\n", status
); })
126 static int sohci_bulk_handler(void * ohci_in
, unsigned int ep_addr
, int ctrl_len
, void * ctrl
, void * data
, int data_len
, int status
, __OHCI_BAG lw0
, __OHCI_BAG lw
)
128 *(int * )lw0
= status
;
129 wake_up(&bulk_wakeup
);
131 OHCI_DEBUG( { int i
; printk("USB HC BULK<<<: %x:", ep_addr
, ctrl_len
);)
132 OHCI_DEBUG( printk(" data(%d):", data_len
);)
133 OHCI_DEBUG( for(i
=0; i
< data_len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
134 OHCI_DEBUG( printk(" ret_status: %x\n", status
); })
138 static int sohci_request_irq(struct usb_device
*usb_dev
, unsigned int pipe
, usb_device_irq handler
, int period
, void *dev_id
)
140 struct ohci
* ohci
= usb_dev
->bus
->hcpriv
;
141 union ep_addr_ ep_addr
;
144 ep_addr
.bep
.ep
= ((pipe
>> 15) & 0x0f) /* endpoint address */
145 | (pipe
& 0x80) /* direction */
146 | (1 << 5); /* type = int*/
147 ep_addr
.bep
.fa
= ((pipe
>> 8) & 0x7f); /* device address */
149 OHCI_DEBUG( printk("USB HC IRQ >>>: %x: every %d ms\n", ep_addr
.iep
, period
);)
151 usb_ohci_add_ep(ohci
, ep_addr
.iep
, period
, 1, sohci_int_handler
, 1 << ((pipe
& 0x03) + 3) , (pipe
>> 26) & 0x01);
153 ohci_trans_req(ohci
, ep_addr
.iep
, 0, NULL
, ((struct ohci_device
*) usb_dev
->hcpriv
)->data
, 8, (__OHCI_BAG
) handler
, (__OHCI_BAG
) dev_id
);
158 static int sohci_control_msg(struct usb_device
*usb_dev
, unsigned int pipe
, void *cmd
, void *data
, int len
)
160 DECLARE_WAITQUEUE(wait
, current
);
161 struct ohci
* ohci
= usb_dev
->bus
->hcpriv
;
163 union ep_addr_ ep_addr
;
166 ep_addr
.bep
.ep
= ((pipe
>> 15) & 0x0f) /* endpoint address */
167 | (pipe
& 0x80) /* direction */
168 | (1 << 6); /* type = ctrl*/
169 ep_addr
.bep
.fa
= ((pipe
>> 8) & 0x7f); /* device address */
171 status
= 0xf; /* CC not Accessed */
172 OHCI_DEBUG( { int i
; printk("USB HC CTRL>>>: %x: ctrl(%d):", ep_addr
.iep
, 8);)
173 OHCI_DEBUG( for(i
=0; i
< 8; i
++ ) printk(" %02x", ((__u8
*) cmd
)[i
]);)
174 OHCI_DEBUG( printk(" data(%d):", len
);)
175 OHCI_DEBUG( for(i
=0; i
< len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
176 OHCI_DEBUG( printk("\n"); })
178 usb_ohci_add_ep(ohci
, ep_addr
.iep
, 0, 1, sohci_ctrl_handler
, 1 << ((pipe
& 0x03) + 3) , (pipe
>> 26) & 0x01);
180 current
->state
= TASK_UNINTERRUPTIBLE
;
181 add_wait_queue(&control_wakeup
, &wait
);
183 ohci_trans_req(ohci
, ep_addr
.iep
, 8, cmd
, data
, len
, (__OHCI_BAG
) &status
, 0);
185 schedule_timeout(HZ
/10);
187 remove_wait_queue(&control_wakeup
, &wait
);
189 OHCI_DEBUG(printk("USB HC status::: %x\n", cc_to_status
[status
& 0x0f]);)
191 return cc_to_status
[status
& 0x0f];
194 static int sohci_bulk_msg(struct usb_device
*usb_dev
, unsigned int pipe
, void *data
, int len
)
196 DECLARE_WAITQUEUE(wait
, current
);
197 struct ohci
* ohci
= usb_dev
->bus
->hcpriv
;
199 union ep_addr_ ep_addr
;
202 ep_addr
.bep
.ep
= ((pipe
>> 15) & 0x0f) /* endpoint address */
203 | (pipe
& 0x80) /* direction */
204 | (11 << 5); /* type = bulk*/
205 ep_addr
.bep
.fa
= ((pipe
>> 8) & 0x7f); /* device address */
207 status
= 0xf; /* CC not Accessed */
208 OHCI_DEBUG( { int i
; printk("USB HC BULK>>>: %x:", ep_addr
.iep
);)
209 OHCI_DEBUG( printk(" data(%d):", len
);)
210 OHCI_DEBUG( for(i
=0; i
< len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
211 OHCI_DEBUG( printk("\n"); })
213 usb_ohci_add_ep(ohci
, ep_addr
.iep
, 0, 1, sohci_bulk_handler
, 1 << ((pipe
& 0x03) + 3) , (pipe
>> 26) & 0x01);
215 current
->state
= TASK_UNINTERRUPTIBLE
;
216 add_wait_queue(&bulk_wakeup
, &wait
);
218 ohci_trans_req(ohci
, ep_addr
.iep
, 0, NULL
, data
, len
, (__OHCI_BAG
) &status
, 0);
220 schedule_timeout(HZ
/10);
222 remove_wait_queue(&bulk_wakeup
, &wait
);
224 OHCI_DEBUG(printk("USB HC status::: %x\n", cc_to_status
[status
& 0x0f]);)
226 return cc_to_status
[status
& 0x0f];
229 static int sohci_usb_deallocate(struct usb_device
*usb_dev
) {
230 struct ohci_device
*dev
= usb_to_ohci(usb_dev
);
231 union ep_addr_ ep_addr
;
235 OHCI_DEBUG(printk("USB HC dealloc %x\n", usb_dev
->devnum
);)
239 if(usb_dev
->devnum
>=0) {
240 ep_addr
.bep
.fa
= usb_dev
->devnum
;
241 usb_ohci_rm_function(((struct ohci_device
*)usb_dev
->hcpriv
)->ohci
, ep_addr
.iep
);
250 static struct usb_device
*sohci_usb_allocate(struct usb_device
*parent
) {
252 struct usb_device
*usb_dev
;
253 struct ohci_device
*dev
;
256 USB_ALLOC(usb_dev
, sizeof(*usb_dev
));
260 memset(usb_dev
, 0, sizeof(*usb_dev
));
262 USB_ALLOC(dev
, sizeof(*dev
));
268 /* Initialize "dev" */
269 memset(dev
, 0, sizeof(*dev
));
271 usb_dev
->hcpriv
= dev
;
274 usb_dev
->parent
= parent
;
277 usb_dev
->bus
= parent
->bus
;
278 dev
->ohci
= usb_to_ohci(parent
)->ohci
;
284 struct usb_operations sohci_device_operations
= {
286 sohci_usb_deallocate
,
294 *** ED handling functions
295 ************************************/
300 * search for the right place to insert an interrupt ed into the int tree
301 * do some load ballancing
304 static int usb_ohci_int_ballance(struct ohci
* ohci
, int interval
, int load
) {
308 j
= 0; /* search for the least loaded interrupt endpoint branch of all 32 branches */
309 for(i
=0; i
< 32; i
++) if(ohci
->ohci_int_load
[j
] > ohci
->ohci_int_load
[i
]) j
=i
;
311 if(interval
< 1) interval
= 1;
312 if(interval
> 32) interval
= 32;
313 for(i
= 0; ((interval
>> i
) > 1 ); interval
&= (0xfffe << i
++ )); /* interval = 2^int(ld(interval)) */
316 for(i
=j
%interval
; i
< 32; i
+=interval
) ohci
->ohci_int_load
[i
] += load
;
317 j
= interval
+ (j
% interval
);
319 OHCI_DEBUG(printk("USB HC new int ed on pos : %x \n",j
);)
324 /* get the ed from the endpoint / device adress */
326 struct usb_ohci_ed
* ohci_find_ep(struct ohci
*ohci
, unsigned int ep_addr_in
) {
328 union ep_addr_ ep_addr
;
329 struct usb_ohci_ed
*tmp
;
333 ep_addr
.iep
= ep_addr_in
;
336 if(ep_addr
.bep
.fa
== ohci
->root_hub_funct_addr
) {
337 if((ep_addr
.bep
.ep
& 0x0f) == 0)
338 return &ohci
->ed_rh_ep0
; /* root hub ep0 */
340 return &ohci
->ed_rh_epi
; /* root hub int ep */
344 tmp
= ohci
->ed_func_ep0
[ep_addr
.bep
.fa
];
345 mask
= ((((ep_addr
.bep
.ep
>> 5) & 0x03)==2)?0x7f:0xff);
346 ep_addr
.bep
.ep
&= mask
; /* mask out direction of ctrl ep */
348 while (tmp
!= NULL
) {
349 if (tmp
->ep_addr
.iep
== ep_addr
.iep
)
356 spinlock_t usb_ed_lock
= SPIN_LOCK_UNLOCKED
;
357 /* add a new endpoint ep_addr */
358 struct usb_ohci_ed
*usb_ohci_add_ep(struct ohci
* ohci
, unsigned int ep_addr_in
, int interval
, int load
, f_handler handler
, int ep_size
, int speed
) {
360 struct usb_ohci_ed
* ed
;
361 struct usb_ohci_td
* td
;
362 union ep_addr_ ep_addr
;
367 struct usb_ohci_ed
*tmp
;
369 ep_addr
.iep
= ep_addr_in
;
370 ep_addr
.bep
.ep
&= ((((ep_addr
.bep
.ep
>> 5) & 0x03)==2)?0x7f:0xff); /* mask out direction of ctrl ep */
372 spin_lock(&usb_ed_lock
);
374 tmp
= ohci_find_ep(ohci
, ep_addr
.iep
);
378 if(ep_addr
.bep
.fa
== ohci
->root_hub_funct_addr
) {
379 if((ep_addr
.bep
.ep
& 0x0f) != 0) { /* root hub int ep */
380 ohci
->ed_rh_epi
.handler
= handler
;
381 ohci_init_rh_int_timer(ohci
, interval
);
383 else { /* root hub ep0 */
384 ohci
->ed_rh_ep0
.handler
= handler
;
392 tmp
->hw
.info
= ep_addr
.bep
.fa
| ((ep_addr
.bep
.ep
& 0xf) <<7)
394 | (((ep_addr
.bep
.ep
& 0x60) == 0)? 0x8000 : 0)
398 tmp
->handler
= handler
;
400 spin_unlock(&usb_ed_lock
);
401 return tmp
; /* ed already in use */
405 OHCI_ALLOC(td
, sizeof(td
)); /* dummy td; end of td list for ed */
406 OHCI_ALLOC(ed
, sizeof(ed
));
409 ed
->hw
.tail_td
= virt_to_bus(&td
->hw
);
410 ed
->hw
.head_td
= ed
->hw
.tail_td
;
411 ed
->hw
.info
= ep_addr
.bep
.fa
| ((ep_addr
.bep
.ep
& 0xf) <<7)
412 /* | ((ep_addr.bep.port & 0x80)? 0x1000 : 0x0800 ) */
413 | (((ep_addr
.bep
.ep
& 0x60) == 0)? 0x8000 : 0)
417 ed
->handler
= handler
;
419 switch((ep_addr
.bep
.ep
>> 5) & 0x03) {
422 if(ohci
->ed_controltail
== NULL
) {
423 writel(virt_to_bus(&ed
->hw
), &ohci
->regs
->ed_controlhead
);
426 ohci
->ed_controltail
->hw
.next_ed
= virt_to_bus(&ed
->hw
);
428 ed
->ed_prev
= ohci
->ed_controltail
;
429 ohci
->ed_controltail
= ed
;
433 if(ohci
->ed_bulktail
== NULL
) {
434 writel(virt_to_bus(&ed
->hw
), &ohci
->regs
->ed_bulkhead
);
437 ohci
->ed_bulktail
->hw
.next_ed
= virt_to_bus(&ed
->hw
);
439 ed
->ed_prev
= ohci
->ed_bulktail
;
440 ohci
->ed_bulktail
= ed
;
443 int_junk
= usb_ohci_int_ballance(ohci
, interval
, load
);
444 ed
->hw
.next_ed
= ohci
->hc_area
->ed
[int_junk
].next_ed
;
445 ohci
->hc_area
->ed
[int_junk
].next_ed
= virt_to_bus(&ed
->hw
);
446 ed
->ed_prev
= (struct usb_ohci_ed
*) &ohci
->hc_area
->ed
[int_junk
];
450 ohci
->ed_isotail
->hw
.next_ed
= virt_to_bus(&ed
->hw
);
451 ed
->ed_prev
= ohci
->ed_isotail
;
452 ohci
->ed_isotail
= ed
;
455 ed
->ep_addr
= ep_addr
;
457 /* Add it to the "hash"-table of known endpoint descriptors */
459 ed
->ed_list
= ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
];
460 ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
] = ed
;
462 spin_unlock(&usb_ed_lock
);
464 OHCI_DEBUG(printk("USB HC new ed %x: %x :", ep_addr
.iep
, (unsigned int ) ed
); )
465 OHCI_DEBUG({ int i
; for( i
= 0; i
<8 ;i
++) printk(" %4x", ((unsigned int *) ed
)[i
]) ; printk("\n"); }; )
470 * Request the removal of an endpoint
472 * put the ep on the rm_list and request a stop of the bulk or ctrl list
473 * real removal is done at the next start of frame hardware interrupt
475 int usb_ohci_rm_ep(struct ohci
* ohci
, struct usb_ohci_ed
*ed
)
478 struct usb_ohci_ed
*tmp
;
480 OHCI_DEBUG(printk("USB HC remove ed %x: %x :\n", ed
->ep_addr
.iep
, (unsigned int ) ed
); )
482 spin_lock_irqsave(&usb_ed_lock
, flags
);
484 tmp
= ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
];
486 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
491 ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
] = ed
->ed_list
;
494 while (tmp
->ed_list
!= ed
) {
495 if (tmp
->ed_list
== NULL
) {
496 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
501 tmp
->ed_list
= ed
->ed_list
;
503 ed
->ed_list
= ohci
->ed_rm_list
;
504 ohci
->ed_rm_list
= ed
;
505 ed
->hw
.info
|= OHCI_ED_SKIP
;
507 switch((ed
->ep_addr
.bep
.ep
>> 5) & 0x03) {
509 writel_mask(~(0x01<<4), &ohci
->regs
->control
); /* stop CTRL list */
512 writel_mask(~(0x01<<5), &ohci
->regs
->control
); /* stop BULK list */
517 writel( OHCI_INTR_SF
, &ohci
->regs
->intrenable
); /* enable sof interrupt */
519 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
524 /* we have requested to stop the bulk or CTRL list,
525 * now we can remove the eds on the rm_list */
527 static int ohci_rm_eds(struct ohci
* ohci
) {
530 struct usb_ohci_ed
*ed
;
531 struct usb_ohci_ed
*ed_tmp
;
532 struct usb_ohci_td
*td
;
536 spin_lock_irqsave(&usb_ed_lock
, flags
);
538 ed
= ohci
->ed_rm_list
;
542 switch((ed
->ep_addr
.bep
.ep
>> 5) & 0x03) {
544 if(ed
->ed_prev
== NULL
) {
545 writel(ed
->hw
.next_ed
, &ohci
->regs
->ed_controlhead
);
548 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
550 if(ohci
->ed_controltail
== ed
) {
551 ohci
->ed_controltail
= ed
->ed_prev
;
555 if(ed
->ed_prev
== NULL
) {
556 writel(ed
->hw
.next_ed
, &ohci
->regs
->ed_bulkhead
);
559 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
561 if(ohci
->ed_bulktail
== ed
) {
562 ohci
->ed_bulktail
= ed
->ed_prev
;
566 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
569 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
570 if(ohci
->ed_isotail
== ed
) {
571 ohci
->ed_isotail
= ed
->ed_prev
;
576 if(ed
->hw
.next_ed
!= 0) ((struct usb_ohci_ed
*) bus_to_virt(ed
->hw
.next_ed
))->ed_prev
= ed
->ed_prev
;
579 /* tds directly connected to ed */
581 td_hw
= ed
->hw
.head_td
& 0xfffffff0;
583 td
= bus_to_virt(td_hw
);
585 td_hw
= td
->hw
.next_td
;
586 OHCI_FREE(td
); /* free pending tds */
587 if(td_hw_tmp
== ed
->hw
.tail_td
) break;
591 /* mark TDs on the hc done list (if there are any) */
592 td_hw
= readl(&ohci
->regs
->donehead
) & 0xfffffff0;
594 td
= bus_to_virt(td_hw
);
595 td_hw
= td
->hw
.next_td
;
596 if(td
->ep
== ed
) td
->ep
= 0;
599 /* mark TDs on the hcca done list (if there are any) */
600 td_hw
= ohci
->hc_area
->hcca
.done_head
& 0xfffffff0 ;
603 td
= bus_to_virt(td_hw
);
604 td_hw
= td
->hw
.next_td
;
605 if(td
->ep
== ed
) td
->ep
= 0;
610 OHCI_FREE(ed_tmp
); /* free ed */
612 writel(0, &ohci
->regs
->ed_controlcurrent
); /* reset CTRL list */
613 writel(0, &ohci
->regs
->ed_bulkcurrent
); /* reset BULK list */
614 writel_set((0x03<<4), &ohci
->regs
->control
); /* start CTRL u. (BULK list) */
616 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
618 ohci
->ed_rm_list
= NULL
;
619 OHCI_DEBUG(printk("USB HC after rm ed control: %4x intrstat: %4x intrenable: %4x\n", readl(&ohci
->regs
->control
),readl(&ohci
->regs
->intrstatus
),readl(&ohci
->regs
->intrenable
));)
625 /* remove all endpoints of a function (device) */
626 int usb_ohci_rm_function( struct ohci
* ohci
, unsigned int ep_addr_in
)
628 struct usb_ohci_ed
*ed
;
629 struct usb_ohci_ed
*tmp
;
630 union ep_addr_ ep_addr
;
634 ep_addr
.iep
= ep_addr_in
;
636 for(ed
= ohci
->ed_func_ep0
[ep_addr
.bep
.fa
]; ed
!= NULL
;) {
639 usb_ohci_rm_ep(ohci
, tmp
);
652 *** TD handling functions
653 ************************************/
656 #define FILL_TD(TD_PT, HANDLER, INFO, DATA, LEN, LW0, LW1) \
658 td_pt1 = (struct usb_ohci_td *) bus_to_virt(usb_ep->hw.tail_td); \
659 td_pt1->ep = usb_ep; \
660 td_pt1->handler = (HANDLER); \
661 td_pt1->buffer_start = (DATA); \
662 td_pt1->lw0 = (LW0); \
663 td_pt1->lw1 = (LW1); \
664 td_pt1->hw.info = (INFO); \
665 td_pt1->hw.cur_buf = virt_to_bus(DATA); \
666 td_pt1->hw.buf_end = td_pt1->hw.cur_buf + (LEN) - 1; \
667 td_pt1->hw.next_td = virt_to_bus(td_pt); \
668 usb_ep->hw.tail_td = virt_to_bus(td_pt); \
669 td_pt->prev_td = td_pt1; \
670 td_pt->hw.next_td = 0
672 spinlock_t usb_req_lock
= SPIN_LOCK_UNLOCKED
;
674 int ohci_trans_req(struct ohci
* ohci
, unsigned int ep_addr
, int ctrl_len
, void *ctrl
, void * data
, int data_len
, __OHCI_BAG lw0
, __OHCI_BAG lw1
) {
678 struct usb_ohci_td
*td_pt
;
679 struct usb_ohci_td
*td_pt1
;
680 struct usb_ohci_td
*td_pt_a1
, *td_pt_a2
, *td_pt_a3
;
681 struct usb_ohci_ed
*usb_ep
;
689 usb_ep
= ohci_find_ep(ohci
, ep_addr
);
690 if(usb_ep
== NULL
) return -1; /* not known ep */
692 handler
= usb_ep
->handler
;
695 if(usb_ep
== &ohci
->ed_rh_ep0
) { /* root hub ep 0 control endpoint */
696 root_hub_control_msg(ohci
, 8, ctrl
, data
, data_len
, lw0
, lw1
, handler
);
700 if(usb_ep
== &ohci
->ed_rh_epi
) { /* root hub interrupt endpoint */
702 root_hub_int_req(ohci
, 8, ctrl
, data
, data_len
, lw0
, lw1
, handler
);
706 /* struct usb_ohci_ed * usb_ep = usb_ohci_add_ep(pipe, ohci, interval, 1); */
708 ed_type
= ((((union ep_addr_
)ep_addr
).bep
.ep
>> 5) & 0x07);
715 OHCI_ALLOC(td_pt_a1
, sizeof(td_pt_a1
));
720 OHCI_ALLOC(td_pt_a1
, sizeof(td_pt_a1
));
721 OHCI_ALLOC(td_pt_a3
, sizeof(td_pt_a3
));
723 OHCI_ALLOC(td_pt_a2
, sizeof(td_pt_a2
));
732 spin_lock_irqsave(&usb_req_lock
, flags
);
736 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_R
| TD_DP_IN
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
737 writel( OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
741 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_DP_OUT
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
742 writel( OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
746 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_R
| TD_DP_IN
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
750 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_DP_OUT
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
754 FILL_TD( td_pt_a1
, NULL
, TD_CC
| TD_DP_SETUP
| TD_T_DATA0
, ctrl
, ctrl_len
, 0, 0 );
756 FILL_TD( td_pt_a2
, NULL
, TD_CC
| TD_R
| TD_DP_IN
| TD_T_DATA1
, data
, data_len
, 0, 0 );
758 FILL_TD( td_pt_a3
, handler
, TD_CC
| TD_DP_OUT
| TD_T_DATA1
, NULL
, 0, lw0
, lw1
);
759 writel( OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
763 FILL_TD( td_pt_a1
, NULL
, TD_CC
| TD_DP_SETUP
| TD_T_DATA0
, ctrl
, ctrl_len
, 0, 0 );
765 FILL_TD( td_pt_a2
, NULL
, TD_CC
| TD_R
| TD_DP_OUT
| TD_T_DATA1
, data
, data_len
, 0, 0 );
767 FILL_TD( td_pt_a3
, handler
, TD_CC
| TD_DP_IN
| TD_T_DATA1
, NULL
, 0, lw0
, lw1
);
768 writel( OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
779 td_pt1
= (struct usb_ohci_td
*) bus_to_virt(usb_ep
->hw
.tail_td
);
782 if(td_pt_a3
!= NULL
) td_pt_a3
->prev_td
= NULL
;
783 else if (td_pt_a2
!= NULL
) td_pt_a2
->prev_td
= NULL
;
784 else if (td_pt_a1
!= NULL
) td_pt_a1
->prev_td
= NULL
;
786 spin_unlock_irqrestore(&usb_req_lock
, flags
);
792 *** Done List handling functions
793 ************************************/
795 /* replies to the request have to be on a FIFO basis so
796 * we reverse the reversed done-list */
798 static struct usb_ohci_td
* ohci_reverse_done_list(struct ohci
* ohci
) {
801 struct usb_ohci_td
* td_list
= NULL
;
802 struct usb_ohci_td
* td_rev
= NULL
;
804 td_list_hc
= ohci
->hc_area
->hcca
.done_head
& 0xfffffff0;
805 ohci
->hc_area
->hcca
.done_head
= 0;
809 td_list
= (struct usb_ohci_td
*) bus_to_virt(td_list_hc
);
810 td_list
->next_dl_td
= td_rev
;
813 td_list_hc
= td_list
->hw
.next_td
& 0xfffffff0;
818 /* all done requests are replied here */
819 static int usb_ohci_done_list(struct ohci
* ohci
) {
821 struct usb_ohci_td
* td
= NULL
;
822 struct usb_ohci_td
* td_list
;
823 struct usb_ohci_td
* td_list_next
= NULL
;
824 struct usb_ohci_td
* td_err
= NULL
;
828 td_list
= ohci_reverse_done_list(ohci
);
831 td_list_next
= td_list
->next_dl_td
;
834 if(td
->ep
== NULL
) { /* removed ep */
839 /* the HC halts an ED if an error occurs; put all pendings TDs of an halted ED on the
840 * done list; they are marked with an 0xf CC_error code
843 if(TD_CC_GET(td_list
->hw
.info
) != TD_CC_NOERROR
) { /* on error move all pending tds of an ed into the done list */
844 printk("******* USB BUS error %x @ep %x\n", TD_CC_GET(td_list
->hw
.info
), td_list
->ep
->ep_addr
.iep
);
846 td_hw
= td_list
->ep
->hw
.head_td
& 0xfffffff0;
848 if(td_hw
== td_list
->ep
->hw
.tail_td
) break;
849 td
= bus_to_virt(td_hw
);
850 td_err
->next_dl_td
= td
;
852 td_hw
= td
->hw
.next_td
;
854 td_list
->ep
->hw
.head_td
= td_list
->ep
->hw
.tail_td
;
855 td
->next_dl_td
= td_list_next
;
856 td_list_next
= td_list
->next_dl_td
;
860 if(td_list
->handler
!= NULL
) {
861 if(td_list
->prev_td
== NULL
) {
862 td_list
->handler((void *) ohci
,
863 td_list
->ep
->ep_addr
.iep
,
866 td_list
->buffer_start
,
867 td_list
->hw
.buf_end
-virt_to_bus(td_list
->buffer_start
)+1,
868 TD_CC_GET(td_list
->hw
.info
),
874 if(td_list
->prev_td
->prev_td
== NULL
) { /* cntrl 2 Transactions dataless */
875 td_list
->handler((void *) ohci
,
876 td_list
->ep
->ep_addr
.iep
,
877 td_list
->prev_td
->hw
.buf_end
-virt_to_bus(td_list
->prev_td
->buffer_start
)+1,
878 td_list
->prev_td
->buffer_start
,
881 (TD_CC_GET(td_list
->prev_td
->hw
.info
) > 0) ? TD_CC_GET(td_list
->prev_td
->hw
.info
) : TD_CC_GET(td_list
->hw
.info
),
884 OHCI_FREE(td_list
->prev_td
);
887 else { /* cntrl 3 Transactions */
888 td_list
->handler((void *) ohci
,
889 td_list
->ep
->ep_addr
.iep
,
890 td_list
->prev_td
->prev_td
->hw
.buf_end
-virt_to_bus(td_list
->prev_td
->prev_td
->buffer_start
)+1,
891 td_list
->prev_td
->prev_td
->buffer_start
,
892 td_list
->prev_td
->buffer_start
,
893 td_list
->prev_td
->hw
.buf_end
-virt_to_bus(td_list
->prev_td
->buffer_start
)+1,
894 (TD_CC_GET(td_list
->prev_td
->prev_td
->hw
.info
) > 0) ? TD_CC_GET(td_list
->prev_td
->prev_td
->hw
.info
)
895 : (TD_CC_GET(td_list
->prev_td
->hw
.info
) > 0) ? TD_CC_GET(td_list
->prev_td
->hw
.info
) : TD_CC_GET(td_list
->hw
.info
),
898 OHCI_FREE(td_list
->prev_td
->prev_td
);
899 OHCI_FREE(td_list
->prev_td
);
906 td_list
= td_list_next
;
915 ************************************/
919 void reset_hc(struct ohci
*ohci
) {
924 if(readl(&ohci
->regs
->control
) & 0x100) { /* SMM owns the HC */
925 writel(0x08, &ohci
->regs
->cmdstatus
); /* request ownership */
926 printk("USB HC TakeOver from SMM\n");
930 printk("USB HC TakeOver timed out!\n");
934 while(readl(&ohci
->regs
->control
) & 0x100);
937 writel((1<<31), &ohci
->regs
->intrdisable
); /* Disable HC interrupts */
938 OHCI_DEBUG(printk("USB HC reset_hc: %x ; retries: %d\n", readl(&ohci
->regs
->control
), 5-retries
);)
939 fminterval
= readl(&ohci
->regs
->fminterval
) & 0x3fff;
940 writel(1, &ohci
->regs
->cmdstatus
); /* HC Reset */
941 while ((readl(&ohci
->regs
->cmdstatus
) & 0x01) != 0) { /* 10us Reset */
942 if (--timeout
== 0) {
943 printk("USB HC reset timed out!\n");
949 fminterval
|= (((fminterval
-210) * 6)/7)<<16;
950 writel(fminterval
, &ohci
->regs
->fminterval
);
951 writel(((fminterval
&0x3fff)*9)/10, &ohci
->regs
->periodicstart
);
956 * Reset and start an OHCI controller
958 void start_hc(struct ohci
*ohci
)
960 /* int fminterval; */
963 /* fminterval = readl(&ohci->regs->fminterval) & 0x3fff;
967 writel(virt_to_bus(&ohci
->hc_area
->hcca
), &ohci
->regs
->hcca
); /* a reset clears this */
969 /* Choose the interrupts we care about now, others later on demand */
970 mask
= OHCI_INTR_MIE
| OHCI_INTR_WDH
;
971 /* | OHCI_INTR_SO | OHCI_INTR_UE |OHCI_INTR_RHSC |OHCI_INTR_SF|
974 if(readl(&ohci
->regs
->roothub
.a
) & 0x100) /* global power on */
975 writel( 0x10000, &ohci
->regs
->roothub
.status
); /* root hub power on */
976 else { /* port power on */
977 for(port_nr
=0; port_nr
< (ohci
->regs
->roothub
.a
& 0xff); port_nr
++)
978 writel(0x100, &ohci
->regs
->roothub
.portstatus
[port_nr
]);
982 writel((0x00), &ohci
->regs
->control
); /* USB Reset BUS */
985 writel((0xB7), &ohci
->regs
->control
); /* USB Operational */
987 OHCI_DEBUG(printk("USB HC rstart_hc_operational: %x\n", readl(&ohci
->regs
->control
)); )
988 OHCI_DEBUG(printk("USB HC roothubstata: %x \n", readl( &(ohci
->regs
->roothub
.a
) )); )
989 OHCI_DEBUG(printk("USB HC roothubstatb: %x \n", readl( &(ohci
->regs
->roothub
.b
) )); )
990 OHCI_DEBUG(printk("USB HC roothubstatu: %x \n", readl( &(ohci
->regs
->roothub
.status
) )); )
991 OHCI_DEBUG(printk("USB HC roothubstat1: %x \n", readl( &(ohci
->regs
->roothub
.portstatus
[0]) )); )
992 OHCI_DEBUG(printk("USB HC roothubstat2: %x \n", readl( &(ohci
->regs
->roothub
.portstatus
[1]) )); )
994 /* control_wakeup = NULL; */
995 writel(mask
, &ohci
->regs
->intrenable
);
996 writel(mask
, &ohci
->regs
->intrstatus
);
1001 struct usb_device
* usb_dev
;
1002 struct ohci_device
*dev
;
1004 usb_dev
= sohci_usb_allocate(ohci
->root_hub
->usb
);
1005 dev
= usb_dev
->hcpriv
;
1009 usb_connect(usb_dev
);
1011 ohci
->root_hub
->usb
->children
[0] = usb_dev
;
1013 usb_new_device(usb_dev
);
1024 static void ohci_interrupt(int irq
, void *__ohci
, struct pt_regs
*r
)
1026 struct ohci
*ohci
= __ohci
;
1027 struct ohci_regs
*regs
= ohci
->regs
;
1032 if((ohci
->hc_area
->hcca
.done_head
!= 0) && !(ohci
->hc_area
->hcca
.done_head
& 0x01)) {
1033 ints
= OHCI_INTR_WDH
;
1036 if((ints
= (readl(®s
->intrstatus
) & readl(®s
->intrenable
))) == 0)
1040 ohci
->intrstatus
|= ints
;
1041 OHCI_DEBUG(printk("USB HC interrupt: %x (%x) \n", ints
, readl(&ohci
->regs
->intrstatus
));)
1043 /* ints &= ~(OHCI_INTR_WDH); WH Bit will be set by done list subroutine */
1044 /* if(ints & OHCI_INTR_FNO) {
1045 writel(OHCI_INTR_FNO, ®s->intrstatus);
1046 if (waitqueue_active(&ohci_tasks)) wake_up(&ohci_tasks);
1049 if(ints
& OHCI_INTR_WDH
) {
1050 writel(OHCI_INTR_WDH
, ®s
->intrdisable
);
1051 ohci
->intrstatus
&= (~OHCI_INTR_WDH
);
1052 usb_ohci_done_list(ohci
); /* prepare out channel list */
1053 writel(OHCI_INTR_WDH
, &ohci
->regs
->intrstatus
);
1054 writel(OHCI_INTR_WDH
, &ohci
->regs
->intrenable
);
1058 if(ints
& OHCI_INTR_SF
) {
1059 writel(OHCI_INTR_SF
, ®s
->intrdisable
);
1060 writel(OHCI_INTR_SF
, &ohci
->regs
->intrstatus
);
1061 ohci
->intrstatus
&= (~OHCI_INTR_SF
);
1062 if(ohci
->ed_rm_list
!= NULL
) {
1067 if(ints
& OHCI_INTR_RHSC
) {
1068 writel(OHCI_INTR_RHSC
, ®s
->intrdisable
);
1069 writel(OHCI_INTR_RHSC
, &ohci
->regs
->intrstatus
);
1075 writel(OHCI_INTR_MIE
, ®s
->intrenable
);
1081 * This gets called if the connect status on the root
1082 * hub (and the root hub only) changes.
1084 static void ohci_connect_change(struct ohci
*ohci
, unsigned int port_nr
)
1086 struct usb_device
*usb_dev
;
1087 struct ohci_device
*dev
;
1088 OHCI_DEBUG(printk("uhci_connect_change: called for %d stat %x\n", port_nr
,readl(&ohci
->regs
->roothub
.portstatus
[port_nr
]) );)
1091 * Even if the status says we're connected,
1092 * the fact that the status bits changed may
1093 * that we got disconnected and then reconnected.
1095 * So start off by getting rid of any old devices..
1097 usb_disconnect(&ohci
->root_hub
->usb
->children
[port_nr
]);
1099 if(!(readl(&ohci
->regs
->roothub
.portstatus
[port_nr
]) & RH_PS_CCS
)) {
1100 writel(RH_PS_CCS
, &ohci
->regs
->roothub
.portstatus
[port_nr
]);
1101 return; /* nothing connected */
1104 * Ok, we got a new connection. Allocate a device to it,
1105 * and find out what it wants to do..
1107 usb_dev
= sohci_usb_allocate(ohci
->root_hub
->usb
);
1108 dev
= usb_dev
->hcpriv
;
1110 usb_connect(dev
->usb
);
1111 ohci
->root_hub
->usb
->children
[port_nr
] = usb_dev
;
1112 wait_ms(200); /* wait for powerup */
1113 /* reset port/device */
1114 writel(RH_PS_PRS
, &ohci
->regs
->roothub
.portstatus
[port_nr
]); /* reset port */
1115 while(!(readl( &ohci
->regs
->roothub
.portstatus
[port_nr
]) & RH_PS_PRSC
)) wait_ms(10); /* reset active ? */
1116 writel(RH_PS_PES
, &ohci
->regs
->roothub
.portstatus
[port_nr
]); /* enable port */
1118 /* Get speed information */
1119 usb_dev
->slow
= (readl( &ohci
->regs
->roothub
.portstatus
[port_nr
]) & RH_PS_LSDA
) ? 1 : 0;
1122 * Ok, all the stuff specific to the root hub has been done.
1123 * The rest is generic for any new USB attach, regardless of
1126 usb_new_device(usb_dev
);
1133 * Allocate the resources required for running an OHCI controller.
1134 * Host controller interrupts must not be running while calling this
1137 * The mem_base parameter must be the usable -virtual- address of the
1138 * host controller's memory mapped I/O registers.
1140 * This is where OHCI triumphs over UHCI, because good is dumb.
1141 * Note how much simpler this function is than in uhci.c.
1143 * OHCI hardware takes care of most of the scheduling of different
1144 * transfer types with the correct prioritization for us.
1148 static struct ohci
*alloc_ohci(void* mem_base
)
1152 struct ohci_hc_area
*hc_area
;
1153 struct usb_bus
*bus
;
1154 struct ohci_device
*dev
;
1155 struct usb_device
*usb
;
1158 * Here we allocate some dummy EDs as well as the
1159 * OHCI host controller communications area. The HCCA is just
1160 * a nice pool of memory with pointers to endpoint descriptors
1161 * for the different interrupts.
1163 * The first page of memory contains the HCCA and ohci structure
1165 hc_area
= (struct ohci_hc_area
*) __get_free_pages(GFP_KERNEL
, 1);
1168 memset(hc_area
, 0, sizeof(*hc_area
));
1169 ohci
= &hc_area
->ohci
;
1171 ohci
->regs
= mem_base
;
1173 ohci
->hc_area
= hc_area
;
1174 /* Tell the controller where the HCCA is */
1175 writel(virt_to_bus(&hc_area
->hcca
), &ohci
->regs
->hcca
);
1179 * Initialize the ED polling "tree", full tree;
1180 * dummy eds ed[i] (hc should skip them)
1181 * i == 0 is the end of the iso list;
1182 * 1 is the 1ms node,
1184 * 4,5,6,7 4ms nodes,
1185 * 8 ... 15 8ms nodes,
1186 * 16 ... 31 16ms nodes,
1187 * 32 ... 63 32ms nodes
1203 hc_area
->ed
[ED_ISO
].info
|= OHCI_ED_SKIP
; /* place holder, so skip it */
1204 hc_area
->ed
[ED_ISO
].next_ed
= 0x0000; /* end of iso list */
1206 hc_area
->ed
[1].next_ed
= virt_to_bus(&(hc_area
->ed
[ED_ISO
]));
1207 hc_area
->ed
[1].info
|= OHCI_ED_SKIP
; /* place holder, skip it */
1210 for (i
= 2; i
< (NUM_INTS
* 2); i
++) {
1212 hc_area
->hcca
.int_table
[i
- NUM_INTS
] = virt_to_bus(&(hc_area
->ed
[i
]));
1214 if( i
== j
*4) j
*= 2;
1215 hc_area
->ed
[i
].next_ed
= virt_to_bus(&(hc_area
->ed
[j
+ i
%j
]));
1216 hc_area
->ed
[i
].info
|= OHCI_ED_SKIP
; /* place holder, skip it */
1221 * for load ballancing of the interrupt branches
1223 for (i
= 0; i
< NUM_INTS
; i
++) ohci
->ohci_int_load
[i
] = 0;
1226 * Store the end of control and bulk list eds. So, we know where we can add
1227 * elements to these lists.
1229 ohci
->ed_isotail
= (struct usb_ohci_ed
*) &(hc_area
->ed
[ED_ISO
]);
1230 ohci
->ed_controltail
= NULL
;
1231 ohci
->ed_bulktail
= NULL
;
1234 * Tell the controller where the control and bulk lists are
1235 * The lists are empty now.
1237 writel(0, &ohci
->regs
->ed_controlhead
);
1238 writel(0, &ohci
->regs
->ed_bulkhead
);
1241 USB_ALLOC(bus
, sizeof(*bus
));
1245 memset(bus
, 0, sizeof(*bus
));
1248 bus
->hcpriv
= (void *) ohci
;
1249 bus
->op
= &sohci_device_operations
;
1252 usb
= sohci_usb_allocate(NULL
);
1256 dev
= ohci
->root_hub
= usb_to_ohci(usb
);
1259 /* bus->root_hub = ohci_to_usb(ohci->root_hub); */
1262 /* Initialize the root hub */
1264 usb
->maxchild
= readl(&ohci
->regs
->roothub
.a
) & 0xff;
1265 usb_init_root_hub(usb
);
1272 * De-allocate all resources..
1275 static void release_ohci(struct ohci
*ohci
)
1278 union ep_addr_ ep_addr
;
1281 OHCI_DEBUG(printk("USB HC release ohci \n");)
1283 if (ohci
->irq
>= 0) {
1284 free_irq(ohci
->irq
, ohci
);
1289 writel(OHCI_USB_SUSPEND
, &ohci
->regs
->control
);
1291 /* deallocate all EDs and TDs */
1292 for(i
=0; i
< 128; i
++) {
1294 usb_ohci_rm_function(ohci
, ep_addr
.iep
);
1296 ohci_rm_eds(ohci
); /* remove eds */
1298 /* disconnect all devices */
1300 for(i
= 0; i
< ohci
->root_hub
->usb
->maxchild
; i
++)
1301 usb_disconnect(ohci
->root_hub
->usb
->children
+ i
);
1303 USB_FREE(ohci
->root_hub
->usb
);
1304 USB_FREE(ohci
->root_hub
);
1305 USB_FREE(ohci
->bus
);
1307 /* unmap the IO address space */
1308 iounmap(ohci
->regs
);
1311 free_pages((unsigned int) ohci
->hc_area
, 1);
1316 void cleanup_drivers(void);
1318 static int ohci_roothub_thread(void * __ohci
)
1320 struct ohci
*ohci
= (struct ohci
*)__ohci
;
1324 * This thread doesn't need any user-level access,
1325 * so get rid of all our resources..
1327 printk("ohci_roothub_thread at %p\n", &ohci_roothub_thread
);
1329 exit_files(current
);
1333 strcpy(current
->comm
, "root-hub");
1337 writel( 0x10000, &ohci
->regs
->roothub
.status
);
1338 wait_ms(50); /* root hub power on */
1348 OHCI_DEBUG(printk("USB RH tasks: int: %x\n", ohci
->intrstatus
); )
1350 /* if (ohci->intrstatus & OHCI_INTR_RHSC) */
1353 for(port_nr
=0; port_nr
< ohci
->root_hub
->usb
->maxchild
; port_nr
++)
1354 if(readl(&ohci
->regs
->roothub
.portstatus
[port_nr
]) & (RH_PS_CSC
| RH_PS_PRSC
)) {
1355 ohci_connect_change(ohci
, port_nr
);
1356 writel(0xffff0000, &ohci
->regs
->roothub
.portstatus
[port_nr
]);
1358 ohci
->intrstatus
&= ~(OHCI_INTR_RHSC
);
1359 writel(OHCI_INTR_RHSC
, &ohci
->regs
->intrenable
);
1363 interruptible_sleep_on(&root_hub
);
1365 } while (!signal_pending(current
));
1368 ohci_del_rh_int_timer(ohci
);
1373 /* reset_hc(ohci); */
1378 printk("ohci_control_thread exiting\n");
1387 * Increment the module usage count, start the control thread and
1390 static int found_ohci(int irq
, void* mem_base
)
1394 OHCI_DEBUG(printk("USB HC found ohci: irq= %d membase= %x \n", irq
, (int)mem_base
);)
1395 /* Allocate the running OHCI structures */
1396 ohci
= alloc_ohci(mem_base
);
1404 if (request_irq(irq
, ohci_interrupt
, SA_SHIRQ
, "ohci-usb", ohci
) == 0) {
1410 pid
= kernel_thread(ohci_roothub_thread
, ohci
, CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
1423 static int start_ohci(struct pci_dev
*dev
)
1425 unsigned int mem_base
= dev
->base_address
[0];
1427 /* If its OHCI, its memory */
1428 if (mem_base
& PCI_BASE_ADDRESS_SPACE_IO
)
1431 /* Get the memory address and map it for IO */
1432 mem_base
&= PCI_BASE_ADDRESS_MEM_MASK
;
1435 * FIXME ioremap_nocache isn't implemented on all CPUs (such
1436 * as the Alpha) [?] What should I use instead...
1438 * The iounmap() is done on in release_ohci.
1440 mem_base
= (unsigned int) ioremap_nocache(mem_base
, 4096);
1443 printk("Error mapping OHCI memory\n");
1447 return found_ohci(dev
->irq
, (void *) mem_base
);
1453 static int handle_apm_event(apm_event_t event
)
1455 static int down
= 0;
1458 case APM_SYS_SUSPEND
:
1459 case APM_USER_SUSPEND
:
1461 printk(KERN_DEBUG
"ohci: received extra suspend event\n");
1466 case APM_NORMAL_RESUME
:
1467 case APM_CRITICAL_RESUME
:
1469 printk(KERN_DEBUG
"ohci: received bogus resume event\n");
1473 if (waitqueue_active(&root_hub
)) {
1486 void cleanup_module(void)
1489 apm_unregister_callback(&handle_apm_event
);
1493 #define ohci_hcd_init init_module
1497 #define PCI_CLASS_SERIAL_USB_OHCI 0x0C0310
1498 #define PCI_CLASS_SERIAL_USB_OHCI_PG 0x10
1501 int ohci_hcd_init(void)
1504 struct pci_dev
*dev
= NULL
;
1509 while((dev
= pci_find_class(PCI_CLASS_SERIAL_USB_OHCI
, dev
))) { /* OHCI */
1510 retval
= start_ohci(dev
);
1511 if (retval
< 0) break;
1515 apm_register_callback(&handle_apm_event
);