blob: 6fef1ee7d1010e9cc223290e73054cc0f60ccdc0 [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
Alan Stern58a97ff2008-04-14 12:17:10 -040031#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
32
Alan Sternaff6d182008-04-18 11:11:26 -040033#ifdef CONFIG_PM
34
Alan Stern383975d2007-05-04 11:52:40 -040035static int ehci_hub_control(
36 struct usb_hcd *hcd,
37 u16 typeReq,
38 u16 wValue,
39 u16 wIndex,
40 char *buf,
41 u16 wLength
42);
43
44/* After a power loss, ports that were owned by the companion must be
45 * reset so that the companion can still own them.
46 */
47static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
48{
49 u32 __iomem *reg;
50 u32 status;
51 int port;
52 __le32 buf;
53 struct usb_hcd *hcd = ehci_to_hcd(ehci);
54
55 if (!ehci->owned_ports)
56 return;
57
58 /* Give the connections some time to appear */
59 msleep(20);
60
61 port = HCS_N_PORTS(ehci->hcs_params);
62 while (port--) {
63 if (test_bit(port, &ehci->owned_ports)) {
64 reg = &ehci->regs->port_status[port];
Alan Stern3c519b82007-05-04 11:55:31 -040065 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Alan Stern383975d2007-05-04 11:52:40 -040066
67 /* Port already owned by companion? */
68 if (status & PORT_OWNER)
69 clear_bit(port, &ehci->owned_ports);
Alan Stern3c519b82007-05-04 11:55:31 -040070 else if (test_bit(port, &ehci->companion_ports))
71 ehci_writel(ehci, status & ~PORT_PE, reg);
Alan Stern383975d2007-05-04 11:52:40 -040072 else
73 ehci_hub_control(hcd, SetPortFeature,
74 USB_PORT_FEAT_RESET, port + 1,
75 NULL, 0);
76 }
77 }
78
79 if (!ehci->owned_ports)
80 return;
81 msleep(90); /* Wait for resets to complete */
82
83 port = HCS_N_PORTS(ehci->hcs_params);
84 while (port--) {
85 if (test_bit(port, &ehci->owned_ports)) {
86 ehci_hub_control(hcd, GetPortStatus,
87 0, port + 1,
88 (char *) &buf, sizeof(buf));
89
90 /* The companion should now own the port,
91 * but if something went wrong the port must not
92 * remain enabled.
93 */
94 reg = &ehci->regs->port_status[port];
95 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
96 if (status & PORT_OWNER)
97 ehci_writel(ehci, status | PORT_CSC, reg);
98 else {
99 ehci_dbg(ehci, "failed handover port %d: %x\n",
100 port + 1, status);
101 ehci_writel(ehci, status & ~PORT_PE, reg);
102 }
103 }
104 }
105
106 ehci->owned_ports = 0;
107}
108
Alan Stern0c0382e2005-10-13 17:08:02 -0400109static int ehci_bus_suspend (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
112 int port;
Alan Stern8c033562006-11-09 14:42:16 -0500113 int mask;
Alek Du331ac6b2009-07-13 12:41:20 +0800114 u32 __iomem *hostpc_reg = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Alan Stern8c774fe2007-02-01 16:09:59 -0500116 ehci_dbg(ehci, "suspend root hub\n");
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (time_before (jiffies, ehci->next_statechange))
119 msleep(5);
Alan Sternf8fa7572008-01-10 16:43:15 -0500120 del_timer_sync(&ehci->watchdog);
121 del_timer_sync(&ehci->iaa_watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 port = HCS_N_PORTS (ehci->hcs_params);
124 spin_lock_irq (&ehci->lock);
125
126 /* stop schedules, clean any completed work */
127 if (HC_IS_RUNNING(hcd->state)) {
128 ehci_quiesce (ehci);
129 hcd->state = HC_STATE_QUIESCING;
130 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100131 ehci->command = ehci_readl(ehci, &ehci->regs->command);
David Howells7d12e782006-10-05 14:55:46 +0100132 ehci_work(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Alan Stern8c033562006-11-09 14:42:16 -0500134 /* Unlike other USB host controller types, EHCI doesn't have
135 * any notion of "global" or bus-wide suspend. The driver has
136 * to manually suspend all the active unsuspended ports, and
137 * then manually resume them in the bus_resume() routine.
138 */
139 ehci->bus_suspended = 0;
Alan Stern383975d2007-05-04 11:52:40 -0400140 ehci->owned_ports = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 while (port--) {
142 u32 __iomem *reg = &ehci->regs->port_status [port];
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100143 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 u32 t2 = t1;
145
Alek Du331ac6b2009-07-13 12:41:20 +0800146 if (ehci->has_hostpc)
147 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
148 + HOSTPC0 + 4 * (port & 0xff));
Alan Stern8c033562006-11-09 14:42:16 -0500149 /* keep track of which ports we suspend */
Alan Stern383975d2007-05-04 11:52:40 -0400150 if (t1 & PORT_OWNER)
151 set_bit(port, &ehci->owned_ports);
152 else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 t2 |= PORT_SUSPEND;
Alan Stern8c033562006-11-09 14:42:16 -0500154 set_bit(port, &ehci->bus_suspended);
155 }
156
157 /* enable remote wakeup on all ports */
Alek Du331ac6b2009-07-13 12:41:20 +0800158 if (hcd->self.root_hub->do_remote_wakeup) {
159 /* only enable appropriate wake bits, otherwise the
160 * hardware can not go phy low power mode. If a race
161 * condition happens here(connection change during bits
162 * set), the port change detection will finally fix it.
163 */
164 if (t1 & PORT_CONNECT) {
165 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
166 t2 &= ~PORT_WKCONN_E;
167 } else {
168 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
169 t2 &= ~PORT_WKDISC_E;
170 }
171 } else
Alan Stern58a97ff2008-04-14 12:17:10 -0400172 t2 &= ~PORT_WAKE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 if (t1 != t2) {
175 ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
176 port + 1, t1, t2);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100177 ehci_writel(ehci, t2, reg);
Alek Du331ac6b2009-07-13 12:41:20 +0800178 if (hostpc_reg) {
179 u32 t3;
180
181 msleep(5);/* 5ms for HCD enter low pwr mode */
182 t3 = ehci_readl(ehci, hostpc_reg);
183 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
184 t3 = ehci_readl(ehci, hostpc_reg);
185 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
186 port, (t3 & HOSTPC_PHCD) ?
187 "succeeded" : "failed");
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190 }
191
Alan Sterncd930c92008-01-10 11:14:53 -0500192 /* Apparently some devices need a >= 1-uframe delay here */
193 if (ehci->bus_suspended)
194 udelay(150);
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 /* turn off now-idle HC */
197 ehci_halt (ehci);
198 hcd->state = HC_STATE_SUSPENDED;
199
David Brownellcdc647a2008-04-02 13:40:20 -0700200 if (ehci->reclaim)
201 end_unlink_async(ehci);
202
Alan Stern8c033562006-11-09 14:42:16 -0500203 /* allow remote wakeup */
204 mask = INTR_MASK;
Alan Stern58a97ff2008-04-14 12:17:10 -0400205 if (!hcd->self.root_hub->do_remote_wakeup)
Alan Stern8c033562006-11-09 14:42:16 -0500206 mask &= ~STS_PCD;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100207 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
208 ehci_readl(ehci, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
211 spin_unlock_irq (&ehci->lock);
212 return 0;
213}
214
215
216/* caller has locked the root hub, and should reset/reinit on error */
Alan Stern0c0382e2005-10-13 17:08:02 -0400217static int ehci_bus_resume (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
220 u32 temp;
Alan Stern383975d2007-05-04 11:52:40 -0400221 u32 power_okay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 int i;
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530223 u8 resume_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 if (time_before (jiffies, ehci->next_statechange))
226 msleep(5);
227 spin_lock_irq (&ehci->lock);
Alan Sterncfa59da2007-06-21 16:25:35 -0400228 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
229 spin_unlock_irq(&ehci->lock);
230 return -ESHUTDOWN;
231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
David Brownellf03c17f2005-11-23 15:45:28 -0800233 /* Ideally and we've got a real resume here, and no port's power
234 * was lost. (For PCI, that means Vaux was maintained.) But we
235 * could instead be restoring a swsusp snapshot -- so that BIOS was
236 * the last user of the controller, not reset/pm hardware keeping
237 * state we gave to it.
238 */
Alan Stern383975d2007-05-04 11:52:40 -0400239 power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
240 ehci_dbg(ehci, "resume root hub%s\n",
241 power_okay ? "" : " after power loss");
David Brownellf03c17f2005-11-23 15:45:28 -0800242
Alan Stern8c033562006-11-09 14:42:16 -0500243 /* at least some APM implementations will try to deliver
244 * IRQs right away, so delay them until we're ready.
245 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100246 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500247
248 /* re-init operational registers */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100249 ehci_writel(ehci, 0, &ehci->regs->segment);
250 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
251 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 /* restore CMD_RUN, framelist size, and irq threshold */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100254 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Alan Sterne198a312007-03-15 15:54:30 -0400256 /* Some controller/firmware combinations need a delay during which
257 * they set up the port statuses. See Bugzilla #8190. */
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530258 spin_unlock_irq(&ehci->lock);
259 msleep(8);
260 spin_lock_irq(&ehci->lock);
Alan Sterne198a312007-03-15 15:54:30 -0400261
Alan Stern8c033562006-11-09 14:42:16 -0500262 /* manually resume the ports we suspended during bus_suspend() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 i = HCS_N_PORTS (ehci->hcs_params);
264 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100265 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern58a97ff2008-04-14 12:17:10 -0400266 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
Alan Stern8c033562006-11-09 14:42:16 -0500267 if (test_bit(i, &ehci->bus_suspended) &&
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530268 (temp & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 temp |= PORT_RESUME;
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530270 resume_needed = 1;
271 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100272 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530274
275 /* msleep for 20ms only if code is trying to resume port */
276 if (resume_needed) {
277 spin_unlock_irq(&ehci->lock);
278 msleep(20);
279 spin_lock_irq(&ehci->lock);
280 }
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 i = HCS_N_PORTS (ehci->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100284 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern8c033562006-11-09 14:42:16 -0500285 if (test_bit(i, &ehci->bus_suspended) &&
286 (temp & PORT_SUSPEND)) {
287 temp &= ~(PORT_RWC_BITS | PORT_RESUME);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100288 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Alan Stern8c033562006-11-09 14:42:16 -0500289 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100292 (void) ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 /* maybe re-activate the schedule(s) */
295 temp = 0;
296 if (ehci->async->qh_next.qh)
297 temp |= CMD_ASE;
298 if (ehci->periodic_sched)
299 temp |= CMD_PSE;
300 if (temp) {
301 ehci->command |= temp;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100302 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
305 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
306 hcd->state = HC_STATE_RUNNING;
307
308 /* Now we can safely re-enable irqs */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100309 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 spin_unlock_irq (&ehci->lock);
Alan Stern3bb1af52008-03-03 15:15:36 -0500312 ehci_handover_companion_ports(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return 0;
314}
315
316#else
317
Alan Stern0c0382e2005-10-13 17:08:02 -0400318#define ehci_bus_suspend NULL
319#define ehci_bus_resume NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321#endif /* CONFIG_PM */
322
323/*-------------------------------------------------------------------------*/
324
Alan Stern57e06c12007-01-16 11:59:45 -0500325/* Display the ports dedicated to the companion controller */
Tony Jones5a3201b2007-09-11 14:07:31 -0700326static ssize_t show_companion(struct device *dev,
327 struct device_attribute *attr,
328 char *buf)
Alan Stern57e06c12007-01-16 11:59:45 -0500329{
330 struct ehci_hcd *ehci;
331 int nports, index, n;
332 int count = PAGE_SIZE;
333 char *ptr = buf;
334
Tony Jones5a3201b2007-09-11 14:07:31 -0700335 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
Alan Stern57e06c12007-01-16 11:59:45 -0500336 nports = HCS_N_PORTS(ehci->hcs_params);
337
338 for (index = 0; index < nports; ++index) {
339 if (test_bit(index, &ehci->companion_ports)) {
340 n = scnprintf(ptr, count, "%d\n", index + 1);
341 ptr += n;
342 count -= n;
343 }
344 }
345 return ptr - buf;
346}
347
348/*
Balaji Rao90da0962007-11-22 01:58:14 +0530349 * Sets the owner of a port
Alan Stern57e06c12007-01-16 11:59:45 -0500350 */
Balaji Rao90da0962007-11-22 01:58:14 +0530351static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
Alan Stern57e06c12007-01-16 11:59:45 -0500352{
Alan Stern57e06c12007-01-16 11:59:45 -0500353 u32 __iomem *status_reg;
354 u32 port_status;
Balaji Rao90da0962007-11-22 01:58:14 +0530355 int try;
Alan Stern57e06c12007-01-16 11:59:45 -0500356
Balaji Rao90da0962007-11-22 01:58:14 +0530357 status_reg = &ehci->regs->port_status[portnum];
Alan Stern57e06c12007-01-16 11:59:45 -0500358
359 /*
360 * The controller won't set the OWNER bit if the port is
361 * enabled, so this loop will sometimes require at least two
362 * iterations: one to disable the port and one to set OWNER.
363 */
Alan Stern57e06c12007-01-16 11:59:45 -0500364 for (try = 4; try > 0; --try) {
365 spin_lock_irq(&ehci->lock);
366 port_status = ehci_readl(ehci, status_reg);
367 if ((port_status & PORT_OWNER) == new_owner
368 || (port_status & (PORT_OWNER | PORT_CONNECT))
369 == 0)
370 try = 0;
371 else {
372 port_status ^= PORT_OWNER;
373 port_status &= ~(PORT_PE | PORT_RWC_BITS);
374 ehci_writel(ehci, port_status, status_reg);
375 }
376 spin_unlock_irq(&ehci->lock);
377 if (try > 1)
378 msleep(5);
379 }
Balaji Rao90da0962007-11-22 01:58:14 +0530380}
381
382/*
383 * Dedicate or undedicate a port to the companion controller.
384 * Syntax is "[-]portnum", where a leading '-' sign means
385 * return control of the port to the EHCI controller.
386 */
387static ssize_t store_companion(struct device *dev,
388 struct device_attribute *attr,
389 const char *buf, size_t count)
390{
391 struct ehci_hcd *ehci;
392 int portnum, new_owner;
393
394 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
395 new_owner = PORT_OWNER; /* Owned by companion */
396 if (sscanf(buf, "%d", &portnum) != 1)
397 return -EINVAL;
398 if (portnum < 0) {
399 portnum = - portnum;
400 new_owner = 0; /* Owned by EHCI */
401 }
402 if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
403 return -ENOENT;
404 portnum--;
405 if (new_owner)
406 set_bit(portnum, &ehci->companion_ports);
407 else
408 clear_bit(portnum, &ehci->companion_ports);
409 set_owner(ehci, portnum, new_owner);
Alan Stern57e06c12007-01-16 11:59:45 -0500410 return count;
411}
Tony Jones5a3201b2007-09-11 14:07:31 -0700412static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
Alan Stern57e06c12007-01-16 11:59:45 -0500413
414static inline void create_companion_file(struct ehci_hcd *ehci)
415{
416 int i;
417
418 /* with integrated TT there is no companion! */
419 if (!ehci_is_TDI(ehci))
Greg Kroah-Hartmaned14f032009-04-27 13:15:38 -0700420 i = device_create_file(ehci_to_hcd(ehci)->self.controller,
Tony Jones5a3201b2007-09-11 14:07:31 -0700421 &dev_attr_companion);
Alan Stern57e06c12007-01-16 11:59:45 -0500422}
423
424static inline void remove_companion_file(struct ehci_hcd *ehci)
425{
426 /* with integrated TT there is no companion! */
427 if (!ehci_is_TDI(ehci))
Greg Kroah-Hartmaned14f032009-04-27 13:15:38 -0700428 device_remove_file(ehci_to_hcd(ehci)->self.controller,
Tony Jones5a3201b2007-09-11 14:07:31 -0700429 &dev_attr_companion);
Alan Stern57e06c12007-01-16 11:59:45 -0500430}
431
432
433/*-------------------------------------------------------------------------*/
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435static int check_reset_complete (
436 struct ehci_hcd *ehci,
437 int index,
Alan Sterne6316562007-01-16 11:58:00 -0500438 u32 __iomem *status_reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 int port_status
440) {
David Brownellcd4cdc92008-01-24 12:39:43 -0800441 if (!(port_status & PORT_CONNECT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return port_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 /* if reset finished and it's still not enabled -- handoff */
445 if (!(port_status & PORT_PE)) {
446
447 /* with integrated TT, there's nobody to hand it to! */
448 if (ehci_is_TDI(ehci)) {
449 ehci_dbg (ehci,
450 "Failed to enable port %d on root hub TT\n",
451 index+1);
452 return port_status;
453 }
454
455 ehci_dbg (ehci, "port %d full speed --> companion\n",
456 index + 1);
457
458 // what happens if HCS_N_CC(params) == 0 ?
459 port_status |= PORT_OWNER;
David Brownell10f65242005-08-31 10:55:38 -0700460 port_status &= ~PORT_RWC_BITS;
Alan Sterne6316562007-01-16 11:58:00 -0500461 ehci_writel(ehci, port_status, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Vitaly Bordug796bcae2008-11-09 19:43:30 +0100463 /* ensure 440EPX ohci controller state is operational */
464 if (ehci->has_amcc_usb23)
465 set_ohci_hcfs(ehci, 1);
466 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 ehci_dbg (ehci, "port %d high speed\n", index + 1);
Vitaly Bordug796bcae2008-11-09 19:43:30 +0100468 /* ensure 440EPx ohci controller state is suspended */
469 if (ehci->has_amcc_usb23)
470 set_ohci_hcfs(ehci, 0);
471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 return port_status;
474}
475
476/*-------------------------------------------------------------------------*/
477
478
479/* build "status change" packet (one or two bytes) from HC registers */
480
481static int
482ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
483{
484 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
485 u32 temp, status = 0;
David Brownell93f1a472006-11-16 23:34:58 -0800486 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 int ports, i, retval = 1;
488 unsigned long flags;
489
490 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
491 if (!HC_IS_RUNNING(hcd->state))
492 return 0;
493
494 /* init status to no-changes */
495 buf [0] = 0;
496 ports = HCS_N_PORTS (ehci->hcs_params);
497 if (ports > 7) {
498 buf [1] = 0;
499 retval++;
500 }
David Brownell53bd6a62006-08-30 14:50:06 -0700501
David Brownell93f1a472006-11-16 23:34:58 -0800502 /* Some boards (mostly VIA?) report bogus overcurrent indications,
503 * causing massive log spam unless we completely ignore them. It
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200504 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
David Brownell93f1a472006-11-16 23:34:58 -0800505 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
506 * PORT_POWER; that's surprising, but maybe within-spec.
507 */
508 if (!ignore_oc)
509 mask = PORT_CSC | PORT_PEC | PORT_OCC;
510 else
511 mask = PORT_CSC | PORT_PEC;
512 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /* no hub change reports (bit 0) for now (power, ...) */
515
516 /* port N changes (bit N)? */
517 spin_lock_irqsave (&ehci->lock, flags);
518 for (i = 0; i < ports; i++) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100519 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern625b5c92007-01-16 11:58:47 -0500520
521 /*
522 * Return status information even for ports with OWNER set.
523 * Otherwise khubd wouldn't see the disconnect event when a
524 * high-speed device is switched over to the companion
525 * controller by the user.
526 */
527
Alan Sterneafe5b92008-10-06 11:25:53 -0400528 if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend)
529 || (ehci->reset_done[i] && time_after_eq(
530 jiffies, ehci->reset_done[i]))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (i < 7)
532 buf [0] |= 1 << (i + 1);
533 else
534 buf [1] |= 1 << (i - 7);
535 status = STS_PCD;
536 }
537 }
538 /* FIXME autosuspend idle root hubs */
539 spin_unlock_irqrestore (&ehci->lock, flags);
540 return status ? retval : 0;
541}
542
543/*-------------------------------------------------------------------------*/
544
545static void
546ehci_hub_descriptor (
547 struct ehci_hcd *ehci,
548 struct usb_hub_descriptor *desc
549) {
550 int ports = HCS_N_PORTS (ehci->hcs_params);
551 u16 temp;
552
553 desc->bDescriptorType = 0x29;
554 desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
555 desc->bHubContrCurrent = 0;
556
557 desc->bNbrPorts = ports;
558 temp = 1 + (ports / 8);
559 desc->bDescLength = 7 + 2 * temp;
560
561 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
562 memset (&desc->bitmap [0], 0, temp);
563 memset (&desc->bitmap [temp], 0xff, temp);
564
565 temp = 0x0008; /* per-port overcurrent reporting */
566 if (HCS_PPC (ehci->hcs_params))
567 temp |= 0x0001; /* per-port power control */
David Brownell56c1e262005-04-09 09:00:29 -0700568 else
569 temp |= 0x0002; /* no power switching */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#if 0
571// re-enable when we support USB_PORT_FEAT_INDICATOR below.
572 if (HCS_INDICATOR (ehci->hcs_params))
573 temp |= 0x0080; /* per-port indicators (LEDs) */
574#endif
Al Virofd05e722008-04-28 07:00:16 +0100575 desc->wHubCharacteristics = cpu_to_le16(temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
578/*-------------------------------------------------------------------------*/
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580static int ehci_hub_control (
581 struct usb_hcd *hcd,
582 u16 typeReq,
583 u16 wValue,
584 u16 wIndex,
585 char *buf,
586 u16 wLength
587) {
588 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
589 int ports = HCS_N_PORTS (ehci->hcs_params);
Alan Stern383975d2007-05-04 11:52:40 -0400590 u32 __iomem *status_reg = &ehci->regs->port_status[
591 (wIndex & 0xff) - 1];
Alek Du331ac6b2009-07-13 12:41:20 +0800592 u32 __iomem *hostpc_reg = NULL;
593 u32 temp, temp1, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 unsigned long flags;
595 int retval = 0;
David Brownellf0d7f272006-11-16 23:56:15 -0800596 unsigned selector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 /*
599 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
600 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
601 * (track current state ourselves) ... blink for diagnostics,
602 * power, "this is the one", etc. EHCI spec supports this.
603 */
604
Alek Du331ac6b2009-07-13 12:41:20 +0800605 if (ehci->has_hostpc)
606 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
607 + HOSTPC0 + 4 * ((wIndex & 0xff) - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 spin_lock_irqsave (&ehci->lock, flags);
609 switch (typeReq) {
610 case ClearHubFeature:
611 switch (wValue) {
612 case C_HUB_LOCAL_POWER:
613 case C_HUB_OVER_CURRENT:
614 /* no hub-wide feature/status flags */
615 break;
616 default:
617 goto error;
618 }
619 break;
620 case ClearPortFeature:
621 if (!wIndex || wIndex > ports)
622 goto error;
623 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -0500624 temp = ehci_readl(ehci, status_reg);
Alan Stern625b5c92007-01-16 11:58:47 -0500625
626 /*
627 * Even if OWNER is set, so the port is owned by the
628 * companion controller, khubd needs to be able to clear
629 * the port-change status bits (especially
630 * USB_PORT_FEAT_C_CONNECTION).
631 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 switch (wValue) {
634 case USB_PORT_FEAT_ENABLE:
Alan Sterne6316562007-01-16 11:58:00 -0500635 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 break;
637 case USB_PORT_FEAT_C_ENABLE:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100638 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC,
Alan Sterne6316562007-01-16 11:58:00 -0500639 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 break;
641 case USB_PORT_FEAT_SUSPEND:
642 if (temp & PORT_RESET)
643 goto error;
David Brownellf8aeb3b2006-01-20 13:55:14 -0800644 if (ehci->no_selective_suspend)
645 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (temp & PORT_SUSPEND) {
647 if ((temp & PORT_PE) == 0)
648 goto error;
649 /* resume signaling for 20 msec */
David Brownell10f65242005-08-31 10:55:38 -0700650 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100651 ehci_writel(ehci, temp | PORT_RESUME,
Alan Sterne6316562007-01-16 11:58:00 -0500652 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 ehci->reset_done [wIndex] = jiffies
654 + msecs_to_jiffies (20);
655 }
656 break;
657 case USB_PORT_FEAT_C_SUSPEND:
Alan Sternd1f114d2008-05-20 16:58:58 -0400658 clear_bit(wIndex, &ehci->port_c_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 break;
660 case USB_PORT_FEAT_POWER:
661 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100662 ehci_writel(ehci,
663 temp & ~(PORT_RWC_BITS | PORT_POWER),
Alan Sterne6316562007-01-16 11:58:00 -0500664 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 break;
666 case USB_PORT_FEAT_C_CONNECTION:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100667 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
Alan Sterne6316562007-01-16 11:58:00 -0500668 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 break;
670 case USB_PORT_FEAT_C_OVER_CURRENT:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100671 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC,
Alan Sterne6316562007-01-16 11:58:00 -0500672 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 break;
674 case USB_PORT_FEAT_C_RESET:
675 /* GetPortStatus clears reset */
676 break;
677 default:
678 goto error;
679 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100680 ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
682 case GetHubDescriptor:
683 ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
684 buf);
685 break;
686 case GetHubStatus:
687 /* no hub-wide feature/status flags */
688 memset (buf, 0, 4);
689 //cpu_to_le32s ((u32 *) buf);
690 break;
691 case GetPortStatus:
692 if (!wIndex || wIndex > ports)
693 goto error;
694 wIndex--;
695 status = 0;
Alan Sterne6316562007-01-16 11:58:00 -0500696 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 // wPortChange bits
699 if (temp & PORT_CSC)
700 status |= 1 << USB_PORT_FEAT_C_CONNECTION;
701 if (temp & PORT_PEC)
702 status |= 1 << USB_PORT_FEAT_C_ENABLE;
Christian Engelmayer756aa6b2007-05-30 11:04:48 -0700703
704 if ((temp & PORT_OCC) && !ignore_oc){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT;
706
Christian Engelmayer756aa6b2007-05-30 11:04:48 -0700707 /*
708 * Hubs should disable port power on over-current.
709 * However, not all EHCI implementations do this
710 * automatically, even if they _do_ support per-port
711 * power switching; they're allowed to just limit the
712 * current. khubd will turn the power back on.
713 */
714 if (HCS_PPC (ehci->hcs_params)){
715 ehci_writel(ehci,
716 temp & ~(PORT_RWC_BITS | PORT_POWER),
717 status_reg);
718 }
719 }
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 /* whoever resumes must GetPortStatus to complete it!! */
Alan Stern629e4422007-01-22 16:08:53 -0500722 if (temp & PORT_RESUME) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Alan Stern629e4422007-01-22 16:08:53 -0500724 /* Remote Wakeup received? */
725 if (!ehci->reset_done[wIndex]) {
726 /* resume signaling for 20 msec */
727 ehci->reset_done[wIndex] = jiffies
728 + msecs_to_jiffies(20);
729 /* check the port again */
730 mod_timer(&ehci_to_hcd(ehci)->rh_timer,
731 ehci->reset_done[wIndex]);
732 }
733
734 /* resume completed? */
735 else if (time_after_eq(jiffies,
736 ehci->reset_done[wIndex])) {
Alan Sterneafe5b92008-10-06 11:25:53 -0400737 clear_bit(wIndex, &ehci->suspended_ports);
Alan Sternd1f114d2008-05-20 16:58:58 -0400738 set_bit(wIndex, &ehci->port_c_suspend);
Alan Stern629e4422007-01-22 16:08:53 -0500739 ehci->reset_done[wIndex] = 0;
740
741 /* stop resume signaling */
742 temp = ehci_readl(ehci, status_reg);
743 ehci_writel(ehci,
Alan Sterne6316562007-01-16 11:58:00 -0500744 temp & ~(PORT_RWC_BITS | PORT_RESUME),
745 status_reg);
Alan Stern629e4422007-01-22 16:08:53 -0500746 retval = handshake(ehci, status_reg,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100747 PORT_RESUME, 0, 2000 /* 2msec */);
Alan Stern629e4422007-01-22 16:08:53 -0500748 if (retval != 0) {
749 ehci_err(ehci,
750 "port %d resume error %d\n",
751 wIndex + 1, retval);
752 goto error;
753 }
754 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757
758 /* whoever resets must GetPortStatus to complete it!! */
759 if ((temp & PORT_RESET)
Alan Stern629e4422007-01-22 16:08:53 -0500760 && time_after_eq(jiffies,
761 ehci->reset_done[wIndex])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 status |= 1 << USB_PORT_FEAT_C_RESET;
763 ehci->reset_done [wIndex] = 0;
764
765 /* force reset to complete */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100766 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
Alan Sterne6316562007-01-16 11:58:00 -0500767 status_reg);
David Brownellc22fa3a2005-06-13 07:15:28 -0700768 /* REVISIT: some hardware needs 550+ usec to clear
769 * this bit; seems too long to spin routinely...
770 */
Alan Sterne6316562007-01-16 11:58:00 -0500771 retval = handshake(ehci, status_reg,
David Brownellc22fa3a2005-06-13 07:15:28 -0700772 PORT_RESET, 0, 750);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (retval != 0) {
774 ehci_err (ehci, "port %d reset error %d\n",
775 wIndex + 1, retval);
776 goto error;
777 }
778
779 /* see what we found out */
Alan Sterne6316562007-01-16 11:58:00 -0500780 temp = check_reset_complete (ehci, wIndex, status_reg,
781 ehci_readl(ehci, status_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
783
Alan Sterneafe5b92008-10-06 11:25:53 -0400784 if (!(temp & (PORT_RESUME|PORT_RESET)))
785 ehci->reset_done[wIndex] = 0;
786
Alan Stern57e06c12007-01-16 11:59:45 -0500787 /* transfer dedicated ports to the companion hc */
788 if ((temp & PORT_CONNECT) &&
789 test_bit(wIndex, &ehci->companion_ports)) {
790 temp &= ~PORT_RWC_BITS;
791 temp |= PORT_OWNER;
792 ehci_writel(ehci, temp, status_reg);
793 ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
794 temp = ehci_readl(ehci, status_reg);
795 }
796
Alan Stern625b5c92007-01-16 11:58:47 -0500797 /*
798 * Even if OWNER is set, there's no harm letting khubd
799 * see the wPortStatus values (they should all be 0 except
800 * for PORT_POWER anyway).
801 */
802
803 if (temp & PORT_CONNECT) {
804 status |= 1 << USB_PORT_FEAT_CONNECTION;
805 // status may be from integrated TT
Alek Du331ac6b2009-07-13 12:41:20 +0800806 if (ehci->has_hostpc) {
807 temp1 = ehci_readl(ehci, hostpc_reg);
808 status |= ehci_port_speed(ehci, temp1);
809 } else
810 status |= ehci_port_speed(ehci, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
Alan Stern625b5c92007-01-16 11:58:47 -0500812 if (temp & PORT_PE)
813 status |= 1 << USB_PORT_FEAT_ENABLE;
Alan Sterneafe5b92008-10-06 11:25:53 -0400814
815 /* maybe the port was unsuspended without our knowledge */
816 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
Alan Stern625b5c92007-01-16 11:58:47 -0500817 status |= 1 << USB_PORT_FEAT_SUSPEND;
Alan Sterneafe5b92008-10-06 11:25:53 -0400818 } else if (test_bit(wIndex, &ehci->suspended_ports)) {
819 clear_bit(wIndex, &ehci->suspended_ports);
820 ehci->reset_done[wIndex] = 0;
821 if (temp & PORT_PE)
822 set_bit(wIndex, &ehci->port_c_suspend);
823 }
824
Alan Stern625b5c92007-01-16 11:58:47 -0500825 if (temp & PORT_OC)
826 status |= 1 << USB_PORT_FEAT_OVER_CURRENT;
827 if (temp & PORT_RESET)
828 status |= 1 << USB_PORT_FEAT_RESET;
829 if (temp & PORT_POWER)
830 status |= 1 << USB_PORT_FEAT_POWER;
Alan Sternd1f114d2008-05-20 16:58:58 -0400831 if (test_bit(wIndex, &ehci->port_c_suspend))
832 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
David Brownell9776afc2008-02-01 11:42:05 -0800834#ifndef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 if (status & ~0xffff) /* only if wPortChange is interesting */
836#endif
837 dbg_port (ehci, "GetStatus", wIndex + 1, temp);
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700838 put_unaligned_le32(status, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 break;
840 case SetHubFeature:
841 switch (wValue) {
842 case C_HUB_LOCAL_POWER:
843 case C_HUB_OVER_CURRENT:
844 /* no hub-wide feature/status flags */
845 break;
846 default:
847 goto error;
848 }
849 break;
850 case SetPortFeature:
David Brownellf0d7f272006-11-16 23:56:15 -0800851 selector = wIndex >> 8;
852 wIndex &= 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (!wIndex || wIndex > ports)
854 goto error;
855 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -0500856 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (temp & PORT_OWNER)
858 break;
859
David Brownell10f65242005-08-31 10:55:38 -0700860 temp &= ~PORT_RWC_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 switch (wValue) {
862 case USB_PORT_FEAT_SUSPEND:
David Brownellf8aeb3b2006-01-20 13:55:14 -0800863 if (ehci->no_selective_suspend)
864 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if ((temp & PORT_PE) == 0
866 || (temp & PORT_RESET) != 0)
867 goto error;
Alan Sterne6316562007-01-16 11:58:00 -0500868 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
Alek Du331ac6b2009-07-13 12:41:20 +0800869 /* After above check the port must be connected.
870 * Set appropriate bit thus could put phy into low power
871 * mode if we have hostpc feature
872 */
873 if (hostpc_reg) {
874 temp &= ~PORT_WKCONN_E;
875 temp |= (PORT_WKDISC_E | PORT_WKOC_E);
876 ehci_writel(ehci, temp | PORT_SUSPEND,
877 status_reg);
878 msleep(5);/* 5ms for HCD enter low pwr mode */
879 temp1 = ehci_readl(ehci, hostpc_reg);
880 ehci_writel(ehci, temp1 | HOSTPC_PHCD,
881 hostpc_reg);
882 temp1 = ehci_readl(ehci, hostpc_reg);
883 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
884 wIndex, (temp1 & HOSTPC_PHCD) ?
885 "succeeded" : "failed");
886 }
Alan Sterneafe5b92008-10-06 11:25:53 -0400887 set_bit(wIndex, &ehci->suspended_ports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 break;
889 case USB_PORT_FEAT_POWER:
890 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100891 ehci_writel(ehci, temp | PORT_POWER,
Alan Sterne6316562007-01-16 11:58:00 -0500892 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 break;
894 case USB_PORT_FEAT_RESET:
895 if (temp & PORT_RESUME)
896 goto error;
897 /* line status bits may report this as low speed,
898 * which can be fine if this root hub has a
899 * transaction translator built in.
900 */
901 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
902 && !ehci_is_TDI(ehci)
903 && PORT_USB11 (temp)) {
904 ehci_dbg (ehci,
905 "port %d low speed --> companion\n",
906 wIndex + 1);
907 temp |= PORT_OWNER;
908 } else {
909 ehci_vdbg (ehci, "port %d reset\n", wIndex + 1);
910 temp |= PORT_RESET;
911 temp &= ~PORT_PE;
912
913 /*
914 * caller must wait, then call GetPortStatus
915 * usb 2.0 spec says 50 ms resets on root
916 */
917 ehci->reset_done [wIndex] = jiffies
918 + msecs_to_jiffies (50);
919 }
Alan Sterne6316562007-01-16 11:58:00 -0500920 ehci_writel(ehci, temp, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 break;
David Brownellf0d7f272006-11-16 23:56:15 -0800922
923 /* For downstream facing ports (these): one hub port is put
924 * into test mode according to USB2 11.24.2.13, then the hub
925 * must be reset (which for root hub now means rmmod+modprobe,
926 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
927 * about the EHCI-specific stuff.
928 */
929 case USB_PORT_FEAT_TEST:
930 if (!selector || selector > 5)
931 goto error;
932 ehci_quiesce(ehci);
933 ehci_halt(ehci);
934 temp |= selector << 16;
Alan Sterne6316562007-01-16 11:58:00 -0500935 ehci_writel(ehci, temp, status_reg);
David Brownellf0d7f272006-11-16 23:56:15 -0800936 break;
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 default:
939 goto error;
940 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100941 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 break;
943
944 default:
945error:
946 /* "stall" on error */
947 retval = -EPIPE;
948 }
949 spin_unlock_irqrestore (&ehci->lock, flags);
950 return retval;
951}
Balaji Rao90da0962007-11-22 01:58:14 +0530952
953static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
954{
955 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
956
957 if (ehci_is_TDI(ehci))
958 return;
959 set_owner(ehci, --portnum, PORT_OWNER);
960}
961
Alan Stern3a311552008-05-20 16:58:29 -0400962static int ehci_port_handed_over(struct usb_hcd *hcd, int portnum)
963{
964 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
965 u32 __iomem *reg;
966
967 if (ehci_is_TDI(ehci))
968 return 0;
969 reg = &ehci->regs->port_status[portnum - 1];
970 return ehci_readl(ehci, reg) & PORT_OWNER;
971}