aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-hub.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2007-05-04 11:52:40 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-12 19:29:47 -0400
commit383975d765523a56dc43a6cd6d52e9b376800cf2 (patch)
treed6ecbfe620d7d5fba372211d7af185e7c44e5097 /drivers/usb/host/ehci-hub.c
parent0458d5b4c9cc4ca0f62625d0144ddc4b4bc97a3c (diff)
USB: EHCI, OHCI: handover changes
This patch (as887) changes the way ehci-hcd and ohci-hcd handle a loss of VBUS power during suspend. In order for the USB-persist facility to work correctly, it is necessary for low- and full-speed devices attached to a high-speed port to be handed back to the companion controller during resume processing. This entails three changes: adding code to ehci-hcd to perform the handover, removing code from ohci-hcd to turn off ports during root-hub reinit, and adding code to ohci-hcd to turn on ports during PCI controller resume. (Other bus glue resume methods for platforms supporting high-speed controllers would need a similar change, if any existed.) Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/ehci-hub.c')
-rw-r--r--drivers/usb/host/ehci-hub.c99
1 files changed, 94 insertions, 5 deletions
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index f4d301bc83b9..3e80de7c7f5b 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -28,6 +28,87 @@
28 28
29/*-------------------------------------------------------------------------*/ 29/*-------------------------------------------------------------------------*/
30 30
31#ifdef CONFIG_USB_PERSIST
32
33static int ehci_hub_control(
34 struct usb_hcd *hcd,
35 u16 typeReq,
36 u16 wValue,
37 u16 wIndex,
38 char *buf,
39 u16 wLength
40);
41
42/* After a power loss, ports that were owned by the companion must be
43 * reset so that the companion can still own them.
44 */
45static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
46{
47 u32 __iomem *reg;
48 u32 status;
49 int port;
50 __le32 buf;
51 struct usb_hcd *hcd = ehci_to_hcd(ehci);
52
53 if (!ehci->owned_ports)
54 return;
55
56 /* Give the connections some time to appear */
57 msleep(20);
58
59 port = HCS_N_PORTS(ehci->hcs_params);
60 while (port--) {
61 if (test_bit(port, &ehci->owned_ports)) {
62 reg = &ehci->regs->port_status[port];
63 status = ehci_readl(ehci, reg);
64
65 /* Port already owned by companion? */
66 if (status & PORT_OWNER)
67 clear_bit(port, &ehci->owned_ports);
68 else
69 ehci_hub_control(hcd, SetPortFeature,
70 USB_PORT_FEAT_RESET, port + 1,
71 NULL, 0);
72 }
73 }
74
75 if (!ehci->owned_ports)
76 return;
77 msleep(90); /* Wait for resets to complete */
78
79 port = HCS_N_PORTS(ehci->hcs_params);
80 while (port--) {
81 if (test_bit(port, &ehci->owned_ports)) {
82 ehci_hub_control(hcd, GetPortStatus,
83 0, port + 1,
84 (char *) &buf, sizeof(buf));
85
86 /* The companion should now own the port,
87 * but if something went wrong the port must not
88 * remain enabled.
89 */
90 reg = &ehci->regs->port_status[port];
91 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
92 if (status & PORT_OWNER)
93 ehci_writel(ehci, status | PORT_CSC, reg);
94 else {
95 ehci_dbg(ehci, "failed handover port %d: %x\n",
96 port + 1, status);
97 ehci_writel(ehci, status & ~PORT_PE, reg);
98 }
99 }
100 }
101
102 ehci->owned_ports = 0;
103}
104
105#else /* CONFIG_USB_PERSIST */
106
107static inline void ehci_handover_companion_ports(struct ehci_hcd *ehci)
108{ }
109
110#endif
111
31#ifdef CONFIG_PM 112#ifdef CONFIG_PM
32 113
33static int ehci_bus_suspend (struct usb_hcd *hcd) 114static int ehci_bus_suspend (struct usb_hcd *hcd)
@@ -60,14 +141,16 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
60 * then manually resume them in the bus_resume() routine. 141 * then manually resume them in the bus_resume() routine.
61 */ 142 */
62 ehci->bus_suspended = 0; 143 ehci->bus_suspended = 0;
144 ehci->owned_ports = 0;
63 while (port--) { 145 while (port--) {
64 u32 __iomem *reg = &ehci->regs->port_status [port]; 146 u32 __iomem *reg = &ehci->regs->port_status [port];
65 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; 147 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
66 u32 t2 = t1; 148 u32 t2 = t1;
67 149
68 /* keep track of which ports we suspend */ 150 /* keep track of which ports we suspend */
69 if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) && 151 if (t1 & PORT_OWNER)
70 !(t1 & PORT_SUSPEND)) { 152 set_bit(port, &ehci->owned_ports);
153 else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
71 t2 |= PORT_SUSPEND; 154 t2 |= PORT_SUSPEND;
72 set_bit(port, &ehci->bus_suspended); 155 set_bit(port, &ehci->bus_suspended);
73 } 156 }
@@ -108,6 +191,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
108{ 191{
109 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 192 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
110 u32 temp; 193 u32 temp;
194 u32 power_okay;
111 int i; 195 int i;
112 196
113 if (time_before (jiffies, ehci->next_statechange)) 197 if (time_before (jiffies, ehci->next_statechange))
@@ -120,8 +204,9 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
120 * the last user of the controller, not reset/pm hardware keeping 204 * the last user of the controller, not reset/pm hardware keeping
121 * state we gave to it. 205 * state we gave to it.
122 */ 206 */
123 temp = ehci_readl(ehci, &ehci->regs->intr_enable); 207 power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
124 ehci_dbg(ehci, "resume root hub%s\n", temp ? "" : " after power loss"); 208 ehci_dbg(ehci, "resume root hub%s\n",
209 power_okay ? "" : " after power loss");
125 210
126 /* at least some APM implementations will try to deliver 211 /* at least some APM implementations will try to deliver
127 * IRQs right away, so delay them until we're ready. 212 * IRQs right away, so delay them until we're ready.
@@ -184,6 +269,9 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
184 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); 269 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
185 270
186 spin_unlock_irq (&ehci->lock); 271 spin_unlock_irq (&ehci->lock);
272
273 if (!power_okay)
274 ehci_handover_companion_ports(ehci);
187 return 0; 275 return 0;
188} 276}
189 277
@@ -448,7 +536,8 @@ static int ehci_hub_control (
448) { 536) {
449 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 537 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
450 int ports = HCS_N_PORTS (ehci->hcs_params); 538 int ports = HCS_N_PORTS (ehci->hcs_params);
451 u32 __iomem *status_reg = &ehci->regs->port_status[wIndex - 1]; 539 u32 __iomem *status_reg = &ehci->regs->port_status[
540 (wIndex & 0xff) - 1];
452 u32 temp, status; 541 u32 temp, status;
453 unsigned long flags; 542 unsigned long flags;
454 int retval = 0; 543 int retval = 0;