X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fusb%2Fhost%2Fuhci-hcd.c;h=3a7bfe7a8874c321990bb802910ea4a902671c9a;hb=0f8469a54f7bd65f2c740a5480c56260dc8a7ae0;hp=4db17f75f4f1a51268767ae1bf0b09f8c6461ec9;hpb=541010e4b8921cd781ff02ae68028501457045b6;p=linux-2.6 diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index 4db17f75f4..3a7bfe7a88 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c @@ -234,7 +234,7 @@ static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) return 0; } -static int remote_wakeup_is_broken(struct uhci_hcd *uhci) +static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) { int port; const char *sys_info; @@ -261,33 +261,60 @@ __releases(uhci->lock) __acquires(uhci->lock) { int auto_stop; - int int_enable, egsm_enable; + int int_enable, egsm_enable, wakeup_enable; + struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub; auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); - dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev, - "%s%s\n", __FUNCTION__, + dev_dbg(&rhdev->dev, "%s%s\n", __func__, (auto_stop ? " (auto-stop)" : "")); - /* If we get a suspend request when we're already auto-stopped - * then there's nothing to do. + /* Start off by assuming Resume-Detect interrupts and EGSM work + * and that remote wakeups should be enabled. + */ + egsm_enable = USBCMD_EGSM; + uhci->RD_enable = 1; + int_enable = USBINTR_RESUME; + wakeup_enable = 1; + + /* In auto-stop mode wakeups must always be detected, but + * Resume-Detect interrupts may be prohibited. (In the absence + * of CONFIG_PM, they are always disallowed.) */ - if (uhci->rh_state == UHCI_RH_AUTO_STOPPED) { - uhci->rh_state = new_state; - return; + if (auto_stop) { + if (!device_may_wakeup(&rhdev->dev)) + int_enable = 0; + + /* In bus-suspend mode wakeups may be disabled, but if they are + * allowed then so are Resume-Detect interrupts. + */ + } else { +#ifdef CONFIG_PM + if (!rhdev->do_remote_wakeup) + wakeup_enable = 0; +#endif } - /* Enable resume-detect interrupts if they work. - * Then enter Global Suspend mode if _it_ works, still configured. + /* EGSM causes the root hub to echo a 'K' signal (resume) out any + * port which requests a remote wakeup. According to the USB spec, + * every hub is supposed to do this. But if we are ignoring + * remote-wakeup requests anyway then there's no point to it. + * We also shouldn't enable EGSM if it's broken. */ - egsm_enable = USBCMD_EGSM; - uhci->working_RD = 1; - int_enable = USBINTR_RESUME; - if (remote_wakeup_is_broken(uhci)) + if (!wakeup_enable || global_suspend_mode_is_broken(uhci)) egsm_enable = 0; - if (resume_detect_interrupts_are_broken(uhci) || !egsm_enable || - !device_may_wakeup( - &uhci_to_hcd(uhci)->self.root_hub->dev)) - uhci->working_RD = int_enable = 0; + + /* If we're ignoring wakeup events then there's no reason to + * enable Resume-Detect interrupts. We also shouldn't enable + * them if they are broken or disallowed. + * + * This logic may lead us to enabling RD but not EGSM. The UHCI + * spec foolishly says that RD works only when EGSM is on, but + * there's no harm in enabling it anyway -- perhaps some chips + * will implement it! + */ + if (!wakeup_enable || resume_detect_interrupts_are_broken(uhci) || + !int_enable) + uhci->RD_enable = int_enable = 0; outw(int_enable, uhci->io_addr + USBINTR); outw(egsm_enable | USBCMD_CF, uhci->io_addr + USBCMD); @@ -308,14 +335,17 @@ __acquires(uhci->lock) return; } if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) - dev_warn(&uhci_to_hcd(uhci)->self.root_hub->dev, - "Controller not stopped yet!\n"); + dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n"); uhci_get_current_frame_number(uhci); uhci->rh_state = new_state; uhci->is_stopped = UHCI_IS_STOPPED; - uhci_to_hcd(uhci)->poll_rh = !int_enable; + + /* If interrupts don't work and remote wakeup is enabled then + * the suspended root hub needs to be polled. + */ + uhci_to_hcd(uhci)->poll_rh = (!int_enable && wakeup_enable); uhci_scan_schedule(uhci); uhci_fsbr_off(uhci); @@ -342,7 +372,7 @@ __releases(uhci->lock) __acquires(uhci->lock) { dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev, - "%s%s\n", __FUNCTION__, + "%s%s\n", __func__, uhci->rh_state == UHCI_RH_AUTO_STOPPED ? " (auto-start)" : ""); @@ -351,9 +381,12 @@ __acquires(uhci->lock) * for 20 ms. */ if (uhci->rh_state == UHCI_RH_SUSPENDED) { + unsigned egsm; + + /* Keep EGSM on if it was set before */ + egsm = inw(uhci->io_addr + USBCMD) & USBCMD_EGSM; uhci->rh_state = UHCI_RH_RESUMING; - outw(USBCMD_FGR | USBCMD_EGSM | USBCMD_CF, - uhci->io_addr + USBCMD); + outw(USBCMD_FGR | USBCMD_CF | egsm, uhci->io_addr + USBCMD); spin_unlock_irq(&uhci->lock); msleep(20); spin_lock_irq(&uhci->lock); @@ -378,7 +411,6 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd) { struct uhci_hcd *uhci = hcd_to_uhci(hcd); unsigned short status; - unsigned long flags; /* * Read the interrupt status, and write it back to clear the @@ -398,7 +430,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd) dev_err(uhci_dev(uhci), "host controller process " "error, something bad happened!\n"); if (status & USBSTS_HCH) { - spin_lock_irqsave(&uhci->lock, flags); + spin_lock(&uhci->lock); if (uhci->rh_state >= UHCI_RH_RUNNING) { dev_err(uhci_dev(uhci), "host controller halted, " @@ -415,16 +447,16 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd) * pending unlinks */ mod_timer(&hcd->rh_timer, jiffies); } - spin_unlock_irqrestore(&uhci->lock, flags); + spin_unlock(&uhci->lock); } } if (status & USBSTS_RD) usb_hcd_poll_rh_status(hcd); else { - spin_lock_irqsave(&uhci->lock, flags); + spin_lock(&uhci->lock); uhci_scan_schedule(uhci); - spin_unlock_irqrestore(&uhci->lock, flags); + spin_unlock(&uhci->lock); } return IRQ_HANDLED; @@ -738,12 +770,12 @@ static int uhci_rh_resume(struct usb_hcd *hcd) return rc; } -static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) +static int uhci_pci_suspend(struct usb_hcd *hcd, pm_message_t message) { struct uhci_hcd *uhci = hcd_to_uhci(hcd); int rc = 0; - dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); + dev_dbg(uhci_dev(uhci), "%s\n", __func__); spin_lock_irq(&uhci->lock); if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) @@ -775,11 +807,11 @@ done: return rc; } -static int uhci_resume(struct usb_hcd *hcd) +static int uhci_pci_resume(struct usb_hcd *hcd) { struct uhci_hcd *uhci = hcd_to_uhci(hcd); - dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); + dev_dbg(uhci_dev(uhci), "%s\n", __func__); /* Since we aren't in D3 any more, it's safe to set this flag * even if the controller was dead. @@ -809,8 +841,10 @@ static int uhci_resume(struct usb_hcd *hcd) spin_unlock_irq(&uhci->lock); - if (!uhci->working_RD) { - /* Suspended root hub needs to be polled */ + /* If interrupts don't work and remote wakeup is enabled then + * the suspended root hub needs to be polled. + */ + if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) { hcd->poll_rh = 1; usb_hcd_poll_rh_status(hcd); } @@ -873,8 +907,8 @@ static const struct hc_driver uhci_driver = { .reset = uhci_init, .start = uhci_start, #ifdef CONFIG_PM - .suspend = uhci_suspend, - .resume = uhci_resume, + .pci_suspend = uhci_pci_suspend, + .pci_resume = uhci_pci_resume, .bus_suspend = uhci_rh_suspend, .bus_resume = uhci_rh_resume, #endif