25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/errno.h>
42 #include <linux/bitops.h>
45 #include <asm/uaccess.h>
54 #define DRIVER_AUTHOR \
55 "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, " \
56 "Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, " \
57 "Roman Weissgaerber, Alan Stern"
58 #define DRIVER_DESC "USB Universal Host Controller Interface driver"
61 static bool ignore_oc;
73 #define DEBUG_CONFIGURED 1
79 #define DEBUG_CONFIGURED 0
84 #define ERRBUF_LEN (32 * 1024)
89 static void wakeup_rh(
struct uhci_hcd *uhci);
90 static void uhci_get_current_frame_number(
struct uhci_hcd *uhci);
127 static void finish_reset(
struct uhci_hcd *uhci)
136 uhci_writew(uhci, 0,
USBPORTSC1 + (port * 2));
148 static void uhci_hc_died(
struct uhci_hcd *uhci)
150 uhci_get_current_frame_number(uhci);
164 static void check_and_reset_hc(
struct uhci_hcd *uhci)
170 #if defined(CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC)
181 static void uhci_generic_reset_hc(
struct uhci_hcd *uhci)
198 uhci_writew(uhci, 0,
USBCMD);
207 static int uhci_generic_check_and_reset_hc(
struct uhci_hcd *uhci)
221 cmd = uhci_readw(uhci,
USBCMD);
228 intr = uhci_readw(uhci,
USBINTR);
238 uhci_generic_reset_hc(uhci);
246 static void configure_hc(
struct uhci_hcd *uhci)
263 static int resume_detect_interrupts_are_broken(
struct uhci_hcd *uhci)
274 static int global_suspend_mode_is_broken(
struct uhci_hcd *uhci)
286 struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
289 dev_dbg(&rhdev->dev,
"%s%s\n", __func__,
290 (auto_stop ?
" (auto-stop)" :
""));
305 if (!device_may_wakeup(&rhdev->dev))
306 egsm_enable = int_enable = 0;
315 if (!rhdev->do_remote_wakeup)
335 if (!wakeup_enable || global_suspend_mode_is_broken(uhci) ||
336 resume_detect_interrupts_are_broken(uhci))
337 egsm_enable = int_enable = 0;
340 uhci_writew(uhci, int_enable,
USBINTR);
341 uhci_writew(uhci, egsm_enable | USBCMD_CF,
USBCMD);
352 spin_unlock_irq(&uhci->
lock);
354 spin_lock_irq(&uhci->
lock);
358 if (!(uhci_readw(uhci,
USBSTS) & USBSTS_HCH))
361 uhci_get_current_frame_number(uhci);
371 if (wakeup_enable && (!int_enable || !egsm_enable))
376 uhci_scan_schedule(uhci);
380 static void start_rh(
struct uhci_hcd *uhci)
395 static void wakeup_rh(
struct uhci_hcd *uhci)
399 dev_dbg(&uhci_to_hcd(uhci)->
self.root_hub->dev,
402 " (auto-start)" :
"");
415 spin_unlock_irq(&uhci->
lock);
417 spin_lock_irq(&uhci->
lock);
422 uhci_writew(uhci, USBCMD_CF,
USBCMD);
432 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
437 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
445 status = uhci_readw(uhci,
USBSTS);
446 if (!(status & ~USBSTS_HCH))
448 uhci_writew(uhci, status,
USBSTS);
456 "error, something bad happened!\n");
457 if (status & USBSTS_HCH) {
458 spin_lock(&uhci->
lock);
461 "host controller halted, "
463 if (
debug > 1 && errbuf) {
465 uhci_sprint_schedule(uhci,
476 spin_unlock(&uhci->
lock);
483 spin_lock(&uhci->
lock);
484 uhci_scan_schedule(uhci);
485 spin_unlock(&uhci->
lock);
499 static void uhci_get_current_frame_number(
struct uhci_hcd *uhci)
513 static void release_uhci(
struct uhci_hcd *uhci)
518 spin_lock_irq(&uhci->
lock);
520 spin_unlock_irq(&uhci->
lock);
526 uhci_free_qh(uhci, uhci->
skelqh[i]);
528 uhci_free_td(uhci, uhci->
term_td);
559 static int uhci_start(
struct usb_hcd *hcd)
561 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
566 hcd->uses_new_polling = 1;
568 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
569 hcd->self.sg_tablesize = ~0;
573 (
unsigned long) uhci);
577 #ifdef UHCI_DEBUG_OPS
580 uhci, &uhci_debug_operations);
593 "consistent memory for frame list\n");
594 goto err_alloc_frame;
602 "memory for frame pointers\n");
603 goto err_alloc_frame_cpu;
607 sizeof(
struct uhci_td), 16, 0);
610 goto err_create_td_pool;
614 sizeof(
struct uhci_qh), 16, 0);
617 goto err_create_qh_pool;
620 uhci->
term_td = uhci_alloc_td(uhci);
623 goto err_alloc_term_td;
630 goto err_alloc_skelqh;
640 uhci->skel_term_qh->link =
LINK_TO_QH(uhci, uhci->skel_term_qh);
646 uhci->skel_async_qh->element = uhci->skel_term_qh->element =
656 uhci->
frame[
i] = uhci_frame_skel_link(uhci, i);
667 spin_lock_irq(&uhci->
lock);
669 spin_unlock_irq(&uhci->
lock);
678 uhci_free_qh(uhci, uhci->
skelqh[i]);
681 uhci_free_td(uhci, uhci->
term_td);
694 UHCI_NUMFRAMES *
sizeof(*uhci->
frame),
703 static void uhci_stop(
struct usb_hcd *hcd)
705 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
707 spin_lock_irq(&uhci->
lock);
708 if (HCD_HW_ACCESSIBLE(hcd) && !uhci->
dead)
710 uhci_scan_schedule(uhci);
711 spin_unlock_irq(&uhci->
lock);
719 static int uhci_rh_suspend(
struct usb_hcd *hcd)
721 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
724 spin_lock_irq(&uhci->
lock);
725 if (!HCD_HW_ACCESSIBLE(hcd))
735 else if (hcd->self.root_hub->do_remote_wakeup &&
742 spin_unlock_irq(&uhci->
lock);
746 static int uhci_rh_resume(
struct usb_hcd *hcd)
748 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
751 spin_lock_irq(&uhci->
lock);
752 if (!HCD_HW_ACCESSIBLE(hcd))
754 else if (!uhci->
dead)
756 spin_unlock_irq(&uhci->
lock);
763 static void uhci_hcd_endpoint_disable(
struct usb_hcd *hcd,
764 struct usb_host_endpoint *
hep)
766 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
769 spin_lock_irq(&uhci->
lock);
770 qh = (
struct uhci_qh *) hep->hcpriv;
776 spin_unlock_irq(&uhci->
lock);
779 spin_lock_irq(&uhci->
lock);
783 uhci_free_qh(uhci, qh);
785 spin_unlock_irq(&uhci->
lock);
788 static int uhci_hcd_get_frame_number(
struct usb_hcd *hcd)
790 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
798 (UHCI_NUMFRAMES - 1);
799 return frame_number +
delta;
803 static int uhci_count_ports(
struct usb_hcd *hcd)
805 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
806 unsigned io_size = (unsigned) hcd->rsrc_len;
818 unsigned int portstatus;
820 portstatus = uhci_readw(uhci,
USBPORTSC1 + (port * 2));
821 if (!(portstatus & 0x0080) || portstatus == 0xffff)
830 "forcing to 2 ports\n");
837 static const char hcd_name[] =
"uhci_hcd";
841 #define PCI_DRIVER uhci_pci_driver
844 #ifdef CONFIG_SPARC_LEON
846 #define PLATFORM_DRIVER uhci_grlib_driver
849 #ifdef CONFIG_USB_UHCI_PLATFORM
851 #define PLATFORM_DRIVER uhci_platform_driver
854 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER)
855 #error "missing bus glue for uhci-hcd"
858 static int __init uhci_hcd_init(
void)
866 ignore_oc ?
", overcurrent ignored" :
"");
874 if (!uhci_debugfs_root)
883 #ifdef PLATFORM_DRIVER
890 retval = pci_register_driver(&PCI_DRIVER);
900 #ifdef PLATFORM_DRIVER
918 static void __exit uhci_hcd_cleanup(
void)
920 #ifdef PLATFORM_DRIVER