blob: 12f881ff4b2302088760ec4739cdb7118b3c86c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
David Brownelld49d4312005-05-07 13:21:50 -07002 * Copyright (C) 2001-2004 by David Brownell
David Brownell53bd6a62006-08-30 14:50:06 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* this file is part of ehci-hcd.c */
20
21/*-------------------------------------------------------------------------*/
22
23/*
24 * EHCI Root Hub ... the nonsharable stuff
25 *
26 * Registers don't need cpu_to_le32, that happens transparently
27 */
28
29/*-------------------------------------------------------------------------*/
30
31#ifdef CONFIG_PM
32
Alan Stern0c0382e2005-10-13 17:08:02 -040033static int ehci_bus_suspend (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
36 int port;
Alan Stern8c033562006-11-09 14:42:16 -050037 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39 if (time_before (jiffies, ehci->next_statechange))
40 msleep(5);
41
42 port = HCS_N_PORTS (ehci->hcs_params);
43 spin_lock_irq (&ehci->lock);
44
45 /* stop schedules, clean any completed work */
46 if (HC_IS_RUNNING(hcd->state)) {
47 ehci_quiesce (ehci);
48 hcd->state = HC_STATE_QUIESCING;
49 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110050 ehci->command = ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (ehci->reclaim)
Greg Kroah-Hartman64f89792006-10-17 13:57:18 -070052 ehci->reclaim_ready = 1;
David Howells7d12e782006-10-05 14:55:46 +010053 ehci_work(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Alan Stern8c033562006-11-09 14:42:16 -050055 /* Unlike other USB host controller types, EHCI doesn't have
56 * any notion of "global" or bus-wide suspend. The driver has
57 * to manually suspend all the active unsuspended ports, and
58 * then manually resume them in the bus_resume() routine.
59 */
60 ehci->bus_suspended = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 while (port--) {
62 u32 __iomem *reg = &ehci->regs->port_status [port];
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110063 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 u32 t2 = t1;
65
Alan Stern8c033562006-11-09 14:42:16 -050066 /* keep track of which ports we suspend */
67 if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) &&
68 !(t1 & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 t2 |= PORT_SUSPEND;
Alan Stern8c033562006-11-09 14:42:16 -050070 set_bit(port, &ehci->bus_suspended);
71 }
72
73 /* enable remote wakeup on all ports */
David Brownell2c1c3c42005-11-07 15:24:46 -080074 if (device_may_wakeup(&hcd->self.root_hub->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 t2 |= PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E;
76 else
77 t2 &= ~(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E);
78
79 if (t1 != t2) {
80 ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
81 port + 1, t1, t2);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110082 ehci_writel(ehci, t2, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84 }
85
86 /* turn off now-idle HC */
David Brownell4756ae52005-05-09 17:23:51 -070087 del_timer_sync (&ehci->watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 ehci_halt (ehci);
89 hcd->state = HC_STATE_SUSPENDED;
90
Alan Stern8c033562006-11-09 14:42:16 -050091 /* allow remote wakeup */
92 mask = INTR_MASK;
93 if (!device_may_wakeup(&hcd->self.root_hub->dev))
94 mask &= ~STS_PCD;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110095 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
96 ehci_readl(ehci, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -050097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
99 spin_unlock_irq (&ehci->lock);
100 return 0;
101}
102
103
104/* caller has locked the root hub, and should reset/reinit on error */
Alan Stern0c0382e2005-10-13 17:08:02 -0400105static int ehci_bus_resume (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
108 u32 temp;
109 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 if (time_before (jiffies, ehci->next_statechange))
112 msleep(5);
113 spin_lock_irq (&ehci->lock);
114
David Brownellf03c17f2005-11-23 15:45:28 -0800115 /* Ideally and we've got a real resume here, and no port's power
116 * was lost. (For PCI, that means Vaux was maintained.) But we
117 * could instead be restoring a swsusp snapshot -- so that BIOS was
118 * the last user of the controller, not reset/pm hardware keeping
119 * state we gave to it.
120 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100121 temp = ehci_readl(ehci, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500122 ehci_dbg(ehci, "resume root hub%s\n", temp ? "" : " after power loss");
David Brownellf03c17f2005-11-23 15:45:28 -0800123
Alan Stern8c033562006-11-09 14:42:16 -0500124 /* at least some APM implementations will try to deliver
125 * IRQs right away, so delay them until we're ready.
126 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100127 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500128
129 /* re-init operational registers */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100130 ehci_writel(ehci, 0, &ehci->regs->segment);
131 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
132 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 /* restore CMD_RUN, framelist size, and irq threshold */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100135 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Alan Stern8c033562006-11-09 14:42:16 -0500137 /* manually resume the ports we suspended during bus_suspend() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 i = HCS_N_PORTS (ehci->hcs_params);
139 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100140 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
David Brownell10f65242005-08-31 10:55:38 -0700141 temp &= ~(PORT_RWC_BITS
142 | PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E);
Alan Stern8c033562006-11-09 14:42:16 -0500143 if (test_bit(i, &ehci->bus_suspended) &&
144 (temp & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20);
146 temp |= PORT_RESUME;
147 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100148 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
150 i = HCS_N_PORTS (ehci->hcs_params);
151 mdelay (20);
152 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100153 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern8c033562006-11-09 14:42:16 -0500154 if (test_bit(i, &ehci->bus_suspended) &&
155 (temp & PORT_SUSPEND)) {
156 temp &= ~(PORT_RWC_BITS | PORT_RESUME);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100157 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Alan Stern8c033562006-11-09 14:42:16 -0500158 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100161 (void) ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* maybe re-activate the schedule(s) */
164 temp = 0;
165 if (ehci->async->qh_next.qh)
166 temp |= CMD_ASE;
167 if (ehci->periodic_sched)
168 temp |= CMD_PSE;
169 if (temp) {
170 ehci->command |= temp;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100171 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
174 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
175 hcd->state = HC_STATE_RUNNING;
176
177 /* Now we can safely re-enable irqs */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100178 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 spin_unlock_irq (&ehci->lock);
181 return 0;
182}
183
184#else
185
Alan Stern0c0382e2005-10-13 17:08:02 -0400186#define ehci_bus_suspend NULL
187#define ehci_bus_resume NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189#endif /* CONFIG_PM */
190
191/*-------------------------------------------------------------------------*/
192
193static int check_reset_complete (
194 struct ehci_hcd *ehci,
195 int index,
Alan Sterne6316562007-01-16 11:58:00 -0500196 u32 __iomem *status_reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 int port_status
198) {
199 if (!(port_status & PORT_CONNECT)) {
200 ehci->reset_done [index] = 0;
201 return port_status;
202 }
203
204 /* if reset finished and it's still not enabled -- handoff */
205 if (!(port_status & PORT_PE)) {
206
207 /* with integrated TT, there's nobody to hand it to! */
208 if (ehci_is_TDI(ehci)) {
209 ehci_dbg (ehci,
210 "Failed to enable port %d on root hub TT\n",
211 index+1);
212 return port_status;
213 }
214
215 ehci_dbg (ehci, "port %d full speed --> companion\n",
216 index + 1);
217
218 // what happens if HCS_N_CC(params) == 0 ?
219 port_status |= PORT_OWNER;
David Brownell10f65242005-08-31 10:55:38 -0700220 port_status &= ~PORT_RWC_BITS;
Alan Sterne6316562007-01-16 11:58:00 -0500221 ehci_writel(ehci, port_status, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 } else
224 ehci_dbg (ehci, "port %d high speed\n", index + 1);
225
226 return port_status;
227}
228
229/*-------------------------------------------------------------------------*/
230
231
232/* build "status change" packet (one or two bytes) from HC registers */
233
234static int
235ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
236{
237 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
238 u32 temp, status = 0;
David Brownell93f1a472006-11-16 23:34:58 -0800239 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 int ports, i, retval = 1;
241 unsigned long flags;
242
243 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
244 if (!HC_IS_RUNNING(hcd->state))
245 return 0;
246
247 /* init status to no-changes */
248 buf [0] = 0;
249 ports = HCS_N_PORTS (ehci->hcs_params);
250 if (ports > 7) {
251 buf [1] = 0;
252 retval++;
253 }
David Brownell53bd6a62006-08-30 14:50:06 -0700254
David Brownell93f1a472006-11-16 23:34:58 -0800255 /* Some boards (mostly VIA?) report bogus overcurrent indications,
256 * causing massive log spam unless we completely ignore them. It
257 * may be relevant that VIA VT8235 controlers, where PORT_POWER is
258 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
259 * PORT_POWER; that's surprising, but maybe within-spec.
260 */
261 if (!ignore_oc)
262 mask = PORT_CSC | PORT_PEC | PORT_OCC;
263 else
264 mask = PORT_CSC | PORT_PEC;
265 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /* no hub change reports (bit 0) for now (power, ...) */
268
269 /* port N changes (bit N)? */
270 spin_lock_irqsave (&ehci->lock, flags);
271 for (i = 0; i < ports; i++) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100272 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (temp & PORT_OWNER) {
274 /* don't report this in GetPortStatus */
275 if (temp & PORT_CSC) {
David Brownell10f65242005-08-31 10:55:38 -0700276 temp &= ~PORT_RWC_BITS;
277 temp |= PORT_CSC;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100278 ehci_writel(ehci, temp,
279 &ehci->regs->port_status [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281 continue;
282 }
283 if (!(temp & PORT_CONNECT))
284 ehci->reset_done [i] = 0;
David Brownell93f1a472006-11-16 23:34:58 -0800285 if ((temp & mask) != 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 || ((temp & PORT_RESUME) != 0
287 && time_after (jiffies,
288 ehci->reset_done [i]))) {
289 if (i < 7)
290 buf [0] |= 1 << (i + 1);
291 else
292 buf [1] |= 1 << (i - 7);
293 status = STS_PCD;
294 }
295 }
296 /* FIXME autosuspend idle root hubs */
297 spin_unlock_irqrestore (&ehci->lock, flags);
298 return status ? retval : 0;
299}
300
301/*-------------------------------------------------------------------------*/
302
303static void
304ehci_hub_descriptor (
305 struct ehci_hcd *ehci,
306 struct usb_hub_descriptor *desc
307) {
308 int ports = HCS_N_PORTS (ehci->hcs_params);
309 u16 temp;
310
311 desc->bDescriptorType = 0x29;
312 desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
313 desc->bHubContrCurrent = 0;
314
315 desc->bNbrPorts = ports;
316 temp = 1 + (ports / 8);
317 desc->bDescLength = 7 + 2 * temp;
318
319 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
320 memset (&desc->bitmap [0], 0, temp);
321 memset (&desc->bitmap [temp], 0xff, temp);
322
323 temp = 0x0008; /* per-port overcurrent reporting */
324 if (HCS_PPC (ehci->hcs_params))
325 temp |= 0x0001; /* per-port power control */
David Brownell56c1e262005-04-09 09:00:29 -0700326 else
327 temp |= 0x0002; /* no power switching */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#if 0
329// re-enable when we support USB_PORT_FEAT_INDICATOR below.
330 if (HCS_INDICATOR (ehci->hcs_params))
331 temp |= 0x0080; /* per-port indicators (LEDs) */
332#endif
333 desc->wHubCharacteristics = (__force __u16)cpu_to_le16 (temp);
334}
335
336/*-------------------------------------------------------------------------*/
337
David Brownell53bd6a62006-08-30 14:50:06 -0700338#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340static int ehci_hub_control (
341 struct usb_hcd *hcd,
342 u16 typeReq,
343 u16 wValue,
344 u16 wIndex,
345 char *buf,
346 u16 wLength
347) {
348 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
349 int ports = HCS_N_PORTS (ehci->hcs_params);
Alan Sterne6316562007-01-16 11:58:00 -0500350 u32 __iomem *status_reg = &ehci->regs->port_status[wIndex - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 u32 temp, status;
352 unsigned long flags;
353 int retval = 0;
David Brownellf0d7f272006-11-16 23:56:15 -0800354 unsigned selector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 /*
357 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
358 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
359 * (track current state ourselves) ... blink for diagnostics,
360 * power, "this is the one", etc. EHCI spec supports this.
361 */
362
363 spin_lock_irqsave (&ehci->lock, flags);
364 switch (typeReq) {
365 case ClearHubFeature:
366 switch (wValue) {
367 case C_HUB_LOCAL_POWER:
368 case C_HUB_OVER_CURRENT:
369 /* no hub-wide feature/status flags */
370 break;
371 default:
372 goto error;
373 }
374 break;
375 case ClearPortFeature:
376 if (!wIndex || wIndex > ports)
377 goto error;
378 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -0500379 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if (temp & PORT_OWNER)
381 break;
382
383 switch (wValue) {
384 case USB_PORT_FEAT_ENABLE:
Alan Sterne6316562007-01-16 11:58:00 -0500385 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
387 case USB_PORT_FEAT_C_ENABLE:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100388 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC,
Alan Sterne6316562007-01-16 11:58:00 -0500389 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 break;
391 case USB_PORT_FEAT_SUSPEND:
392 if (temp & PORT_RESET)
393 goto error;
David Brownellf8aeb3b2006-01-20 13:55:14 -0800394 if (ehci->no_selective_suspend)
395 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (temp & PORT_SUSPEND) {
397 if ((temp & PORT_PE) == 0)
398 goto error;
399 /* resume signaling for 20 msec */
David Brownell10f65242005-08-31 10:55:38 -0700400 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100401 ehci_writel(ehci, temp | PORT_RESUME,
Alan Sterne6316562007-01-16 11:58:00 -0500402 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 ehci->reset_done [wIndex] = jiffies
404 + msecs_to_jiffies (20);
405 }
406 break;
407 case USB_PORT_FEAT_C_SUSPEND:
408 /* we auto-clear this feature */
409 break;
410 case USB_PORT_FEAT_POWER:
411 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100412 ehci_writel(ehci,
413 temp & ~(PORT_RWC_BITS | PORT_POWER),
Alan Sterne6316562007-01-16 11:58:00 -0500414 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 break;
416 case USB_PORT_FEAT_C_CONNECTION:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100417 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
Alan Sterne6316562007-01-16 11:58:00 -0500418 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 break;
420 case USB_PORT_FEAT_C_OVER_CURRENT:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100421 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC,
Alan Sterne6316562007-01-16 11:58:00 -0500422 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 break;
424 case USB_PORT_FEAT_C_RESET:
425 /* GetPortStatus clears reset */
426 break;
427 default:
428 goto error;
429 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100430 ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 break;
432 case GetHubDescriptor:
433 ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
434 buf);
435 break;
436 case GetHubStatus:
437 /* no hub-wide feature/status flags */
438 memset (buf, 0, 4);
439 //cpu_to_le32s ((u32 *) buf);
440 break;
441 case GetPortStatus:
442 if (!wIndex || wIndex > ports)
443 goto error;
444 wIndex--;
445 status = 0;
Alan Sterne6316562007-01-16 11:58:00 -0500446 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 // wPortChange bits
449 if (temp & PORT_CSC)
450 status |= 1 << USB_PORT_FEAT_C_CONNECTION;
451 if (temp & PORT_PEC)
452 status |= 1 << USB_PORT_FEAT_C_ENABLE;
David Brownell93f1a472006-11-16 23:34:58 -0800453 if ((temp & PORT_OCC) && !ignore_oc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT;
455
456 /* whoever resumes must GetPortStatus to complete it!! */
457 if ((temp & PORT_RESUME)
458 && time_after (jiffies,
459 ehci->reset_done [wIndex])) {
460 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
461 ehci->reset_done [wIndex] = 0;
462
463 /* stop resume signaling */
Alan Sterne6316562007-01-16 11:58:00 -0500464 temp = ehci_readl(ehci, status_reg);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100465 ehci_writel(ehci,
Alan Sterne6316562007-01-16 11:58:00 -0500466 temp & ~(PORT_RWC_BITS | PORT_RESUME),
467 status_reg);
468 retval = handshake(ehci, status_reg,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100469 PORT_RESUME, 0, 2000 /* 2msec */);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if (retval != 0) {
471 ehci_err (ehci, "port %d resume error %d\n",
472 wIndex + 1, retval);
473 goto error;
474 }
475 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
476 }
477
478 /* whoever resets must GetPortStatus to complete it!! */
479 if ((temp & PORT_RESET)
480 && time_after (jiffies,
481 ehci->reset_done [wIndex])) {
482 status |= 1 << USB_PORT_FEAT_C_RESET;
483 ehci->reset_done [wIndex] = 0;
484
485 /* force reset to complete */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100486 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
Alan Sterne6316562007-01-16 11:58:00 -0500487 status_reg);
David Brownellc22fa3a2005-06-13 07:15:28 -0700488 /* REVISIT: some hardware needs 550+ usec to clear
489 * this bit; seems too long to spin routinely...
490 */
Alan Sterne6316562007-01-16 11:58:00 -0500491 retval = handshake(ehci, status_reg,
David Brownellc22fa3a2005-06-13 07:15:28 -0700492 PORT_RESET, 0, 750);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (retval != 0) {
494 ehci_err (ehci, "port %d reset error %d\n",
495 wIndex + 1, retval);
496 goto error;
497 }
498
499 /* see what we found out */
Alan Sterne6316562007-01-16 11:58:00 -0500500 temp = check_reset_complete (ehci, wIndex, status_reg,
501 ehci_readl(ehci, status_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
504 // don't show wPortStatus if it's owned by a companion hc
505 if (!(temp & PORT_OWNER)) {
506 if (temp & PORT_CONNECT) {
507 status |= 1 << USB_PORT_FEAT_CONNECTION;
508 // status may be from integrated TT
509 status |= ehci_port_speed(ehci, temp);
510 }
511 if (temp & PORT_PE)
512 status |= 1 << USB_PORT_FEAT_ENABLE;
513 if (temp & (PORT_SUSPEND|PORT_RESUME))
514 status |= 1 << USB_PORT_FEAT_SUSPEND;
515 if (temp & PORT_OC)
516 status |= 1 << USB_PORT_FEAT_OVER_CURRENT;
517 if (temp & PORT_RESET)
518 status |= 1 << USB_PORT_FEAT_RESET;
519 if (temp & PORT_POWER)
520 status |= 1 << USB_PORT_FEAT_POWER;
521 }
522
523#ifndef EHCI_VERBOSE_DEBUG
524 if (status & ~0xffff) /* only if wPortChange is interesting */
525#endif
526 dbg_port (ehci, "GetStatus", wIndex + 1, temp);
527 // we "know" this alignment is good, caller used kmalloc()...
528 *((__le32 *) buf) = cpu_to_le32 (status);
529 break;
530 case SetHubFeature:
531 switch (wValue) {
532 case C_HUB_LOCAL_POWER:
533 case C_HUB_OVER_CURRENT:
534 /* no hub-wide feature/status flags */
535 break;
536 default:
537 goto error;
538 }
539 break;
540 case SetPortFeature:
David Brownellf0d7f272006-11-16 23:56:15 -0800541 selector = wIndex >> 8;
542 wIndex &= 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 if (!wIndex || wIndex > ports)
544 goto error;
545 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -0500546 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (temp & PORT_OWNER)
548 break;
549
David Brownell10f65242005-08-31 10:55:38 -0700550 temp &= ~PORT_RWC_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 switch (wValue) {
552 case USB_PORT_FEAT_SUSPEND:
David Brownellf8aeb3b2006-01-20 13:55:14 -0800553 if (ehci->no_selective_suspend)
554 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 if ((temp & PORT_PE) == 0
556 || (temp & PORT_RESET) != 0)
557 goto error;
David Brownell2c1c3c42005-11-07 15:24:46 -0800558 if (device_may_wakeup(&hcd->self.root_hub->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 temp |= PORT_WAKE_BITS;
Alan Sterne6316562007-01-16 11:58:00 -0500560 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 break;
562 case USB_PORT_FEAT_POWER:
563 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100564 ehci_writel(ehci, temp | PORT_POWER,
Alan Sterne6316562007-01-16 11:58:00 -0500565 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 break;
567 case USB_PORT_FEAT_RESET:
568 if (temp & PORT_RESUME)
569 goto error;
570 /* line status bits may report this as low speed,
571 * which can be fine if this root hub has a
572 * transaction translator built in.
573 */
574 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
575 && !ehci_is_TDI(ehci)
576 && PORT_USB11 (temp)) {
577 ehci_dbg (ehci,
578 "port %d low speed --> companion\n",
579 wIndex + 1);
580 temp |= PORT_OWNER;
581 } else {
582 ehci_vdbg (ehci, "port %d reset\n", wIndex + 1);
583 temp |= PORT_RESET;
584 temp &= ~PORT_PE;
585
586 /*
587 * caller must wait, then call GetPortStatus
588 * usb 2.0 spec says 50 ms resets on root
589 */
590 ehci->reset_done [wIndex] = jiffies
591 + msecs_to_jiffies (50);
592 }
Alan Sterne6316562007-01-16 11:58:00 -0500593 ehci_writel(ehci, temp, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 break;
David Brownellf0d7f272006-11-16 23:56:15 -0800595
596 /* For downstream facing ports (these): one hub port is put
597 * into test mode according to USB2 11.24.2.13, then the hub
598 * must be reset (which for root hub now means rmmod+modprobe,
599 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
600 * about the EHCI-specific stuff.
601 */
602 case USB_PORT_FEAT_TEST:
603 if (!selector || selector > 5)
604 goto error;
605 ehci_quiesce(ehci);
606 ehci_halt(ehci);
607 temp |= selector << 16;
Alan Sterne6316562007-01-16 11:58:00 -0500608 ehci_writel(ehci, temp, status_reg);
David Brownellf0d7f272006-11-16 23:56:15 -0800609 break;
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 default:
612 goto error;
613 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100614 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 break;
616
617 default:
618error:
619 /* "stall" on error */
620 retval = -EPIPE;
621 }
622 spin_unlock_irqrestore (&ehci->lock, flags);
623 return retval;
624}