2 * Universal Host Controller Interface driver for USB.
4 * (C) Copyright 1999 Linus Torvalds
6 * Intel documents this fairly well, and as far as I know there
7 * are no royalties or anything like that, but even so there are
8 * people who decided that they want to do the same thing in a
9 * completely different way.
11 * Oh, well. The intel version is the more common by far. As such,
12 * that's the one I care about right now.
14 * WARNING! The USB documentation is downright evil. Most of it
15 * is just crap, written by a committee. You're better off ignoring
16 * most of it, the important stuff is:
17 * - the low-level protocol (fairly simple but lots of small details)
18 * - working around the horridness of the rest
21 /* 4/4/1999 added data toggle for interrupt pipes -keryan */
22 /* 5/16/1999 added global toggles for bulk and control */
23 /* 6/25/1999 added fix for data toggles on bidirectional bulk endpoints */
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/pci.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/ioport.h>
31 #include <linux/sched.h>
32 #include <linux/malloc.h>
33 #include <linux/smp_lock.h>
34 #include <linux/errno.h>
35 #include <linux/unistd.h>
37 #include <asm/uaccess.h>
38 #include <asm/spinlock.h>
41 #include <asm/system.h>
46 #include <linux/apm_bios.h>
47 static int handle_apm_event(apm_event_t event
);
48 static int apm_resume
= 0;
51 static int uhci_debug
= 1;
53 #define compile_assert(x) do { switch (0) { case 1: case !(x): } } while (0)
55 static DECLARE_WAIT_QUEUE_HEAD(uhci_configure
);
58 * Map status to standard result codes
60 static int uhci_map_status(int status
, int dir_out
)
63 return USB_ST_NOERROR
;
64 if (status
& 0x02) /* Bitstuff error*/
65 return USB_ST_BITSTUFF
;
66 if (status
& 0x04) { /* CRC/Timeout */
68 return USB_ST_NORESPONSE
;
72 if (status
& 0x08) /* NAK */
73 return USB_ST_TIMEOUT
;
74 if (status
& 0x10) /* Babble */
76 if (status
& 0x20) /* Buffer error */
77 return USB_ST_BUFFERUNDERRUN
;
78 if (status
& 0x40) /* Stalled */
80 if (status
& 0x80) /* Active */
81 return USB_ST_NOERROR
;
82 return USB_ST_INTERNALERROR
;
85 * Return the result of a TD..
87 static int uhci_td_result(struct uhci_device
*dev
, struct uhci_td
*td
, unsigned long *rval
)
90 struct uhci_td
*tmp
= td
->first
;
95 /* locate the first failing td, if any */
98 status
= (tmp
->status
>> 16) & 0xff;
100 /* must reset the toggle on first error */
102 printk("Set toggle from %x rval %ld\n", (unsigned int)tmp
, rval
? *rval
: 0);
104 usb_settoggle(dev
->usb
, usb_pipeendpoint(tmp
->info
), usb_pipeout(tmp
->info
), (tmp
->info
>> 19) & 1);
108 *rval
+= (tmp
->status
& 0x3ff) + 1;
110 if ((tmp
->link
& 1) || (tmp
->link
& 2))
112 tmp
= bus_to_virt(tmp
->link
& ~0xF);
117 return USB_ST_NOERROR
;
119 /* Some debugging code */
120 if (uhci_debug
/* && (!usb_pipeendpoint(tmp->info) || !(status & 0x08))*/ ) {
124 printk("uhci_td_result() failed with status %x\n", status
);
125 //show_status(dev->uhci);
128 if ((tmp
->link
& 1) || (tmp
->link
& 2))
130 tmp
= bus_to_virt(tmp
->link
& ~0xF);
137 /* endpoint has stalled - mark it halted */
139 usb_endpoint_halt(dev
->usb
, usb_pipeendpoint(tmp
->info
));
144 if (status
== 0x80) {
147 return USB_ST_DATAUNDERRUN
;
149 return uhci_map_status(status
, usb_pipeout(tmp
->info
));
153 * Inserts a td into qh list at the top.
155 * Careful about atomicity: even on UP this
156 * requires a locked access due to the concurrent
159 * NOTE! This assumes that first->last is a valid
160 * list of TD's with the proper backpointers set
163 static void uhci_insert_tds_in_qh(struct uhci_qh
*qh
, struct uhci_td
*first
, struct uhci_td
*last
)
165 unsigned int link
= qh
->element
;
166 unsigned int new = 4 | virt_to_bus(first
);
169 unsigned char success
;
172 first
->backptr
= &qh
->element
;
173 asm volatile("lock ; cmpxchg %4,%2 ; sete %0"
174 :"=q" (success
), "=a" (link
)
175 :"m" (qh
->element
), "1" (link
), "r" (new)
178 /* Was there a successor entry? Fix it's backpointer.. */
179 if ((link
& 1) == 0) {
180 struct uhci_td
*next
= bus_to_virt(link
& ~15);
181 next
->backptr
= &last
->link
;
188 static inline void uhci_insert_td_in_qh(struct uhci_qh
*qh
, struct uhci_td
*td
)
190 uhci_insert_tds_in_qh(qh
, td
, td
);
193 static void uhci_insert_qh(struct uhci_qh
*qh
, struct uhci_qh
*newqh
)
195 newqh
->link
= qh
->link
;
196 qh
->link
= virt_to_bus(newqh
) | 2;
199 static void uhci_remove_qh(struct uhci_qh
*qh
, struct uhci_qh
*remqh
)
201 unsigned int remphys
= virt_to_bus(remqh
);
202 struct uhci_qh
*lqh
= qh
;
204 while ((lqh
->link
& ~0xF) != remphys
) {
208 lqh
= bus_to_virt(lqh
->link
& ~0xF);
212 printk("couldn't find qh in chain!\n");
216 lqh
->link
= remqh
->link
;
220 * Removes td from qh if present.
222 * NOTE! We keep track of both forward and back-pointers,
223 * so this should be trivial, right?
225 * Wrong. While all TD insert/remove operations are synchronous
226 * on the CPU, the UHCI controller can (and does) play with the
227 * very first forward pointer. So we need to validate the backptr
228 * before we change it, so that we don't by mistake reset the QH
229 * head to something old.
231 static void uhci_remove_td(struct uhci_td
*td
)
233 unsigned int *backptr
= td
->backptr
;
234 unsigned int link
= td
->link
;
243 * This is the easy case: the UHCI will never change "td->link",
244 * so we can always just look at that and fix up the backpointer
245 * of any next element..
248 struct uhci_td
*next
= bus_to_virt(link
& ~15);
249 next
->backptr
= backptr
;
253 * The nasty case is "backptr->next", which we need to
254 * update to "link" _only_ if "backptr" still points
255 * to us (it may not: maybe backptr is a QH->element
256 * pointer and the UHCI has changed the value).
258 me
= virt_to_bus(td
) | (0xe & *backptr
);
259 asm volatile("lock ; cmpxchg %0,%1"
261 :"r" (link
), "m" (*backptr
), "a" (me
)
265 static struct uhci_qh
*uhci_qh_allocate(struct uhci_device
*dev
)
271 for (; (inuse
= test_and_set_bit(0, &qh
->inuse
)) != 0 && qh
< &dev
->qh
[UHCI_MAXQH
]; qh
++)
277 printk("ran out of qh's for dev %p\n", dev
);
281 static void uhci_qh_deallocate(struct uhci_qh
*qh
)
283 // if (qh->element != 1)
284 // printk("qh %p leaving dangling entries? (%X)\n", qh, qh->element);
289 clear_bit(0, &qh
->inuse
);
292 static struct uhci_td
*uhci_td_allocate(struct uhci_device
*dev
)
298 for (; (inuse
= test_and_set_bit(0, &td
->inuse
)) != 0 && td
< &dev
->td
[UHCI_MAXTD
]; td
++)
306 printk("ran out of td's for dev %p\n", dev
);
311 * This MUST only be called when it has been removed from a QH already (or
312 * the QH has been removed from the skeleton
314 static void uhci_td_deallocate(struct uhci_td
*td
)
318 clear_bit(0, &td
->inuse
);
322 * UHCI interrupt list operations..
324 static spinlock_t irqlist_lock
= SPIN_LOCK_UNLOCKED
;
326 static void uhci_add_irq_list(struct uhci
*uhci
, struct uhci_td
*td
, usb_device_irq completed
, void *dev_id
)
330 td
->completed
= completed
;
333 spin_lock_irqsave(&irqlist_lock
, flags
);
334 list_add(&td
->irq_list
, &uhci
->interrupt_list
);
335 spin_unlock_irqrestore(&irqlist_lock
, flags
);
338 static void uhci_remove_irq_list(struct uhci_td
*td
)
342 spin_lock_irqsave(&irqlist_lock
, flags
);
343 list_del(&td
->irq_list
);
344 spin_unlock_irqrestore(&irqlist_lock
, flags
);
349 * Request a interrupt handler..
351 * Returns: a "handle pointer" that release_irq can use to stop this
352 * interrupt. (It's really a pointer to the TD).
354 static void* uhci_request_irq(struct usb_device
*usb_dev
, unsigned int pipe
, usb_device_irq handler
, int period
, void *dev_id
)
356 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
357 struct uhci_device
*root_hub
=usb_to_uhci(dev
->uhci
->bus
->root_hub
);
358 struct uhci_td
*td
= uhci_td_allocate(dev
);
359 struct uhci_qh
*interrupt_qh
= uhci_qh_allocate(dev
);
361 unsigned int destination
, status
;
363 /* Destination: pipe destination with INPUT */
364 destination
= (pipe
& PIPE_DEVEP_MASK
) | 0x69;
366 /* Status: slow/fast, Interrupt, Active, Short Packet Detect Infinite Errors */
367 status
= (pipe
& (1 << 26)) | (1 << 24) | (1 << 23) | (1 << 29) | (0 << 27);
369 if(interrupt_qh
->element
!= 1)
370 printk("interrupt_qh->element = 0x%x\n",
371 interrupt_qh
->element
);
374 td
->status
= status
; /* In */
375 td
->info
= destination
| ((usb_maxpacket(usb_dev
, pipe
) - 1) << 21) |
376 (usb_gettoggle(usb_dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
)) << 19);
377 td
->buffer
= virt_to_bus(dev
->data
);
379 td
->qh
= interrupt_qh
;
382 /* if period 0, insert into fast q */
386 interrupt_qh
->skel
= &root_hub
->skel_int2_qh
;
388 interrupt_qh
->skel
= &root_hub
->skel_int8_qh
;
390 uhci_add_irq_list(dev
->uhci
, td
, handler
, dev_id
);
392 uhci_insert_td_in_qh(interrupt_qh
, td
);
394 /* Add it into the skeleton */
395 uhci_insert_qh(interrupt_qh
->skel
, interrupt_qh
);
401 * Remove running irq td from queues
403 * This function is not used anymore.
406 static int uhci_remove_irq(struct usb_device
*usb_dev
, unsigned int pipe
, usb_device_irq handler
, int period
, void *dev_id
)
408 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
409 struct uhci_device
*root_hub
=usb_to_uhci(dev
->uhci
->bus
->root_hub
);
411 struct uhci_qh
*interrupt_qh
;
413 struct list_head
*head
= &dev
->uhci
->interrupt_list
;
414 struct list_head
*tmp
;
416 spin_lock_irqsave(&irqlist_lock
, flags
);
418 /* find the TD in the interrupt list */
421 while (tmp
!= head
) {
422 td
= list_entry(tmp
, struct uhci_td
, irq_list
);
423 if (td
->dev_id
== dev_id
&& td
->completed
== handler
) {
425 /* found the right one - let's remove it */
429 td
->completed(USB_ST_REMOVED
, NULL
, 0, td
->dev_id
);
431 /* this is DANGEROUS - not sure whether this is right */
433 list_del(&td
->irq_list
);
435 interrupt_qh
= td
->qh
;
436 uhci_remove_qh(interrupt_qh
->skel
, interrupt_qh
);
437 uhci_td_deallocate(td
);
438 uhci_qh_deallocate(interrupt_qh
);
439 spin_unlock_irqrestore(&irqlist_lock
, flags
);
440 return USB_ST_NOERROR
;
443 spin_unlock_irqrestore(&irqlist_lock
, flags
);
444 return USB_ST_INTERNALERROR
;
449 * Release an interrupt handler previously allocated using
450 * uhci_request_irq. This function does no validity checking, so make
451 * sure you're not releasing an already released handle as it may be
452 * in use by something else..
454 * This function can NOT be called from an interrupt.
456 int uhci_release_irq(void* handle
)
459 struct uhci_qh
*interrupt_qh
;
463 printk("usb-uhci: Releasing irq handle %p\n", handle
);
466 td
= (struct uhci_td
*)handle
;
468 return USB_ST_INTERNALERROR
;
470 /* Remove it from the internal irq_list */
471 spin_lock_irqsave(&irqlist_lock
, flags
);
472 list_del(&td
->irq_list
);
473 spin_unlock_irqrestore(&irqlist_lock
, flags
);
475 /* Remove the interrupt TD and QH */
477 interrupt_qh
= td
->qh
;
478 uhci_remove_qh(interrupt_qh
->skel
, interrupt_qh
);
480 if (td
->completed
!= NULL
)
481 td
->completed(USB_ST_REMOVED
, NULL
, 0, td
->dev_id
);
483 /* Free the TD and QH */
484 uhci_td_deallocate(td
);
485 uhci_qh_deallocate(interrupt_qh
);
487 return USB_ST_NOERROR
;
488 } /* uhci_release_irq() */
492 * Isochronous thread operations
495 static int uhci_compress_isochronous(struct usb_device
*usb_dev
, void *_isodesc
)
497 struct uhci_iso_td
*isodesc
= (struct uhci_iso_td
*)_isodesc
;
498 char *data
= isodesc
->data
;
501 for (i
= 0; i
< isodesc
->num
; i
++) {
502 char *cdata
= bus_to_virt(isodesc
->td
[i
].buffer
& ~0xF);
503 int n
= (isodesc
->td
[i
].status
+ 1) & 0x7FF;
505 if ((cdata
!= data
) && (n
))
506 memmove(data
, cdata
, n
);
510 printk("underrun: %d %d\n", i
, n
);
512 if ((isodesc
->td
[i
].status
>> 16) & 0xFF)
513 printk("error: %d %X\n", i
, (isodesc
->td
[i
].status
>> 16));
522 static int uhci_unschedule_isochronous(struct usb_device
*usb_dev
, void *_isodesc
)
524 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
525 struct uhci
*uhci
= dev
->uhci
;
526 struct uhci_iso_td
*isodesc
= (struct uhci_iso_td
*)_isodesc
;
529 if ((isodesc
->frame
< 0) || (isodesc
->frame
> 1023))
532 /* Remove from previous frames */
533 for (i
= 0; i
< isodesc
->num
; i
++) {
534 /* Turn off Active and IOC bits */
535 isodesc
->td
[i
].status
&= ~(3 << 23);
536 uhci
->fl
->frame
[(isodesc
->frame
+ i
) % 1024] = isodesc
->td
[i
].link
;
544 /* td points to the one td we allocated for isochronous transfers */
545 static int uhci_schedule_isochronous(struct usb_device
*usb_dev
, void *_isodesc
, void *_pisodesc
)
547 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
548 struct uhci
*uhci
= dev
->uhci
;
549 struct uhci_iso_td
*isodesc
= (struct uhci_iso_td
*)_isodesc
;
550 struct uhci_iso_td
*pisodesc
= (struct uhci_iso_td
*)_pisodesc
;
553 if (isodesc
->frame
!= -1) {
554 printk("isoc queue not removed\n");
555 uhci_unschedule_isochronous(usb_dev
, isodesc
);
558 /* Insert TD into list */
560 frame
= inw(uhci
->io_addr
+ USBFRNUM
) % 1024;
561 /* HACK: Start 2 frames from now */
562 frame
= (frame
+ 2) % 1024;
564 frame
= (pisodesc
->endframe
+ 1) % 1024;
567 printk("scheduling first at frame %d\n", frame
);
570 for (i
= 0; i
< isodesc
->num
; i
++) {
572 isodesc
->td
[i
].status
|= (1 << 23);
573 isodesc
->td
[i
].backptr
= &uhci
->fl
->frame
[(frame
+ i
) % 1024];
574 isodesc
->td
[i
].link
= uhci
->fl
->frame
[(frame
+ i
) % 1024];
575 uhci
->fl
->frame
[(frame
+ i
) % 1024] = virt_to_bus(&isodesc
->td
[i
]);
579 printk("last at frame %d\n", (frame
+ i
- 1) % 1024);
583 isodesc
->td
[i
- 1].status
|= (1 << 24);
585 isodesc
->frame
= frame
;
586 isodesc
->endframe
= (frame
+ isodesc
->num
- 1) % 1024;
589 return uhci_td_result(dev
, td
[num
- 1]);
595 * Initialize isochronous queue
597 static void *uhci_allocate_isochronous(struct usb_device
*usb_dev
, unsigned int pipe
, void *data
, int len
, int maxsze
, usb_device_irq completed
, void *dev_id
)
599 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
600 unsigned long destination
, status
;
602 struct uhci_iso_td
*isodesc
;
605 isodesc
= kmalloc(sizeof(*isodesc
), GFP_KERNEL
);
607 printk("Couldn't allocate isodesc!\n");
610 memset(isodesc
, 0, sizeof(*isodesc
));
612 /* Carefully work around the non contiguous pages */
613 isodesc
->num
= (len
/ PAGE_SIZE
) * (PAGE_SIZE
/ maxsze
);
614 isodesc
->td
= kmalloc(sizeof(struct uhci_td
) * isodesc
->num
, GFP_KERNEL
);
615 isodesc
->frame
= isodesc
->endframe
= -1;
616 isodesc
->data
= data
;
617 isodesc
->maxsze
= maxsze
;
620 printk("Couldn't allocate td's\n");
625 isodesc
->frame
= isodesc
->endframe
= -1;
628 * Build the DATA TD's
632 /* Build the TD for control status */
633 td
= &isodesc
->td
[i
];
635 /* The "pipe" thing contains the destination in bits 8--18 */
636 destination
= (pipe
& PIPE_DEVEP_MASK
);
638 if (usb_pipeout(pipe
))
639 destination
|= 0xE1; /* OUT */
641 destination
|= 0x69; /* IN */
643 /* Status: slow/fast, Active, Isochronous */
644 status
= (pipe
& (1 << 26)) | (1 << 23) | (1 << 25);
647 * Build the TD for the control request
650 td
->info
= destination
| ((maxsze
- 1) << 21);
651 td
->buffer
= virt_to_bus(data
);
659 if (((int)data
% PAGE_SIZE
) + maxsze
>= PAGE_SIZE
)
660 data
= (char *)(((int)data
+ maxsze
) & ~(PAGE_SIZE
- 1));
663 } while (i
< isodesc
->num
);
665 /* IOC on the last TD */
666 td
->status
|= (1 << 24);
667 uhci_add_irq_list(dev
->uhci
, td
, completed
, dev_id
);
672 static void uhci_delete_isochronous(struct usb_device
*usb_dev
, void *_isodesc
)
674 struct uhci_iso_td
*isodesc
= (struct uhci_iso_td
*)_isodesc
;
676 /* If it's still scheduled, unschedule them */
678 uhci_unschedule_isochronous(usb_dev
, isodesc
);
680 /* Remove it from the IRQ list */
681 uhci_remove_irq_list(&isodesc
->td
[isodesc
->num
- 1]);
688 * Control thread operations: we just mark the last TD
689 * in a control thread as an interrupt TD, and wake up
690 * the front-end on completion.
692 * We need to remove the TD from the lists (both interrupt
693 * list and TD lists) by hand if something bad happens!
695 static DECLARE_WAIT_QUEUE_HEAD(control_wakeup
);
697 static int uhci_control_completed(int status
, void *buffer
, int len
, void *dev_id
)
699 wake_up(&control_wakeup
);
700 return 0; /* Don't re-instate */
703 /* td points to the last td in the list, which interrupts on completion */
704 static int uhci_run_control(struct uhci_device
*dev
, struct uhci_td
*first
, struct uhci_td
*last
)
706 DECLARE_WAITQUEUE(wait
, current
);
707 struct uhci_qh
*ctrl_qh
= uhci_qh_allocate(dev
);
708 struct uhci_td
*curtd
;
709 struct uhci_device
*root_hub
=usb_to_uhci(dev
->uhci
->bus
->root_hub
);
710 current
->state
= TASK_UNINTERRUPTIBLE
;
711 add_wait_queue(&control_wakeup
, &wait
);
713 uhci_add_irq_list(dev
->uhci
, last
, uhci_control_completed
, NULL
);
715 /* FIXME: This is kinda kludged */
716 /* Walk the TD list and update the QH pointer */
726 curtd
= bus_to_virt(curtd
->link
& ~0xF);
728 printk("runaway tds!\n");
734 uhci_insert_tds_in_qh(ctrl_qh
, first
, last
);
736 /* Add it into the skeleton */
737 uhci_insert_qh(&root_hub
->skel_control_qh
, ctrl_qh
);
739 // control should be full here...
740 // printk("control\n");
741 // show_status(dev->uhci);
742 // show_queues(dev->uhci);
744 schedule_timeout(HZ
*5);
746 // control should be empty here...
747 // show_status(dev->uhci);
748 // show_queues(dev->uhci);
750 remove_wait_queue(&control_wakeup
, &wait
);
752 /* Clean up in case it failed.. */
753 uhci_remove_irq_list(last
);
756 printk("Looking for tds [%p, %p]\n", dev
->control_td
, td
);
759 /* Remove it from the skeleton */
760 uhci_remove_qh(&root_hub
->skel_control_qh
, ctrl_qh
);
762 uhci_qh_deallocate(ctrl_qh
);
764 return uhci_td_result(dev
, last
, NULL
);
768 * Send or receive a control message on a pipe.
770 * Note that the "pipe" structure is set up to map
771 * easily to the uhci destination fields.
773 * A control message is built up from three parts:
774 * - The command itself
775 * - [ optional ] data phase
776 * - Status complete phase
778 * The data phase can be an arbitrary number of TD's
779 * although we currently had better not have more than
780 * 29 TD's here (we have 31 TD's allocated for control
781 * operations, and two of them are used for command and
784 * 29 TD's is a minimum of 232 bytes worth of control
785 * information, that's just ridiculously high. Most
786 * control messages have just a few bytes of data.
788 static int uhci_control_msg(struct usb_device
*usb_dev
, unsigned int pipe
, devrequest
*cmd
, void *data
, int len
)
790 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
791 struct uhci_td
*first
, *td
, *prevtd
;
792 unsigned long destination
, status
;
794 int maxsze
= usb_maxpacket(usb_dev
, pipe
);
796 if (len
> maxsze
* 29)
797 printk("Warning, too much data for a control packet, crashing\n");
799 first
= td
= uhci_td_allocate(dev
);
801 /* The "pipe" thing contains the destination in bits 8--18, 0x2D is SETUP */
802 destination
= (pipe
& PIPE_DEVEP_MASK
) | 0x2D;
804 /* Status: slow/fast, Active, Short Packet Detect Three Errors */
805 status
= (pipe
& (1 << 26)) | (1 << 23) | (1 << 29) | (3 << 27);
808 * Build the TD for the control request
810 td
->status
= status
; /* Try forever */
811 td
->info
= destination
| (7 << 21); /* 8 bytes of data */
812 td
->buffer
= virt_to_bus(cmd
);
816 * If direction is "send", change the frame from SETUP (0x2D)
817 * to OUT (0xE1). Else change it from SETUP to IN (0x69)
819 destination
^= (0x2D ^ 0x69); /* SETUP -> IN */
820 if (usb_pipeout(pipe
))
821 destination
^= (0xE1 ^ 0x69); /* IN -> OUT */
824 td
= uhci_td_allocate(dev
);
825 prevtd
->link
= 4 | virt_to_bus(td
);
828 * Build the DATA TD's
831 /* Build the TD for control status */
837 /* Alternate Data0/1 (start with Data1) */
838 destination
^= 1 << 19;
840 td
->status
= status
; /* Status */
841 td
->info
= destination
| ((pktsze
-1) << 21); /* pktsze bytes of data */
842 td
->buffer
= virt_to_bus(data
);
844 td
->backptr
= &prevtd
->link
;
850 td
= uhci_td_allocate(dev
);
851 prevtd
->link
= 4 | virt_to_bus(td
); /* Update previous TD */
856 * Build the final TD for control status
858 destination
^= (0xE1 ^ 0x69); /* OUT -> IN */
859 destination
|= 1 << 19; /* End in Data1 */
861 td
->backptr
= &prevtd
->link
;
862 td
->status
= (status
/* & ~(3 << 27) */) | (1 << 24); /* no limit on final packet */
863 td
->info
= destination
| (UHCI_NULL_DATA_SIZE
<< 21); /* 0 bytes of data */
866 td
->link
= 1; /* Terminate */
870 ret
= uhci_run_control(dev
, first
, td
);
874 struct uhci_td
*curtd
= first
;
875 unsigned int nextlink
;
878 nextlink
= curtd
->link
;
879 uhci_remove_td(curtd
);
880 uhci_td_deallocate(curtd
);
881 if (nextlink
& 1) /* Tail? */
884 curtd
= bus_to_virt(nextlink
& ~0xF);
886 printk("runaway td's!?\n");
892 if (uhci_debug
&& ret
) {
893 __u8
*p
= (__u8
*)cmd
;
895 printk("Failed cmd - %02X %02X %02X %02X %02X %02X %02X %02X\n",
896 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6], p
[7]);
903 * Bulk thread operations: we just mark the last TD
904 * in a bulk thread as an interrupt TD, and wake up
905 * the front-end on completion.
907 * We need to remove the TD from the lists (both interrupt
908 * list and TD lists) by hand if something bad happens!
910 static DECLARE_WAIT_QUEUE_HEAD(bulk_wakeup
);
912 static int uhci_bulk_completed(int status
, void *buffer
, int len
, void *dev_id
)
914 wake_up(&bulk_wakeup
);
915 return 0; /* Don't re-instate */
918 /* td points to the last td in the list, which interrupts on completion */
919 static int uhci_run_bulk(struct uhci_device
*dev
, struct uhci_td
*first
, struct uhci_td
*last
, unsigned long *rval
)
921 DECLARE_WAITQUEUE(wait
, current
);
922 struct uhci_qh
*bulk_qh
= uhci_qh_allocate(dev
);
923 struct uhci_td
*curtd
;
924 struct uhci_device
*root_hub
=usb_to_uhci(dev
->uhci
->bus
->root_hub
);
926 current
->state
= TASK_UNINTERRUPTIBLE
;
927 add_wait_queue(&bulk_wakeup
, &wait
);
929 uhci_add_irq_list(dev
->uhci
, last
, uhci_bulk_completed
, NULL
);
931 /* FIXME: This is kinda kludged */
932 /* Walk the TD list and update the QH pointer */
942 curtd
= bus_to_virt(curtd
->link
& ~0xF);
944 printk("runaway tds!\n");
950 uhci_insert_tds_in_qh(bulk_qh
, first
, last
);
952 /* Add it into the skeleton */
953 uhci_insert_qh(&root_hub
->skel_bulk0_qh
, bulk_qh
);
955 // now we're in the queue... but don't ask WHAT is in there ;-(
957 // show_status(dev->uhci);
958 // show_queues(dev->uhci);
960 schedule_timeout(HZ
*5);
961 // show_status(dev->uhci);
962 // show_queues(dev->uhci);
964 //show_queue(first->qh);
965 remove_wait_queue(&bulk_wakeup
, &wait
);
967 /* Clean up in case it failed.. */
968 uhci_remove_irq_list(last
);
971 printk("Looking for tds [%p, %p]\n", dev
->control_td
, td
);
974 /* Remove it from the skeleton */
975 uhci_remove_qh(&root_hub
->skel_bulk0_qh
, bulk_qh
);
977 uhci_qh_deallocate(bulk_qh
);
979 return uhci_td_result(dev
, last
, rval
);
983 * Send or receive a bulk message on a pipe.
985 * Note that the "pipe" structure is set up to map
986 * easily to the uhci destination fields.
988 * A bulk message is only built up from
991 * The data phase can be an arbitrary number of TD's
992 * although we currently had better not have more than
995 * 31 TD's is a minimum of 248 bytes worth of bulk
998 static int uhci_bulk_msg(struct usb_device
*usb_dev
, unsigned int pipe
, void *data
, int len
, unsigned long *rval
)
1000 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
1001 struct uhci_td
*first
, *td
, *prevtd
;
1002 unsigned long destination
, status
;
1004 int maxsze
= usb_maxpacket(usb_dev
, pipe
);
1006 if (usb_endpoint_halted(usb_dev
, usb_pipeendpoint(pipe
)) &&
1007 usb_clear_halt(usb_dev
, usb_pipeendpoint(pipe
) | (pipe
& 0x80)))
1008 return USB_ST_STALL
;
1010 if (len
> maxsze
* 31)
1011 printk("Warning, too much data for a bulk packet, crashing (%d/%d)\n", len
, maxsze
);
1013 /* The "pipe" thing contains the destination in bits 8--18, 0x69 is IN */
1015 IS THIS NECCESARY? PERHAPS WE CAN JUST USE THE PIPE
1016 LOOK AT: usb_pipeout and the pipe bits
1017 I FORGOT WHAT IT EXACTLY DOES
1019 if (usb_pipeout(pipe
)) {
1020 destination
= (pipe
& PIPE_DEVEP_MASK
) | 0xE1;
1023 destination
= (pipe
& PIPE_DEVEP_MASK
) | 0x69;
1026 /* Status: slow/fast, Active, Short Packet Detect Three Errors */
1027 status
= (pipe
& (1 << 26)) | (1 << 23) | (1 << 29) | (3 << 27);
1030 * Build the TDs for the bulk request
1032 first
= td
= uhci_td_allocate(dev
);
1033 prevtd
= first
; //This is fake, but at least it's not NULL
1035 /* Build the TD for control status */
1038 if (pktsze
> maxsze
)
1041 td
->status
= status
; /* Status */
1042 td
->info
= destination
| ((pktsze
-1) << 21) |
1043 (usb_gettoggle(usb_dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
)) << 19); /* pktsze bytes of data */
1044 td
->buffer
= virt_to_bus(data
);
1045 td
->backptr
= &prevtd
->link
;
1053 td
= uhci_td_allocate(dev
);
1054 prevtd
->link
= 4 | virt_to_bus(td
); /* Update previous TD */
1057 /* Alternate Data0/1 (start with Data0) */
1058 usb_dotoggle(usb_dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
));
1060 td
->link
= 1; /* Terminate */
1061 td
->status
|= (1 << 24); /* IOC */
1063 /* CHANGE DIRECTION HERE! SAVE IT SOMEWHERE IN THE ENDPOINT!!! */
1066 ret
= uhci_run_bulk(dev
, first
, td
, rval
);
1070 struct uhci_td
*curtd
= first
;
1071 unsigned int nextlink
;
1074 nextlink
= curtd
->link
;
1075 uhci_remove_td(curtd
);
1076 uhci_td_deallocate(curtd
);
1077 if (nextlink
& 1) /* Tail? */
1080 curtd
= bus_to_virt(nextlink
& ~0xF);
1082 printk("runaway td's!?\n");
1091 static struct usb_device
*uhci_usb_allocate(struct usb_device
*parent
)
1093 struct usb_device
*usb_dev
;
1094 struct uhci_device
*dev
;
1097 usb_dev
= kmalloc(sizeof(*usb_dev
), GFP_KERNEL
);
1101 memset(usb_dev
, 0, sizeof(*usb_dev
));
1103 dev
= kmalloc(sizeof(*dev
), GFP_KERNEL
);
1105 usb_destroy_configuration(usb_dev
);
1110 /* Initialize "dev" */
1111 memset(dev
, 0, sizeof(*dev
));
1113 usb_dev
->hcpriv
= dev
;
1116 usb_dev
->parent
= parent
;
1119 usb_dev
->bus
= parent
->bus
;
1120 dev
->uhci
= usb_to_uhci(parent
)->uhci
;
1123 /* Reset the QH's and TD's */
1124 for (i
= 0; i
< UHCI_MAXQH
; i
++) {
1125 dev
->qh
[i
].link
= 1;
1126 dev
->qh
[i
].element
= 1;
1127 dev
->qh
[i
].inuse
= 0;
1130 for (i
= 0; i
< UHCI_MAXTD
; i
++) {
1131 dev
->td
[i
].link
= 1;
1132 dev
->td
[i
].inuse
= 0;
1138 static int uhci_usb_deallocate(struct usb_device
*usb_dev
)
1140 struct uhci_device
*dev
= usb_to_uhci(usb_dev
);
1143 /* There are UHCI_MAXTD preallocated tds */
1144 for (i
= 0; i
< UHCI_MAXTD
; ++i
) {
1145 struct uhci_td
*td
= dev
->td
+ i
;
1147 if (td
->inuse
& 1) {
1150 /* And remove it from the irq list, if it's active */
1151 if (td
->status
& (1 << 23))
1152 td
->status
&= ~(1 << 23);
1154 uhci_remove_irq_list(td
);
1159 /* Remove the td from any queues */
1160 for (i
= 0; i
< UHCI_MAXQH
; ++i
) {
1161 struct uhci_qh
*qh
= dev
->qh
+ i
;
1164 uhci_remove_qh(qh
->skel
, qh
);
1168 usb_destroy_configuration(usb_dev
);
1174 struct usb_operations uhci_device_operations
= {
1176 uhci_usb_deallocate
,
1181 uhci_allocate_isochronous
,
1182 uhci_delete_isochronous
,
1183 uhci_schedule_isochronous
,
1184 uhci_unschedule_isochronous
,
1185 uhci_compress_isochronous
1189 * This is just incredibly fragile. The timings must be just
1190 * right, and they aren't really documented very well.
1192 * Note the short delay between disabling reset and enabling
1195 static void uhci_reset_port(unsigned int port
)
1197 unsigned short status
;
1200 outw(status
| USBPORTSC_PR
, port
); /* reset port */
1202 outw(status
& ~USBPORTSC_PR
, port
);
1206 outw(status
| USBPORTSC_PE
, port
); /* enable port */
1210 if(!(status
& USBPORTSC_PE
)) {
1211 outw(status
| USBPORTSC_PE
, port
); /* one more try at enabling port */
1219 * This gets called if the connect status on the root
1220 * hub (and the root hub only) changes.
1222 static void uhci_connect_change(struct uhci
*uhci
, unsigned int port
, unsigned int nr
)
1224 struct usb_device
*usb_dev
;
1225 struct uhci_device
*dev
;
1226 unsigned short status
;
1227 struct uhci_device
*root_hub
=usb_to_uhci(uhci
->bus
->root_hub
);
1228 printk("uhci_connect_change: called for %d\n", nr
);
1231 * Even if the status says we're connected,
1232 * the fact that the status bits changed may
1233 * that we got disconnected and then reconnected.
1235 * So start off by getting rid of any old devices..
1237 usb_disconnect(&root_hub
->usb
->children
[nr
]);
1241 /* If we have nothing connected, then clear change status and disable the port */
1242 status
= (status
& ~USBPORTSC_PE
) | USBPORTSC_PEC
;
1243 if (!(status
& USBPORTSC_CCS
)) {
1249 * Ok, we got a new connection. Allocate a device to it,
1250 * and find out what it wants to do..
1252 usb_dev
= uhci_usb_allocate(root_hub
->usb
);
1256 dev
= usb_dev
->hcpriv
;
1260 usb_connect(usb_dev
);
1262 root_hub
->usb
->children
[nr
] = usb_dev
;
1264 wait_ms(200); /* wait for powerup */
1265 uhci_reset_port(port
);
1267 /* Get speed information */
1268 usb_dev
->slow
= (inw(port
) & USBPORTSC_LSDA
) ? 1 : 0;
1271 * Ok, all the stuff specific to the root hub has been done.
1272 * The rest is generic for any new USB attach, regardless of
1275 usb_new_device(usb_dev
);
1279 * This gets called when the root hub configuration
1280 * has changed. Just go through each port, seeing if
1281 * there is something interesting happening.
1283 static void uhci_check_configuration(struct uhci
*uhci
)
1285 struct uhci_device
* root_hub
=usb_to_uhci(uhci
->bus
->root_hub
);
1286 unsigned int io_addr
= uhci
->io_addr
+ USBPORTSC1
;
1287 int maxchild
= root_hub
->usb
->maxchild
;
1291 unsigned short status
= inw(io_addr
);
1293 if (status
& USBPORTSC_CSC
)
1294 uhci_connect_change(uhci
, io_addr
, nr
);
1297 } while (nr
< maxchild
);
1300 static void uhci_interrupt_notify(struct uhci
*uhci
)
1302 struct list_head
*head
= &uhci
->interrupt_list
;
1303 struct list_head
*tmp
;
1306 spin_lock(&irqlist_lock
);
1308 while (tmp
!= head
) {
1309 struct uhci_td
*td
= list_entry(tmp
, struct uhci_td
, irq_list
);
1310 struct list_head
*next
;
1314 if (!((status
= td
->status
) & (1 << 23)) || /* No longer active? */
1315 ((td
->qh
->element
& ~15) &&
1316 !((status
= uhci_link_to_td(td
->qh
->element
)->status
) & (1 <<23)) &&
1317 (status
& 0x760000) /* is in error state (Stall, db, babble, timeout, bitstuff) */)) {
1318 /* remove from IRQ list */
1319 __list_del(tmp
->prev
, next
);
1320 INIT_LIST_HEAD(tmp
);
1321 if (td
->completed(uhci_map_status(status
, 0), bus_to_virt(td
->buffer
), -1, td
->dev_id
)) {
1322 list_add(&td
->irq_list
, &uhci
->interrupt_list
);
1324 if (!(td
->status
& (1 << 25))) {
1325 struct uhci_qh
*interrupt_qh
= td
->qh
;
1327 usb_dotoggle(td
->dev
, usb_pipeendpoint(td
->info
), usb_pipeout(td
->info
));
1328 td
->info
&= ~(1 << 19); /* clear data toggle */
1329 td
->info
|= usb_gettoggle(td
->dev
, usb_pipeendpoint(td
->info
), usb_pipeout(td
->info
)) << 19; /* toggle between data0 and data1 */
1330 td
->status
= (td
->status
& 0x2f000000) | (1 << 23) | (1 << 24); /* active */
1332 /* Remove then readd? Is that necessary */
1334 uhci_insert_td_in_qh(interrupt_qh
, td
);
1336 } else if (td
->inuse
& 2) {
1337 struct uhci_qh
*interrupt_qh
= td
->qh
;
1338 /* marked for removal */
1340 usb_dotoggle(td
->dev
, usb_pipeendpoint(td
->info
), usb_pipeout(td
->info
));
1341 uhci_remove_qh(interrupt_qh
->skel
, interrupt_qh
);
1342 uhci_qh_deallocate(interrupt_qh
);
1343 uhci_td_deallocate(td
);
1345 /* If completed wants to not reactivate, then it's */
1346 /* responsible for free'ing the TD's and QH's */
1347 /* or another function (such as run_control) */
1351 spin_unlock(&irqlist_lock
);
1355 * Check port status - Connect Status Change - for
1356 * each of the attached ports (defaults to two ports,
1357 * but at least in theory there can be more of them).
1359 * Wake up the configurator if something happened, we
1360 * can't really do much at interrupt time.
1362 static void uhci_root_hub_events(struct uhci
*uhci
, unsigned int io_addr
)
1364 if (waitqueue_active(&uhci_configure
)) {
1365 struct uhci_device
* root_hub
=usb_to_uhci(uhci
->bus
->root_hub
);
1366 int ports
= root_hub
->usb
->maxchild
;
1367 io_addr
+= USBPORTSC1
;
1369 if (inw(io_addr
) & USBPORTSC_CSC
) {
1370 wake_up(&uhci_configure
);
1374 } while (--ports
> 0);
1378 static void uhci_interrupt(int irq
, void *__uhci
, struct pt_regs
*regs
)
1380 struct uhci
*uhci
= __uhci
;
1381 unsigned int io_addr
= uhci
->io_addr
;
1382 unsigned short status
;
1385 * Read the interrupt status, and write it back to clear the interrupt cause
1387 status
= inw(io_addr
+ USBSTS
);
1388 outw(status
, io_addr
+ USBSTS
);
1390 // if ((status & ~0x21) != 0)
1391 // printk("interrupt: %X\n", status);
1393 /* Walk the list of pending TD's to see which ones completed.. */
1394 uhci_interrupt_notify(uhci
);
1396 /* Check if there are any events on the root hub.. */
1397 uhci_root_hub_events(uhci
, io_addr
);
1401 * We init one packet, and mark it just IOC and _not_
1402 * active. Which will result in no actual USB traffic,
1403 * but _will_ result in an interrupt every second.
1405 * Which is exactly what we want.
1407 static void uhci_init_ticktd(struct uhci
*uhci
)
1409 struct uhci_device
*dev
= usb_to_uhci(uhci
->bus
->root_hub
);
1410 struct uhci_td
*td
= uhci_td_allocate(dev
);
1413 td
->status
= (1 << 24); /* interrupt on completion */
1414 td
->info
= (15 << 21) | 0x7f69; /* (ignored) input packet, 16 bytes, device 127 */
1419 uhci
->fl
->frame
[0] = virt_to_bus(td
);
1422 static void reset_hc(struct uhci
*uhci
)
1424 unsigned int io_addr
= uhci
->io_addr
;
1426 /* Global reset for 50ms */
1427 outw(USBCMD_GRESET
, io_addr
+USBCMD
);
1429 outw(0, io_addr
+USBCMD
);
1433 static void start_hc(struct uhci
*uhci
)
1435 unsigned int io_addr
= uhci
->io_addr
;
1438 uhci_init_ticktd(uhci
);
1441 * Reset the HC - this will force us to get a
1442 * new notification of any already connected
1443 * ports due to the virtual disconnect that it
1446 outw(USBCMD_HCRESET
, io_addr
+ USBCMD
);
1447 while (inw(io_addr
+ USBCMD
) & USBCMD_HCRESET
) {
1449 printk("USBCMD_HCRESET timed out!\n");
1455 outw(USBINTR_TIMEOUT
| USBINTR_RESUME
| USBINTR_IOC
| USBINTR_SP
, io_addr
+ USBINTR
);
1456 outw(0, io_addr
+ USBFRNUM
);
1457 outl(virt_to_bus(uhci
->fl
), io_addr
+ USBFLBASEADD
);
1459 /* Run and mark it configured with a 64-byte max packet */
1460 outw(USBCMD_RS
| USBCMD_CF
| USBCMD_MAXP
, io_addr
+ USBCMD
);
1464 * Allocate a frame list, and four regular queues.
1466 * The hardware doesn't really know any difference
1467 * in the queues, but the order does matter for the
1468 * protocols higher up. The order is:
1470 * - any isochronous events handled before any
1471 * of the queues. We don't do that here, because
1472 * we'll create the actual TD entries on demand.
1473 * - The first queue is the "interrupt queue".
1474 * - The second queue is the "control queue".
1475 * - The third queue is "bulk data".
1477 * We could certainly have multiple queues of the same
1478 * type, and maybe we should. We could have per-device
1479 * queues, for example. We begin small.
1481 static struct uhci
*alloc_uhci(unsigned int io_addr
)
1485 struct usb_bus
*bus
;
1486 struct uhci_device
*dev
;
1487 struct usb_device
*usb
;
1489 uhci
= kmalloc(sizeof(*uhci
), GFP_KERNEL
);
1493 memset(uhci
, 0, sizeof(*uhci
));
1496 uhci
->io_addr
= io_addr
;
1497 INIT_LIST_HEAD(&uhci
->interrupt_list
);
1499 /* We need exactly one page (per UHCI specs), how convenient */
1500 uhci
->fl
= (void *)__get_free_page(GFP_KERNEL
);
1504 bus
= kmalloc(sizeof(*bus
), GFP_KERNEL
);
1508 memset(bus
, 0, sizeof(*bus
));
1512 bus
->op
= &uhci_device_operations
;
1515 * We allocate a 8kB area for the UHCI hub. The area
1516 * is described by the uhci_device structure, and basically
1517 * contains everything needed for normal operation.
1519 * The first page is the actual device descriptor for the
1522 * The second page is used for the frame list.
1524 usb
= uhci_usb_allocate(NULL
);
1529 dev
= usb_to_uhci(usb
);
1530 uhci
->bus
->root_hub
=uhci_to_usb(dev
);
1531 /* Initialize the root hub */
1532 /* UHCI specs says devices must have 2 ports, but goes on to say */
1533 /* they may have more but give no way to determine how many they */
1534 /* have, so default to 2 */
1536 usb_init_root_hub(usb
);
1539 * Initialize the queues. They all start out empty,
1540 * linked to each other in the proper order.
1542 for (i
= 1 ; i
< 9; i
++) {
1543 dev
->qh
[i
].link
= 2 | virt_to_bus(&dev
->skel_control_qh
);
1544 dev
->qh
[i
].element
= 1;
1547 dev
->skel_control_qh
.link
= 2 | virt_to_bus(&dev
->skel_bulk0_qh
);
1548 dev
->skel_control_qh
.element
= 1;
1550 dev
->skel_bulk0_qh
.link
= 2 | virt_to_bus(&dev
->skel_bulk1_qh
);
1551 dev
->skel_bulk0_qh
.element
= 1;
1553 dev
->skel_bulk1_qh
.link
= 2 | virt_to_bus(&dev
->skel_bulk2_qh
);
1554 dev
->skel_bulk1_qh
.element
= 1;
1556 dev
->skel_bulk2_qh
.link
= 2 | virt_to_bus(&dev
->skel_bulk3_qh
);
1557 dev
->skel_bulk2_qh
.element
= 1;
1559 dev
->skel_bulk3_qh
.link
= 1;
1560 dev
->skel_bulk3_qh
.element
= 1;
1563 * Fill the frame list: make all entries point to
1564 * the proper interrupt queue.
1566 * This is probably silly, but it's a simple way to
1567 * scatter the interrupt queues in a way that gives
1568 * us a reasonable dynamic range for irq latencies.
1570 for (i
= 0; i
< 1024; i
++) {
1571 struct uhci_qh
* irq
= &dev
->skel_int2_qh
;
1593 uhci
->fl
->frame
[i
] = 2 | virt_to_bus(irq
);
1605 free_page ((unsigned long)uhci
->fl
);
1613 * De-allocate all resources..
1615 static void release_uhci(struct uhci
*uhci
)
1617 if (uhci
->irq
>= 0) {
1618 free_irq(uhci
->irq
, uhci
);
1623 if (uhci
->bus
->root_hub
) {
1624 uhci_usb_deallocate(uhci_to_usb(uhci
->bus
->root_hub
));
1625 uhci
->bus
->root_hub
= NULL
;
1630 free_page((unsigned long)uhci
->fl
);
1638 static int uhci_control_thread(void * __uhci
)
1640 struct uhci
*uhci
= (struct uhci
*)__uhci
;
1641 struct uhci_device
* root_hub
=usb_to_uhci(uhci
->bus
->root_hub
);
1644 request_region(uhci
->io_addr
, 32, "usb-uhci");
1647 * This thread doesn't need any user-level access,
1648 * so get rid of all our resources..
1650 printk("uhci_control_thread at %p\n", &uhci_control_thread
);
1652 exit_files(current
);
1655 strcpy(current
->comm
, "uhci-control");
1658 * Ok, all systems are go..
1661 usb_register_bus(uhci
->bus
);
1664 int unsigned long signr
;
1666 interruptible_sleep_on(&uhci_configure
);
1674 uhci_check_configuration(uhci
);
1676 if(signal_pending(current
)) {
1677 /* sending SIGUSR1 makes us print out some info */
1678 spin_lock_irq(¤t
->sigmask_lock
);
1679 signr
= dequeue_signal(¤t
->blocked
, &info
);
1680 spin_unlock_irq(¤t
->sigmask_lock
);
1682 if(signr
== SIGUSR1
) {
1683 printk("UHCI queue dump:\n");
1685 } else if (signr
== SIGUSR2
) {
1686 uhci_debug
= !uhci_debug
;
1687 printk("UHCI debug toggle = %x\n", uhci_debug
);
1697 for(i
= 0; i
< root_hub
->usb
->maxchild
; i
++)
1698 usb_disconnect(root_hub
->usb
->children
+ i
);
1701 usb_deregister_bus(uhci
->bus
);
1704 release_region(uhci
->io_addr
, 32);
1709 printk("uhci_control_thread exiting\n");
1715 * If we've successfully found a UHCI, now is the time to increment the
1716 * module usage count, start the control thread, and return success..
1718 static int found_uhci(int irq
, unsigned int io_addr
)
1723 uhci
= alloc_uhci(io_addr
);
1730 if (request_irq(irq
, uhci_interrupt
, SA_SHIRQ
, "usb", uhci
) == 0) {
1734 pid
= kernel_thread(uhci_control_thread
, uhci
,
1735 CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
1746 static int start_uhci(struct pci_dev
*dev
)
1750 /* Search for the IO base address.. */
1751 for (i
= 0; i
< 6; i
++) {
1752 unsigned int io_addr
= dev
->base_address
[i
];
1758 io_addr
&= PCI_BASE_ADDRESS_IO_MASK
;
1760 /* Is it already in use? */
1761 if (check_region(io_addr
, 32))
1764 return found_uhci(dev
->irq
, io_addr
);
1770 static int handle_apm_event(apm_event_t event
)
1772 static int down
= 0;
1775 case APM_SYS_SUSPEND
:
1776 case APM_USER_SUSPEND
:
1778 printk(KERN_DEBUG
"uhci: received extra suspend event\n");
1783 case APM_NORMAL_RESUME
:
1784 case APM_CRITICAL_RESUME
:
1786 printk(KERN_DEBUG
"uhci: received bogus resume event\n");
1790 if (waitqueue_active(&uhci_configure
)) {
1792 wake_up(&uhci_configure
);
1804 struct pci_dev
*dev
= NULL
;
1809 dev
= pci_find_class(PCI_CLASS_SERIAL_USB
<<8, dev
);
1813 pci_read_config_byte(dev
, PCI_CLASS_PROG
, &type
);
1817 retval
= start_uhci(dev
);
1822 apm_register_callback(&handle_apm_event
);
1830 int init_module(void)
1835 void cleanup_module(void)
1838 apm_unregister_callback(&handle_apm_event
);