fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / host / uhci-hub.c
index 152971d..8e4427a 100644 (file)
@@ -33,6 +33,9 @@ static __u8 root_hub_hub_des[] =
 /* status change bits:  nonzero writes will clear */
 #define RWC_BITS       (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC)
 
+/* suspend/resume bits: port suspended or port resuming */
+#define SUSPEND_BITS   (USBPORTSC_SUSP | USBPORTSC_RD)
+
 /* A port that either is connected or has a changed-bit set will prevent
  * us from AUTO_STOPPING.
  */
@@ -52,10 +55,20 @@ static int any_ports_active(struct uhci_hcd *uhci)
 static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
 {
        int port;
+       int mask = RWC_BITS;
+
+       /* Some boards (both VIA and Intel apparently) report bogus
+        * overcurrent indications, causing massive log spam unless
+        * we completely ignore them.  This doesn't seem to be a problem
+        * with the chipset so much as with the way it is connected on
+        * the motherboard; if the overcurrent input is left to float
+        * then it may constantly register false positives. */
+       if (ignore_oc)
+               mask &= ~USBPORTSC_OCC;
 
        *buf = 0;
        for (port = 0; port < uhci->rh_numports; ++port) {
-               if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & RWC_BITS) ||
+               if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & mask) ||
                                test_bit(port, &uhci->port_c_suspend))
                        *buf |= (1 << (port + 1));
        }
@@ -84,19 +97,25 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
                unsigned long port_addr)
 {
        int status;
+       int i;
 
-       if (test_bit(port, &uhci->suspended_ports)) {
-               CLR_RH_PORTSTAT(USBPORTSC_SUSP | USBPORTSC_RD);
-               clear_bit(port, &uhci->suspended_ports);
-               clear_bit(port, &uhci->resuming_ports);
-               set_bit(port, &uhci->port_c_suspend);
+       if (inw(port_addr) & SUSPEND_BITS) {
+               CLR_RH_PORTSTAT(SUSPEND_BITS);
+               if (test_bit(port, &uhci->resuming_ports))
+                       set_bit(port, &uhci->port_c_suspend);
 
                /* The controller won't actually turn off the RD bit until
                 * it has had a chance to send a low-speed EOP sequence,
-                * which takes 3 bit times (= 2 microseconds).  We'll delay
-                * slightly longer for good luck. */
-               udelay(4);
+                * which is supposed to take 3 bit times (= 2 microseconds).
+                * Experiments show that some controllers take longer, so
+                * we'll poll for completion. */
+               for (i = 0; i < 10; ++i) {
+                       if (!(inw(port_addr) & SUSPEND_BITS))
+                               break;
+                       udelay(1);
+               }
        }
+       clear_bit(port, &uhci->resuming_ports);
 }
 
 /* Wait for the UHCI controller in HP's iLO2 server management chip.
@@ -170,10 +189,9 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
 
        spin_lock_irqsave(&uhci->lock, flags);
 
-       uhci_scan_schedule(uhci, NULL);
-       if (uhci->hc_inaccessible)
+       uhci_scan_schedule(uhci);
+       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
                goto done;
-       check_fsbr(uhci);
        uhci_check_ports(uhci);
 
        status = get_hub_status_data(uhci, buf);
@@ -228,7 +246,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
        u16 wPortChange, wPortStatus;
        unsigned long flags;
 
-       if (uhci->hc_inaccessible)
+       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
                return -ETIMEDOUT;
 
        spin_lock_irqsave(&uhci->lock, flags);
@@ -258,15 +276,13 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
                        wPortChange |= USB_PORT_STAT_C_CONNECTION;
                if (status & USBPORTSC_PEC)
                        wPortChange |= USB_PORT_STAT_C_ENABLE;
-               if (status & USBPORTSC_OCC)
+               if ((status & USBPORTSC_OCC) && !ignore_oc)
                        wPortChange |= USB_PORT_STAT_C_OVERCURRENT;
 
                if (test_bit(port, &uhci->port_c_suspend)) {
                        wPortChange |= USB_PORT_STAT_C_SUSPEND;
                        lstatus |= 1;
                }
-               if (test_bit(port, &uhci->suspended_ports))
-                       lstatus |= 2;
                if (test_bit(port, &uhci->resuming_ports))
                        lstatus |= 4;
 
@@ -276,7 +292,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
                        wPortStatus |= USB_PORT_STAT_CONNECTION;
                if (status & USBPORTSC_PE) {
                        wPortStatus |= USB_PORT_STAT_ENABLE;
-                       if (status & (USBPORTSC_SUSP | USBPORTSC_RD))
+                       if (status & SUSPEND_BITS)
                                wPortStatus |= USB_PORT_STAT_SUSPEND;
                }
                if (status & USBPORTSC_OC)
@@ -309,7 +325,6 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 
                switch (wValue) {
                case USB_PORT_FEAT_SUSPEND:
-                       set_bit(port, &uhci->suspended_ports);
                        SET_RH_PORTSTAT(USBPORTSC_SUSP);
                        OK(0);
                case USB_PORT_FEAT_RESET:
@@ -343,8 +358,11 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
                        CLR_RH_PORTSTAT(USBPORTSC_PEC);
                        OK(0);
                case USB_PORT_FEAT_SUSPEND:
-                       if (test_bit(port, &uhci->suspended_ports) &&
-                                       !test_and_set_bit(port,
+                       if (!(inw(port_addr) & USBPORTSC_SUSP)) {
+
+                               /* Make certain the port isn't suspended */
+                               uhci_finish_suspend(uhci, port, port_addr);
+                       } else if (!test_and_set_bit(port,
                                                &uhci->resuming_ports)) {
                                SET_RH_PORTSTAT(USBPORTSC_RD);