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
7 * the 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
12 * [ This is based on Linus' UHCI code and gregs OHCI fragments
13 * (0.03c source tree). ]
14 * [ Open Host Controller Interface driver for USB. ]
15 * [ (C) Copyright 1999 Linus Torvalds (uhci.c) ]
16 * [ (C) Copyright 1999 Gregory P. Smith <greg@electricrain.com> ]
17 * [ $Log: ohci.c,v $ ]
18 * [ Revision 1.1 1999/04/05 08:32:30 greg ]
21 * v2.1 1999/05/09 ep_addr correction, code clean up
23 * virtual root hub is now an option,
24 * memory allocation based on kmalloc and kfree now, Bus error handling,
25 * INT and CTRL transfers enabled, Bulk included but disabled, ISO needs completion
27 * from Linus Torvalds (uhci.c) (APM not tested; hub, usb_device, bus and related stuff)
28 * from Greg Smith (ohci.c) (reset controller handling, hub)
30 * v1.0 1999/04/27 initial release
34 /* #define OHCI_DBG */ /* printk some debug information */
37 #include <linux/config.h>
38 #include <linux/module.h>
39 #include <linux/pci.h>
40 #include <linux/kernel.h>
41 #include <linux/delay.h>
42 #include <linux/ioport.h>
43 #include <linux/sched.h>
44 #include <linux/malloc.h>
45 #include <linux/smp_lock.h>
46 #include <linux/errno.h>
47 #include <linux/timer.h>
49 #include <asm/spinlock.h>
52 #include <asm/system.h>
58 #include <linux/apm_bios.h>
59 static int handle_apm_event(apm_event_t event
);
60 static int apm_resume
= 0;
64 static DECLARE_WAIT_QUEUE_HEAD(bulk_wakeup
);
65 static DECLARE_WAIT_QUEUE_HEAD(control_wakeup
);
66 static DECLARE_WAIT_QUEUE_HEAD(root_hub
);
68 static __u8 cc_to_status
[16] = { /* mapping of the OHCI CC to the UHCI status codes; first guess */
69 /* Activ, Stalled, Data Buffer Err, Babble Detected : NAK recvd, CRC/Timeout, Bitstuff, reservd */
75 /* DevNotResp */ 0x04,
82 /* BufferOver */ 0x20,
84 /* Not Access */ 0x80,
90 **** Interface functions
91 ***********************************************/
93 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
)
96 struct ohci
* ohci
= ohci_in
;
97 usb_device_irq handler
=(void *) lw0
;
98 void *dev_id
= (void *) lw1
;
101 OHCI_DEBUG({ int i
; printk("USB HC IRQ <<<: %x: data(%d):", ep_addr
, data_len
);)
102 OHCI_DEBUG( for(i
=0; i
< data_len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
103 OHCI_DEBUG( printk(" ret_status: %x\n", status
); })
105 ret
= handler(cc_to_status
[status
& 0xf], data
, dev_id
);
106 if(ret
== 0) return 0; /* 0 .. do not requeue */
107 if(status
> 0) return -1; /* error occured do not requeue ? */
108 ohci_trans_req(ohci
, ep_addr
, 0, NULL
, data
, 8, (__OHCI_BAG
) handler
, (__OHCI_BAG
) dev_id
); /* requeue int request */
112 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
)
114 *(int * )lw0
= status
;
115 wake_up(&control_wakeup
);
117 OHCI_DEBUG( { int i
; printk("USB HC CTRL<<<: %x: ctrl(%d):", ep_addr
, ctrl_len
);)
118 OHCI_DEBUG( for(i
=0; i
< 8; i
++ ) printk(" %02x", ((__u8
*) ctrl
)[i
]);)
119 OHCI_DEBUG( printk(" data(%d):", data_len
);)
120 OHCI_DEBUG( for(i
=0; i
< data_len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
121 OHCI_DEBUG( printk(" ret_status: %x\n", status
); })
125 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
)
127 *(int * )lw0
= status
;
128 wake_up(&bulk_wakeup
);
130 OHCI_DEBUG( { int i
; printk("USB HC BULK<<<: %x:", ep_addr
, ctrl_len
);)
131 OHCI_DEBUG( printk(" data(%d):", data_len
);)
132 OHCI_DEBUG( for(i
=0; i
< data_len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
133 OHCI_DEBUG( printk(" ret_status: %x\n", status
); })
137 static int sohci_request_irq(struct usb_device
*usb_dev
, unsigned int pipe
, usb_device_irq handler
, int period
, void *dev_id
)
139 struct ohci
* ohci
= usb_dev
->bus
->hcpriv
;
140 union ep_addr_ ep_addr
;
143 ep_addr
.bep
.ep
= ((pipe
>> 15) & 0x0f) /* endpoint address */
144 | (pipe
& 0x80) /* direction */
145 | (1 << 5); /* type = int*/
146 ep_addr
.bep
.fa
= ((pipe
>> 8) & 0x7f); /* device address */
148 OHCI_DEBUG( printk("USB HC IRQ >>>: %x: every %d ms\n", ep_addr
.iep
, period
);)
150 usb_ohci_add_ep(ohci
, ep_addr
.iep
, period
, 1, sohci_int_handler
, 1 << ((pipe
& 0x03) + 3) , (pipe
>> 26) & 0x01);
152 ohci_trans_req(ohci
, ep_addr
.iep
, 0, NULL
, ((struct ohci_device
*) usb_dev
->hcpriv
)->data
, 8, (__OHCI_BAG
) handler
, (__OHCI_BAG
) dev_id
);
157 static int sohci_control_msg(struct usb_device
*usb_dev
, unsigned int pipe
, void *cmd
, void *data
, int len
)
159 DECLARE_WAITQUEUE(wait
, current
);
160 struct ohci
* ohci
= usb_dev
->bus
->hcpriv
;
162 union ep_addr_ ep_addr
;
165 ep_addr
.bep
.ep
= ((pipe
>> 15) & 0x0f) /* endpoint address */
166 | (pipe
& 0x80) /* direction */
167 | (1 << 6); /* type = ctrl*/
168 ep_addr
.bep
.fa
= ((pipe
>> 8) & 0x7f); /* device address */
170 status
= 0xf; /* CC not Accessed */
171 OHCI_DEBUG( { int i
; printk("USB HC CTRL>>>: %x: ctrl(%d):", ep_addr
.iep
, 8);)
172 OHCI_DEBUG( for(i
=0; i
< 8; i
++ ) printk(" %02x", ((__u8
*) cmd
)[i
]);)
173 OHCI_DEBUG( printk(" data(%d):", len
);)
174 OHCI_DEBUG( for(i
=0; i
< len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
175 OHCI_DEBUG( printk("\n"); })
177 usb_ohci_add_ep(ohci
, ep_addr
.iep
, 0, 1, sohci_ctrl_handler
, 1 << ((pipe
& 0x03) + 3) , (pipe
>> 26) & 0x01);
179 current
->state
= TASK_UNINTERRUPTIBLE
;
180 add_wait_queue(&control_wakeup
, &wait
);
182 ohci_trans_req(ohci
, ep_addr
.iep
, 8, cmd
, data
, len
, (__OHCI_BAG
) &status
, 0);
184 schedule_timeout(HZ
/10);
186 remove_wait_queue(&control_wakeup
, &wait
);
188 OHCI_DEBUG(printk("USB HC status::: %x\n", cc_to_status
[status
& 0x0f]);)
190 return cc_to_status
[status
& 0x0f];
193 static int sohci_bulk_msg(struct usb_device
*usb_dev
, unsigned int pipe
, void *data
, int len
)
195 DECLARE_WAITQUEUE(wait
, current
);
196 struct ohci
* ohci
= usb_dev
->bus
->hcpriv
;
198 union ep_addr_ ep_addr
;
201 ep_addr
.bep
.ep
= ((pipe
>> 15) & 0x0f) /* endpoint address */
202 | (pipe
& 0x80) /* direction */
203 | (11 << 5); /* type = bulk*/
204 ep_addr
.bep
.fa
= ((pipe
>> 8) & 0x7f); /* device address */
206 status
= 0xf; /* CC not Accessed */
207 OHCI_DEBUG( { int i
; printk("USB HC BULK>>>: %x:", ep_addr
.iep
);)
208 OHCI_DEBUG( printk(" data(%d):", len
);)
209 OHCI_DEBUG( for(i
=0; i
< len
; i
++ ) printk(" %02x", ((__u8
*) data
)[i
]);)
210 OHCI_DEBUG( printk("\n"); })
212 usb_ohci_add_ep(ohci
, ep_addr
.iep
, 0, 1, sohci_bulk_handler
, 1 << ((pipe
& 0x03) + 3) , (pipe
>> 26) & 0x01);
214 current
->state
= TASK_UNINTERRUPTIBLE
;
215 add_wait_queue(&bulk_wakeup
, &wait
);
217 ohci_trans_req(ohci
, ep_addr
.iep
, 0, NULL
, data
, len
, (__OHCI_BAG
) &status
, 0);
219 schedule_timeout(HZ
/10);
221 remove_wait_queue(&bulk_wakeup
, &wait
);
223 OHCI_DEBUG(printk("USB HC status::: %x\n", cc_to_status
[status
& 0x0f]);)
225 return cc_to_status
[status
& 0x0f];
228 static int sohci_usb_deallocate(struct usb_device
*usb_dev
) {
229 struct ohci_device
*dev
= usb_to_ohci(usb_dev
);
230 union ep_addr_ ep_addr
;
234 OHCI_DEBUG(printk("USB HC dealloc %x\n", usb_dev
->devnum
);)
238 if(usb_dev
->devnum
>=0) {
239 ep_addr
.bep
.fa
= usb_dev
->devnum
;
240 usb_ohci_rm_function(((struct ohci_device
*)usb_dev
->hcpriv
)->ohci
, ep_addr
.iep
);
249 static struct usb_device
*sohci_usb_allocate(struct usb_device
*parent
) {
251 struct usb_device
*usb_dev
;
252 struct ohci_device
*dev
;
255 USB_ALLOC(usb_dev
, sizeof(*usb_dev
));
259 memset(usb_dev
, 0, sizeof(*usb_dev
));
261 USB_ALLOC(dev
, sizeof(*dev
));
267 /* Initialize "dev" */
268 memset(dev
, 0, sizeof(*dev
));
270 usb_dev
->hcpriv
= dev
;
273 usb_dev
->parent
= parent
;
276 usb_dev
->bus
= parent
->bus
;
277 dev
->ohci
= usb_to_ohci(parent
)->ohci
;
283 struct usb_operations sohci_device_operations
= {
285 sohci_usb_deallocate
,
293 *** ED handling functions
294 ************************************/
299 * search for the right place to insert an interrupt ed into the int tree
300 * do some load ballancing
303 static int usb_ohci_int_ballance(struct ohci
* ohci
, int interval
, int load
) {
307 j
= 0; /* search for the least loaded interrupt endpoint branch of all 32 branches */
308 for(i
=0; i
< 32; i
++) if(ohci
->ohci_int_load
[j
] > ohci
->ohci_int_load
[i
]) j
=i
;
310 if(interval
< 1) interval
= 1;
311 if(interval
> 32) interval
= 32;
312 for(i
= 0; ((interval
>> i
) > 1 ); interval
&= (0xfffe << i
++ )); /* interval = 2^int(ld(interval)) */
315 for(i
=j
%interval
; i
< 32; i
+=interval
) ohci
->ohci_int_load
[i
] += load
;
316 j
= interval
+ (j
% interval
);
318 OHCI_DEBUG(printk("USB HC new int ed on pos : %x \n",j
);)
323 /* get the ed from the endpoint / device adress */
325 struct usb_ohci_ed
* ohci_find_ep(struct ohci
*ohci
, unsigned int ep_addr_in
) {
327 union ep_addr_ ep_addr
;
328 struct usb_ohci_ed
*tmp
;
332 ep_addr
.iep
= ep_addr_in
;
335 if(ep_addr
.bep
.fa
== ohci
->root_hub_funct_addr
) {
336 if((ep_addr
.bep
.ep
& 0x0f) == 0)
337 return &ohci
->ed_rh_ep0
; /* root hub ep0 */
339 return &ohci
->ed_rh_epi
; /* root hub int ep */
343 tmp
= ohci
->ed_func_ep0
[ep_addr
.bep
.fa
];
344 mask
= ((((ep_addr
.bep
.ep
>> 5) & 0x03)==2)?0x7f:0xff);
345 ep_addr
.bep
.ep
&= mask
; /* mask out direction of ctrl ep */
347 while (tmp
!= NULL
) {
348 if (tmp
->ep_addr
.iep
== ep_addr
.iep
)
355 spinlock_t usb_ed_lock
= SPIN_LOCK_UNLOCKED
;
356 /* add a new endpoint ep_addr */
357 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
) {
359 struct usb_ohci_ed
* ed
;
360 struct usb_ohci_td
* td
;
361 union ep_addr_ ep_addr
;
366 struct usb_ohci_ed
*tmp
;
368 ep_addr
.iep
= ep_addr_in
;
369 ep_addr
.bep
.ep
&= ((((ep_addr
.bep
.ep
>> 5) & 0x03)==2)?0x7f:0xff); /* mask out direction of ctrl ep */
371 spin_lock(&usb_ed_lock
);
373 tmp
= ohci_find_ep(ohci
, ep_addr
.iep
);
377 if(ep_addr
.bep
.fa
== ohci
->root_hub_funct_addr
) {
378 if((ep_addr
.bep
.ep
& 0x0f) != 0) { /* root hub int ep */
379 ohci
->ed_rh_epi
.handler
= handler
;
380 ohci_init_rh_int_timer(ohci
, interval
);
382 else { /* root hub ep0 */
383 ohci
->ed_rh_ep0
.handler
= handler
;
391 tmp
->hw
.info
= ep_addr
.bep
.fa
| ((ep_addr
.bep
.ep
& 0xf) <<7)
393 | (((ep_addr
.bep
.ep
& 0x60) == 0)? 0x8000 : 0)
397 tmp
->handler
= handler
;
399 spin_unlock(&usb_ed_lock
);
400 return tmp
; /* ed already in use */
404 OHCI_ALLOC(td
, sizeof(td
)); /* dummy td; end of td list for ed */
405 OHCI_ALLOC(ed
, sizeof(ed
));
408 ed
->hw
.tail_td
= virt_to_bus(&td
->hw
);
409 ed
->hw
.head_td
= ed
->hw
.tail_td
;
410 ed
->hw
.info
= ep_addr
.bep
.fa
| ((ep_addr
.bep
.ep
& 0xf) <<7)
411 /* | ((ep_addr.bep.port & 0x80)? 0x1000 : 0x0800 ) */
412 | (((ep_addr
.bep
.ep
& 0x60) == 0)? 0x8000 : 0)
416 ed
->handler
= handler
;
418 switch((ep_addr
.bep
.ep
>> 5) & 0x03) {
421 if(ohci
->ed_controltail
== NULL
) {
422 writel(virt_to_bus(&ed
->hw
), &ohci
->regs
->ed_controlhead
);
425 ohci
->ed_controltail
->hw
.next_ed
= virt_to_bus(&ed
->hw
);
427 ed
->ed_prev
= ohci
->ed_controltail
;
428 ohci
->ed_controltail
= ed
;
432 if(ohci
->ed_bulktail
== NULL
) {
433 writel(virt_to_bus(&ed
->hw
), &ohci
->regs
->ed_bulkhead
);
436 ohci
->ed_bulktail
->hw
.next_ed
= virt_to_bus(&ed
->hw
);
438 ed
->ed_prev
= ohci
->ed_bulktail
;
439 ohci
->ed_bulktail
= ed
;
442 int_junk
= usb_ohci_int_ballance(ohci
, interval
, load
);
443 ed
->hw
.next_ed
= ohci
->hc_area
->ed
[int_junk
].next_ed
;
444 ohci
->hc_area
->ed
[int_junk
].next_ed
= virt_to_bus(&ed
->hw
);
445 ed
->ed_prev
= (struct usb_ohci_ed
*) &ohci
->hc_area
->ed
[int_junk
];
449 ohci
->ed_isotail
->hw
.next_ed
= virt_to_bus(&ed
->hw
);
450 ed
->ed_prev
= ohci
->ed_isotail
;
451 ohci
->ed_isotail
= ed
;
454 ed
->ep_addr
= ep_addr
;
456 /* Add it to the "hash"-table of known endpoint descriptors */
458 ed
->ed_list
= ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
];
459 ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
] = ed
;
461 spin_unlock(&usb_ed_lock
);
463 OHCI_DEBUG(printk("USB HC new ed %x: %x :", ep_addr
.iep
, (unsigned int ) ed
); )
464 OHCI_DEBUG({ int i
; for( i
= 0; i
<8 ;i
++) printk(" %4x", ((unsigned int *) ed
)[i
]) ; printk("\n"); }; )
469 * Request the removal of an endpoint
471 * put the ep on the rm_list and request a stop of the bulk or ctrl list
472 * real removal is done at the next start of frame hardware interrupt
474 int usb_ohci_rm_ep(struct ohci
* ohci
, struct usb_ohci_ed
*ed
)
477 struct usb_ohci_ed
*tmp
;
479 OHCI_DEBUG(printk("USB HC remove ed %x: %x :\n", ed
->ep_addr
.iep
, (unsigned int ) ed
); )
481 spin_lock_irqsave(&usb_ed_lock
, flags
);
483 tmp
= ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
];
485 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
490 ohci
->ed_func_ep0
[ed
->ep_addr
.bep
.fa
] = ed
->ed_list
;
493 while (tmp
->ed_list
!= ed
) {
494 if (tmp
->ed_list
== NULL
) {
495 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
500 tmp
->ed_list
= ed
->ed_list
;
502 ed
->ed_list
= ohci
->ed_rm_list
;
503 ohci
->ed_rm_list
= ed
;
504 ed
->hw
.info
|= OHCI_ED_SKIP
;
506 switch((ed
->ep_addr
.bep
.ep
>> 5) & 0x03) {
508 writel_mask(~(0x01<<4), &ohci
->regs
->control
); /* stop CTRL list */
511 writel_mask(~(0x01<<5), &ohci
->regs
->control
); /* stop BULK list */
516 writel( OHCI_INTR_SF
, &ohci
->regs
->intrenable
); /* enable sof interrupt */
518 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
523 /* we have requested to stop the bulk or CTRL list,
524 * now we can remove the eds on the rm_list */
526 static int ohci_rm_eds(struct ohci
* ohci
) {
529 struct usb_ohci_ed
*ed
;
530 struct usb_ohci_ed
*ed_tmp
;
531 struct usb_ohci_td
*td
;
535 spin_lock_irqsave(&usb_ed_lock
, flags
);
537 ed
= ohci
->ed_rm_list
;
541 switch((ed
->ep_addr
.bep
.ep
>> 5) & 0x03) {
543 if(ed
->ed_prev
== NULL
) {
544 writel(ed
->hw
.next_ed
, &ohci
->regs
->ed_controlhead
);
547 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
549 if(ohci
->ed_controltail
== ed
) {
550 ohci
->ed_controltail
= ed
->ed_prev
;
554 if(ed
->ed_prev
== NULL
) {
555 writel(ed
->hw
.next_ed
, &ohci
->regs
->ed_bulkhead
);
558 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
560 if(ohci
->ed_bulktail
== ed
) {
561 ohci
->ed_bulktail
= ed
->ed_prev
;
565 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
568 ed
->ed_prev
->hw
.next_ed
= ed
->hw
.next_ed
;
569 if(ohci
->ed_isotail
== ed
) {
570 ohci
->ed_isotail
= ed
->ed_prev
;
575 if(ed
->hw
.next_ed
!= 0) ((struct usb_ohci_ed
*) bus_to_virt(ed
->hw
.next_ed
))->ed_prev
= ed
->ed_prev
;
578 /* tds directly connected to ed */
580 td_hw
= ed
->hw
.head_td
& 0xfffffff0;
582 td
= bus_to_virt(td_hw
);
584 td_hw
= td
->hw
.next_td
;
585 OHCI_FREE(td
); /* free pending tds */
586 if(td_hw_tmp
== ed
->hw
.tail_td
) break;
590 /* mark TDs on the hc done list (if there are any) */
591 td_hw
= readl(&ohci
->regs
->donehead
) & 0xfffffff0;
593 td
= bus_to_virt(td_hw
);
594 td_hw
= td
->hw
.next_td
;
595 if(td
->ep
== ed
) td
->ep
= 0;
598 /* mark TDs on the hcca done list (if there are any) */
599 td_hw
= ohci
->hc_area
->hcca
.done_head
& 0xfffffff0 ;
602 td
= bus_to_virt(td_hw
);
603 td_hw
= td
->hw
.next_td
;
604 if(td
->ep
== ed
) td
->ep
= 0;
609 OHCI_FREE(ed_tmp
); /* free ed */
611 writel(0, &ohci
->regs
->ed_controlcurrent
); /* reset CTRL list */
612 writel(0, &ohci
->regs
->ed_bulkcurrent
); /* reset BULK list */
613 writel_set((0x03<<4), &ohci
->regs
->control
); /* start CTRL u. (BULK list) */
615 spin_unlock_irqrestore(&usb_ed_lock
, flags
);
617 ohci
->ed_rm_list
= NULL
;
618 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
));)
624 /* remove all endpoints of a function (device) */
625 int usb_ohci_rm_function( struct ohci
* ohci
, unsigned int ep_addr_in
)
627 struct usb_ohci_ed
*ed
;
628 struct usb_ohci_ed
*tmp
;
629 union ep_addr_ ep_addr
;
633 ep_addr
.iep
= ep_addr_in
;
635 for(ed
= ohci
->ed_func_ep0
[ep_addr
.bep
.fa
]; ed
!= NULL
;) {
638 usb_ohci_rm_ep(ohci
, tmp
);
651 *** TD handling functions
652 ************************************/
655 #define FILL_TD(TD_PT, HANDLER, INFO, DATA, LEN, LW0, LW1) \
657 td_pt1 = (struct usb_ohci_td *) bus_to_virt(usb_ep->hw.tail_td); \
658 td_pt1->ep = usb_ep; \
659 td_pt1->handler = (HANDLER); \
660 td_pt1->buffer_start = (DATA); \
661 td_pt1->lw0 = (LW0); \
662 td_pt1->lw1 = (LW1); \
663 td_pt1->hw.info = (INFO); \
664 td_pt1->hw.cur_buf = virt_to_bus(DATA); \
665 td_pt1->hw.buf_end = td_pt1->hw.cur_buf + (LEN) - 1; \
666 td_pt1->hw.next_td = virt_to_bus(td_pt); \
667 usb_ep->hw.tail_td = virt_to_bus(td_pt); \
668 td_pt->prev_td = td_pt1; \
669 td_pt->hw.next_td = 0
671 spinlock_t usb_req_lock
= SPIN_LOCK_UNLOCKED
;
673 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
) {
677 struct usb_ohci_td
*td_pt
;
678 struct usb_ohci_td
*td_pt1
;
679 struct usb_ohci_td
*td_pt_a1
, *td_pt_a2
, *td_pt_a3
;
680 struct usb_ohci_ed
*usb_ep
;
688 usb_ep
= ohci_find_ep(ohci
, ep_addr
);
689 if(usb_ep
== NULL
) return -1; /* not known ep */
691 handler
= usb_ep
->handler
;
694 if(usb_ep
== &ohci
->ed_rh_ep0
) { /* root hub ep 0 control endpoint */
695 root_hub_control_msg(ohci
, 8, ctrl
, data
, data_len
, lw0
, lw1
, handler
);
699 if(usb_ep
== &ohci
->ed_rh_epi
) { /* root hub interrupt endpoint */
701 root_hub_int_req(ohci
, 8, ctrl
, data
, data_len
, lw0
, lw1
, handler
);
705 /* struct usb_ohci_ed * usb_ep = usb_ohci_add_ep(pipe, ohci, interval, 1); */
707 ed_type
= ((((union ep_addr_
)ep_addr
).bep
.ep
>> 5) & 0x07);
714 OHCI_ALLOC(td_pt_a1
, sizeof(td_pt_a1
));
719 OHCI_ALLOC(td_pt_a1
, sizeof(td_pt_a1
));
720 OHCI_ALLOC(td_pt_a3
, sizeof(td_pt_a3
));
722 OHCI_ALLOC(td_pt_a2
, sizeof(td_pt_a2
));
731 spin_lock_irqsave(&usb_req_lock
, flags
);
735 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_R
| TD_DP_IN
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
736 writel( OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
740 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_DP_OUT
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
741 writel( OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
745 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_R
| TD_DP_IN
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
749 FILL_TD( td_pt_a1
, handler
, TD_CC
| TD_DP_OUT
| TD_T_TOGGLE
, data
, data_len
, lw0
, lw1
);
753 FILL_TD( td_pt_a1
, NULL
, TD_CC
| TD_DP_SETUP
| TD_T_DATA0
, ctrl
, ctrl_len
, 0, 0 );
755 FILL_TD( td_pt_a2
, NULL
, TD_CC
| TD_R
| TD_DP_IN
| TD_T_DATA1
, data
, data_len
, 0, 0 );
757 FILL_TD( td_pt_a3
, handler
, TD_CC
| TD_DP_OUT
| TD_T_DATA1
, NULL
, 0, lw0
, lw1
);
758 writel( OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
762 FILL_TD( td_pt_a1
, NULL
, TD_CC
| TD_DP_SETUP
| TD_T_DATA0
, ctrl
, ctrl_len
, 0, 0 );
764 FILL_TD( td_pt_a2
, NULL
, TD_CC
| TD_R
| TD_DP_OUT
| TD_T_DATA1
, data
, data_len
, 0, 0 );
766 FILL_TD( td_pt_a3
, handler
, TD_CC
| TD_DP_IN
| TD_T_DATA1
, NULL
, 0, lw0
, lw1
);
767 writel( OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
778 td_pt1
= (struct usb_ohci_td
*) bus_to_virt(usb_ep
->hw
.tail_td
);
781 if(td_pt_a3
!= NULL
) td_pt_a3
->prev_td
= NULL
;
782 else if (td_pt_a2
!= NULL
) td_pt_a2
->prev_td
= NULL
;
783 else if (td_pt_a1
!= NULL
) td_pt_a1
->prev_td
= NULL
;
785 spin_unlock_irqrestore(&usb_req_lock
, flags
);
791 *** Done List handling functions
792 ************************************/
794 /* replies to the request have to be on a FIFO basis so
795 * we reverse the reversed done-list */
797 static struct usb_ohci_td
* ohci_reverse_done_list(struct ohci
* ohci
) {
800 struct usb_ohci_td
* td_list
= NULL
;
801 struct usb_ohci_td
* td_rev
= NULL
;
803 td_list_hc
= ohci
->hc_area
->hcca
.done_head
& 0xfffffff0;
804 ohci
->hc_area
->hcca
.done_head
= 0;
808 td_list
= (struct usb_ohci_td
*) bus_to_virt(td_list_hc
);
809 td_list
->next_dl_td
= td_rev
;
812 td_list_hc
= td_list
->hw
.next_td
& 0xfffffff0;
817 /* all done requests are replied here */
818 static int usb_ohci_done_list(struct ohci
* ohci
) {
820 struct usb_ohci_td
* td
= NULL
;
821 struct usb_ohci_td
* td_list
;
822 struct usb_ohci_td
* td_list_next
= NULL
;
823 struct usb_ohci_td
* td_err
= NULL
;
827 td_list
= ohci_reverse_done_list(ohci
);
830 td_list_next
= td_list
->next_dl_td
;
833 if(td
->ep
== NULL
) { /* removed ep */
838 /* the HC halts an ED if an error occurs; put all pendings TDs of an halted ED on the
839 * done list; they are marked with an 0xf CC_error code
842 if(TD_CC_GET(td_list
->hw
.info
) != TD_CC_NOERROR
) { /* on error move all pending tds of an ed into the done list */
843 printk("******* USB BUS error %x @ep %x\n", TD_CC_GET(td_list
->hw
.info
), td_list
->ep
->ep_addr
.iep
);
845 td_hw
= td_list
->ep
->hw
.head_td
& 0xfffffff0;
847 if(td_hw
== td_list
->ep
->hw
.tail_td
) break;
848 td
= bus_to_virt(td_hw
);
849 td_err
->next_dl_td
= td
;
851 td_hw
= td
->hw
.next_td
;
853 td_list
->ep
->hw
.head_td
= td_list
->ep
->hw
.tail_td
;
854 td
->next_dl_td
= td_list_next
;
855 td_list_next
= td_list
->next_dl_td
;
859 if(td_list
->handler
!= NULL
) {
860 if(td_list
->prev_td
== NULL
) {
861 td_list
->handler((void *) ohci
,
862 td_list
->ep
->ep_addr
.iep
,
865 td_list
->buffer_start
,
866 td_list
->hw
.buf_end
-virt_to_bus(td_list
->buffer_start
)+1,
867 TD_CC_GET(td_list
->hw
.info
),
873 if(td_list
->prev_td
->prev_td
== NULL
) { /* cntrl 2 Transactions dataless */
874 td_list
->handler((void *) ohci
,
875 td_list
->ep
->ep_addr
.iep
,
876 td_list
->prev_td
->hw
.buf_end
-virt_to_bus(td_list
->prev_td
->buffer_start
)+1,
877 td_list
->prev_td
->buffer_start
,
880 (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
),
883 OHCI_FREE(td_list
->prev_td
);
886 else { /* cntrl 3 Transactions */
887 td_list
->handler((void *) ohci
,
888 td_list
->ep
->ep_addr
.iep
,
889 td_list
->prev_td
->prev_td
->hw
.buf_end
-virt_to_bus(td_list
->prev_td
->prev_td
->buffer_start
)+1,
890 td_list
->prev_td
->prev_td
->buffer_start
,
891 td_list
->prev_td
->buffer_start
,
892 td_list
->prev_td
->hw
.buf_end
-virt_to_bus(td_list
->prev_td
->buffer_start
)+1,
893 (TD_CC_GET(td_list
->prev_td
->prev_td
->hw
.info
) > 0) ? TD_CC_GET(td_list
->prev_td
->prev_td
->hw
.info
)
894 : (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
),
897 OHCI_FREE(td_list
->prev_td
->prev_td
);
898 OHCI_FREE(td_list
->prev_td
);
905 td_list
= td_list_next
;
914 ************************************/
918 void reset_hc(struct ohci
*ohci
) {
923 if(readl(&ohci
->regs
->control
) & 0x100) { /* SMM owns the HC */
924 writel(0x08, &ohci
->regs
->cmdstatus
); /* request ownership */
925 printk("USB HC TakeOver from SMM\n");
929 printk("USB HC TakeOver timed out!\n");
933 while(readl(&ohci
->regs
->control
) & 0x100);
936 writel((1<<31), &ohci
->regs
->intrdisable
); /* Disable HC interrupts */
937 OHCI_DEBUG(printk("USB HC reset_hc: %x ; retries: %d\n", readl(&ohci
->regs
->control
), 5-retries
);)
938 fminterval
= readl(&ohci
->regs
->fminterval
) & 0x3fff;
939 writel(1, &ohci
->regs
->cmdstatus
); /* HC Reset */
940 while ((readl(&ohci
->regs
->cmdstatus
) & 0x01) != 0) { /* 10us Reset */
941 if (--timeout
== 0) {
942 printk("USB HC reset timed out!\n");
948 fminterval
|= (((fminterval
-210) * 6)/7)<<16;
949 writel(fminterval
, &ohci
->regs
->fminterval
);
950 writel(((fminterval
&0x3fff)*9)/10, &ohci
->regs
->periodicstart
);
955 * Reset and start an OHCI controller
957 void start_hc(struct ohci
*ohci
)
959 /* int fminterval; */
962 /* fminterval = readl(&ohci->regs->fminterval) & 0x3fff;
966 writel(virt_to_bus(&ohci
->hc_area
->hcca
), &ohci
->regs
->hcca
); /* a reset clears this */
968 /* Choose the interrupts we care about now, others later on demand */
969 mask
= OHCI_INTR_MIE
| OHCI_INTR_WDH
;
970 /* | OHCI_INTR_SO | OHCI_INTR_UE |OHCI_INTR_RHSC |OHCI_INTR_SF|
973 if(readl(&ohci
->regs
->roothub
.a
) & 0x100) /* global power on */
974 writel( 0x10000, &ohci
->regs
->roothub
.status
); /* root hub power on */
975 else { /* port power on */
976 for(port_nr
=0; port_nr
< (ohci
->regs
->roothub
.a
& 0xff); port_nr
++)
977 writel(0x100, &ohci
->regs
->roothub
.portstatus
[port_nr
]);
981 writel((0x00), &ohci
->regs
->control
); /* USB Reset BUS */
984 writel((0xB7), &ohci
->regs
->control
); /* USB Operational */
986 OHCI_DEBUG(printk("USB HC rstart_hc_operational: %x\n", readl(&ohci
->regs
->control
)); )
987 OHCI_DEBUG(printk("USB HC roothubstata: %x \n", readl( &(ohci
->regs
->roothub
.a
) )); )
988 OHCI_DEBUG(printk("USB HC roothubstatb: %x \n", readl( &(ohci
->regs
->roothub
.b
) )); )
989 OHCI_DEBUG(printk("USB HC roothubstatu: %x \n", readl( &(ohci
->regs
->roothub
.status
) )); )
990 OHCI_DEBUG(printk("USB HC roothubstat1: %x \n", readl( &(ohci
->regs
->roothub
.portstatus
[0]) )); )
991 OHCI_DEBUG(printk("USB HC roothubstat2: %x \n", readl( &(ohci
->regs
->roothub
.portstatus
[1]) )); )
993 /* control_wakeup = NULL; */
994 writel(mask
, &ohci
->regs
->intrenable
);
995 writel(mask
, &ohci
->regs
->intrstatus
);
1000 struct usb_device
* usb_dev
;
1001 struct ohci_device
*dev
;
1002 struct ohci_device
*tmp_root_hub
= usb_to_ohci(ohci
->bus
->root_hub
);
1003 usb_dev
= sohci_usb_allocate(tmp_root_hub
->usb
);
1004 dev
= usb_dev
->hcpriv
;
1008 usb_connect(usb_dev
);
1010 tmp_root_hub
->usb
->children
[0] = usb_dev
;
1012 usb_new_device(usb_dev
);
1023 static void ohci_interrupt(int irq
, void *__ohci
, struct pt_regs
*r
)
1025 struct ohci
*ohci
= __ohci
;
1026 struct ohci_regs
*regs
= ohci
->regs
;
1031 if((ohci
->hc_area
->hcca
.done_head
!= 0) && !(ohci
->hc_area
->hcca
.done_head
& 0x01)) {
1032 ints
= OHCI_INTR_WDH
;
1035 if((ints
= (readl(®s
->intrstatus
) & readl(®s
->intrenable
))) == 0)
1039 ohci
->intrstatus
|= ints
;
1040 OHCI_DEBUG(printk("USB HC interrupt: %x (%x) \n", ints
, readl(&ohci
->regs
->intrstatus
));)
1042 /* ints &= ~(OHCI_INTR_WDH); WH Bit will be set by done list subroutine */
1043 /* if(ints & OHCI_INTR_FNO) {
1044 writel(OHCI_INTR_FNO, ®s->intrstatus);
1045 if (waitqueue_active(&ohci_tasks)) wake_up(&ohci_tasks);
1048 if(ints
& OHCI_INTR_WDH
) {
1049 writel(OHCI_INTR_WDH
, ®s
->intrdisable
);
1050 ohci
->intrstatus
&= (~OHCI_INTR_WDH
);
1051 usb_ohci_done_list(ohci
); /* prepare out channel list */
1052 writel(OHCI_INTR_WDH
, &ohci
->regs
->intrstatus
);
1053 writel(OHCI_INTR_WDH
, &ohci
->regs
->intrenable
);
1057 if(ints
& OHCI_INTR_SF
) {
1058 writel(OHCI_INTR_SF
, ®s
->intrdisable
);
1059 writel(OHCI_INTR_SF
, &ohci
->regs
->intrstatus
);
1060 ohci
->intrstatus
&= (~OHCI_INTR_SF
);
1061 if(ohci
->ed_rm_list
!= NULL
) {
1066 if(ints
& OHCI_INTR_RHSC
) {
1067 writel(OHCI_INTR_RHSC
, ®s
->intrdisable
);
1068 writel(OHCI_INTR_RHSC
, &ohci
->regs
->intrstatus
);
1074 writel(OHCI_INTR_MIE
, ®s
->intrenable
);
1080 * This gets called if the connect status on the root
1081 * hub (and the root hub only) changes.
1083 static void ohci_connect_change(struct ohci
*ohci
, unsigned int port_nr
)
1085 struct usb_device
*usb_dev
;
1086 struct ohci_device
*dev
;
1087 struct ohci_device
*tmp_root_hub
=usb_to_ohci(ohci
->bus
->root_hub
);
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(&tmp_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(tmp_root_hub
->usb
);
1108 dev
= usb_dev
->hcpriv
;
1110 usb_connect(dev
->usb
);
1111 tmp_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
= usb_to_ohci(usb
);
1258 bus
->root_hub
= usb
;
1261 /* Initialize the root hub */
1263 usb
->maxchild
= readl(&ohci
->regs
->roothub
.a
) & 0xff;
1264 usb_init_root_hub(usb
);
1271 * De-allocate all resources..
1274 static void release_ohci(struct ohci
*ohci
)
1277 struct ohci_device
*tmp_root_hub
=usb_to_ohci(ohci
->bus
->root_hub
);
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 */
1299 if(ohci
->bus
->root_hub
)
1300 for(i
= 0; i
< tmp_root_hub
->usb
->maxchild
; i
++)
1301 usb_disconnect(tmp_root_hub
->usb
->children
+ i
);
1303 usb_deregister_bus(ohci
->bus
);
1304 USB_FREE(tmp_root_hub
->usb
);
1305 USB_FREE(tmp_root_hub
);
1306 USB_FREE(ohci
->bus
);
1308 /* unmap the IO address space */
1309 iounmap(ohci
->regs
);
1311 free_pages((unsigned int) ohci
->hc_area
, 1);
1315 static int ohci_roothub_thread(void * __ohci
)
1317 struct ohci
*ohci
= (struct ohci
*)__ohci
;
1321 * This thread doesn't need any user-level access,
1322 * so get rid of all our resources..
1324 printk("ohci_roothub_thread at %p\n", &ohci_roothub_thread
);
1326 exit_files(current
);
1330 strcpy(current
->comm
, "root-hub");
1334 writel( 0x10000, &ohci
->regs
->roothub
.status
);
1335 wait_ms(50); /* root hub power on */
1336 usb_register_bus(ohci
->bus
);
1346 OHCI_DEBUG(printk("USB RH tasks: int: %x\n",ohci
->intrstatus
););
1348 /* if (ohci->intrstatus & OHCI_INTR_RHSC) */
1351 for(port_nr
=0; port_nr
< ohci
->root_hub
->usb
->maxchild
; port_nr
++)
1352 if(readl(&ohci
->regs
->roothub
.portstatus
[port_nr
]) & (RH_PS_CSC
| RH_PS_PRSC
)) {
1353 ohci_connect_change(ohci
, port_nr
);
1354 writel(0xffff0000, &ohci
->regs
->roothub
.portstatus
[port_nr
]);
1356 ohci
->intrstatus
&= ~(OHCI_INTR_RHSC
);
1357 writel(OHCI_INTR_RHSC
, &ohci
->regs
->intrenable
);
1361 interruptible_sleep_on(&root_hub
);
1363 } while (!signal_pending(current
));
1366 ohci_del_rh_int_timer(ohci
);
1371 /* reset_hc(ohci); */
1376 printk("ohci_control_thread exiting\n");
1382 * Increment the module usage count, start the control thread and
1385 static int found_ohci(int irq
, void* mem_base
)
1389 OHCI_DEBUG(printk("USB HC found ohci: irq= %d membase= %x \n", irq
, (int)mem_base
);)
1390 /* Allocate the running OHCI structures */
1391 ohci
= alloc_ohci(mem_base
);
1399 if (request_irq(irq
, ohci_interrupt
, SA_SHIRQ
, "ohci-usb", ohci
) == 0) {
1405 pid
= kernel_thread(ohci_roothub_thread
, ohci
, CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
1418 static int start_ohci(struct pci_dev
*dev
)
1420 unsigned int mem_base
= dev
->base_address
[0];
1422 /* If its OHCI, its memory */
1423 if (mem_base
& PCI_BASE_ADDRESS_SPACE_IO
)
1426 /* Get the memory address and map it for IO */
1427 mem_base
&= PCI_BASE_ADDRESS_MEM_MASK
;
1430 * FIXME ioremap_nocache isn't implemented on all CPUs (such
1431 * as the Alpha) [?] What should I use instead...
1433 * The iounmap() is done on in release_ohci.
1435 mem_base
= (unsigned int) ioremap_nocache(mem_base
, 4096);
1438 printk("Error mapping OHCI memory\n");
1442 return found_ohci(dev
->irq
, (void *) mem_base
);
1448 static int handle_apm_event(apm_event_t event
)
1450 static int down
= 0;
1453 case APM_SYS_SUSPEND
:
1454 case APM_USER_SUSPEND
:
1456 printk(KERN_DEBUG
"ohci: received extra suspend event\n");
1461 case APM_NORMAL_RESUME
:
1462 case APM_CRITICAL_RESUME
:
1464 printk(KERN_DEBUG
"ohci: received bogus resume event\n");
1468 if (waitqueue_active(&root_hub
)) {
1478 #define PCI_CLASS_SERIAL_USB_OHCI 0x0C0310
1479 #define PCI_CLASS_SERIAL_USB_OHCI_PG 0x10
1482 int ohci_hcd_init(void)
1485 struct pci_dev
*dev
= NULL
;
1490 while((dev
= pci_find_class(PCI_CLASS_SERIAL_USB_OHCI
, dev
))) { /* OHCI */
1491 retval
= start_ohci(dev
);
1492 if (retval
< 0) break;
1496 apm_register_callback(&handle_apm_event
);
1505 int init_module(void){
1506 return ohci_hcd_init();
1509 void cleanup_module(void)
1512 apm_unregister_callback(&handle_apm_event
);