diff options
author | Andiry Xu <andiry.xu@amd.com> | 2010-10-14 10:23:03 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-22 13:22:13 -0400 |
commit | 9777e3ce907d4cb5a513902a87ecd03b52499569 (patch) | |
tree | a2b28eeeaddd39d7c8cdd59f6ddbfa694d40d5ba /drivers/usb/host/xhci-hub.c | |
parent | 561925318725a41189a69f36ebe99199b3fb84c4 (diff) |
USB: xHCI: bus power management implementation
This patch implements xHCI bus suspend/resume function hook.
In the patch it goes through all the ports and suspend/resume
the ports if needed.
If any port is in remote wakeup, abort bus suspend as what ehci/ohci do.
Signed-off-by: Libin Yang <libin.yang@amd.com>
Signed-off-by: Crane Cai <crane.cai@amd.com>
Signed-off-by: Andiry Xu <andiry.xu@amd.com>
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/xhci-hub.c')
-rw-r--r-- | drivers/usb/host/xhci-hub.c | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 8163f17e7043..7f2f63cb6c53 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
@@ -24,6 +24,10 @@ | |||
24 | 24 | ||
25 | #include "xhci.h" | 25 | #include "xhci.h" |
26 | 26 | ||
27 | #define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) | ||
28 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ | ||
29 | PORT_RC | PORT_PLC | PORT_PE) | ||
30 | |||
27 | static void xhci_hub_descriptor(struct xhci_hcd *xhci, | 31 | static void xhci_hub_descriptor(struct xhci_hcd *xhci, |
28 | struct usb_hub_descriptor *desc) | 32 | struct usb_hub_descriptor *desc) |
29 | { | 33 | { |
@@ -560,3 +564,187 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
560 | spin_unlock_irqrestore(&xhci->lock, flags); | 564 | spin_unlock_irqrestore(&xhci->lock, flags); |
561 | return status ? retval : 0; | 565 | return status ? retval : 0; |
562 | } | 566 | } |
567 | |||
568 | #ifdef CONFIG_PM | ||
569 | |||
570 | int xhci_bus_suspend(struct usb_hcd *hcd) | ||
571 | { | ||
572 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
573 | int port; | ||
574 | unsigned long flags; | ||
575 | |||
576 | xhci_dbg(xhci, "suspend root hub\n"); | ||
577 | |||
578 | spin_lock_irqsave(&xhci->lock, flags); | ||
579 | |||
580 | if (hcd->self.root_hub->do_remote_wakeup) { | ||
581 | port = HCS_MAX_PORTS(xhci->hcs_params1); | ||
582 | while (port--) { | ||
583 | if (xhci->resume_done[port] != 0) { | ||
584 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
585 | xhci_dbg(xhci, "suspend failed because " | ||
586 | "port %d is resuming\n", | ||
587 | port + 1); | ||
588 | return -EBUSY; | ||
589 | } | ||
590 | } | ||
591 | } | ||
592 | |||
593 | port = HCS_MAX_PORTS(xhci->hcs_params1); | ||
594 | xhci->bus_suspended = 0; | ||
595 | while (port--) { | ||
596 | /* suspend the port if the port is not suspended */ | ||
597 | u32 __iomem *addr; | ||
598 | u32 t1, t2; | ||
599 | int slot_id; | ||
600 | |||
601 | addr = &xhci->op_regs->port_status_base + | ||
602 | NUM_PORT_REGS * (port & 0xff); | ||
603 | t1 = xhci_readl(xhci, addr); | ||
604 | t2 = xhci_port_state_to_neutral(t1); | ||
605 | |||
606 | if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { | ||
607 | xhci_dbg(xhci, "port %d not suspended\n", port); | ||
608 | slot_id = xhci_find_slot_id_by_port(xhci, port + 1); | ||
609 | if (slot_id) { | ||
610 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
611 | xhci_stop_device(xhci, slot_id, 1); | ||
612 | spin_lock_irqsave(&xhci->lock, flags); | ||
613 | } | ||
614 | t2 &= ~PORT_PLS_MASK; | ||
615 | t2 |= PORT_LINK_STROBE | XDEV_U3; | ||
616 | set_bit(port, &xhci->bus_suspended); | ||
617 | } | ||
618 | if (hcd->self.root_hub->do_remote_wakeup) { | ||
619 | if (t1 & PORT_CONNECT) { | ||
620 | t2 |= PORT_WKOC_E | PORT_WKDISC_E; | ||
621 | t2 &= ~PORT_WKCONN_E; | ||
622 | } else { | ||
623 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; | ||
624 | t2 &= ~PORT_WKDISC_E; | ||
625 | } | ||
626 | } else | ||
627 | t2 &= ~PORT_WAKE_BITS; | ||
628 | |||
629 | t1 = xhci_port_state_to_neutral(t1); | ||
630 | if (t1 != t2) | ||
631 | xhci_writel(xhci, t2, addr); | ||
632 | |||
633 | if (DEV_HIGHSPEED(t1)) { | ||
634 | /* enable remote wake up for USB 2.0 */ | ||
635 | u32 __iomem *addr; | ||
636 | u32 tmp; | ||
637 | |||
638 | addr = &xhci->op_regs->port_power_base + | ||
639 | NUM_PORT_REGS * (port & 0xff); | ||
640 | tmp = xhci_readl(xhci, addr); | ||
641 | tmp |= PORT_RWE; | ||
642 | xhci_writel(xhci, tmp, addr); | ||
643 | } | ||
644 | } | ||
645 | hcd->state = HC_STATE_SUSPENDED; | ||
646 | xhci->next_statechange = jiffies + msecs_to_jiffies(10); | ||
647 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | int xhci_bus_resume(struct usb_hcd *hcd) | ||
652 | { | ||
653 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
654 | int port; | ||
655 | u32 temp; | ||
656 | unsigned long flags; | ||
657 | |||
658 | xhci_dbg(xhci, "resume root hub\n"); | ||
659 | |||
660 | if (time_before(jiffies, xhci->next_statechange)) | ||
661 | msleep(5); | ||
662 | |||
663 | spin_lock_irqsave(&xhci->lock, flags); | ||
664 | if (!HCD_HW_ACCESSIBLE(hcd)) { | ||
665 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
666 | return -ESHUTDOWN; | ||
667 | } | ||
668 | |||
669 | /* delay the irqs */ | ||
670 | temp = xhci_readl(xhci, &xhci->op_regs->command); | ||
671 | temp &= ~CMD_EIE; | ||
672 | xhci_writel(xhci, temp, &xhci->op_regs->command); | ||
673 | |||
674 | port = HCS_MAX_PORTS(xhci->hcs_params1); | ||
675 | while (port--) { | ||
676 | /* Check whether need resume ports. If needed | ||
677 | resume port and disable remote wakeup */ | ||
678 | u32 __iomem *addr; | ||
679 | u32 temp; | ||
680 | int slot_id; | ||
681 | |||
682 | addr = &xhci->op_regs->port_status_base + | ||
683 | NUM_PORT_REGS * (port & 0xff); | ||
684 | temp = xhci_readl(xhci, addr); | ||
685 | if (DEV_SUPERSPEED(temp)) | ||
686 | temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); | ||
687 | else | ||
688 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); | ||
689 | if (test_bit(port, &xhci->bus_suspended) && | ||
690 | (temp & PORT_PLS_MASK)) { | ||
691 | if (DEV_SUPERSPEED(temp)) { | ||
692 | temp = xhci_port_state_to_neutral(temp); | ||
693 | temp &= ~PORT_PLS_MASK; | ||
694 | temp |= PORT_LINK_STROBE | XDEV_U0; | ||
695 | xhci_writel(xhci, temp, addr); | ||
696 | } else { | ||
697 | temp = xhci_port_state_to_neutral(temp); | ||
698 | temp &= ~PORT_PLS_MASK; | ||
699 | temp |= PORT_LINK_STROBE | XDEV_RESUME; | ||
700 | xhci_writel(xhci, temp, addr); | ||
701 | |||
702 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
703 | msleep(20); | ||
704 | spin_lock_irqsave(&xhci->lock, flags); | ||
705 | |||
706 | temp = xhci_readl(xhci, addr); | ||
707 | temp = xhci_port_state_to_neutral(temp); | ||
708 | temp &= ~PORT_PLS_MASK; | ||
709 | temp |= PORT_LINK_STROBE | XDEV_U0; | ||
710 | xhci_writel(xhci, temp, addr); | ||
711 | } | ||
712 | slot_id = xhci_find_slot_id_by_port(xhci, port + 1); | ||
713 | if (slot_id) | ||
714 | xhci_ring_device(xhci, slot_id); | ||
715 | } else | ||
716 | xhci_writel(xhci, temp, addr); | ||
717 | |||
718 | if (DEV_HIGHSPEED(temp)) { | ||
719 | /* disable remote wake up for USB 2.0 */ | ||
720 | u32 __iomem *addr; | ||
721 | u32 tmp; | ||
722 | |||
723 | addr = &xhci->op_regs->port_power_base + | ||
724 | NUM_PORT_REGS * (port & 0xff); | ||
725 | tmp = xhci_readl(xhci, addr); | ||
726 | tmp &= ~PORT_RWE; | ||
727 | xhci_writel(xhci, tmp, addr); | ||
728 | } | ||
729 | } | ||
730 | |||
731 | (void) xhci_readl(xhci, &xhci->op_regs->command); | ||
732 | |||
733 | xhci->next_statechange = jiffies + msecs_to_jiffies(5); | ||
734 | hcd->state = HC_STATE_RUNNING; | ||
735 | /* re-enable irqs */ | ||
736 | temp = xhci_readl(xhci, &xhci->op_regs->command); | ||
737 | temp |= CMD_EIE; | ||
738 | xhci_writel(xhci, temp, &xhci->op_regs->command); | ||
739 | temp = xhci_readl(xhci, &xhci->op_regs->command); | ||
740 | |||
741 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
742 | return 0; | ||
743 | } | ||
744 | |||
745 | #else | ||
746 | |||
747 | #define xhci_bus_suspend NULL | ||
748 | #define xhci_bus_resume NULL | ||
749 | |||
750 | #endif | ||