blob: 47b858fc50b2ee484c035cef8fe8b27c669009b5 [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/*-------------------------------------------------------------------------*/
Anatolij Gustschin83722bc2011-04-18 22:02:00 +020030#include <linux/usb/otg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Alan Stern58a97ff2008-04-14 12:17:10 -040032#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
33
Alan Sternaff6d182008-04-18 11:11:26 -040034#ifdef CONFIG_PM
35
Alan Stern383975d2007-05-04 11:52:40 -040036static int ehci_hub_control(
37 struct usb_hcd *hcd,
38 u16 typeReq,
39 u16 wValue,
40 u16 wIndex,
41 char *buf,
42 u16 wLength
43);
44
Julius Werner9b790912013-05-17 12:08:51 -070045static int persist_enabled_on_companion(struct usb_device *udev, void *unused)
46{
47 return !udev->maxchild && udev->persist_enabled &&
48 udev->bus->root_hub->speed < USB_SPEED_HIGH;
49}
50
Alan Stern383975d2007-05-04 11:52:40 -040051/* After a power loss, ports that were owned by the companion must be
52 * reset so that the companion can still own them.
53 */
54static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
55{
56 u32 __iomem *reg;
57 u32 status;
58 int port;
59 __le32 buf;
60 struct usb_hcd *hcd = ehci_to_hcd(ehci);
61
62 if (!ehci->owned_ports)
63 return;
64
Julius Werner9b790912013-05-17 12:08:51 -070065 /*
66 * USB 1.1 devices are mostly HIDs, which don't need to persist across
67 * suspends. If we ensure that none of our companion's devices have
68 * persist_enabled (by looking through all USB 1.1 buses in the system),
69 * we can skip this and avoid slowing resume down. Devices without
70 * persist will just get reenumerated shortly after resume anyway.
71 */
72 if (!usb_for_each_dev(NULL, persist_enabled_on_companion))
73 return;
74
Alan Sternc73cee72012-10-31 13:21:06 -040075 /* Make sure the ports are powered */
76 port = HCS_N_PORTS(ehci->hcs_params);
77 while (port--) {
78 if (test_bit(port, &ehci->owned_ports)) {
79 reg = &ehci->regs->port_status[port];
80 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
81 if (!(status & PORT_POWER)) {
82 status |= PORT_POWER;
83 ehci_writel(ehci, status, reg);
84 }
85 }
86 }
87
Alan Stern383975d2007-05-04 11:52:40 -040088 /* Give the connections some time to appear */
89 msleep(20);
90
Alan Sternc4f34762012-07-11 11:23:10 -040091 spin_lock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -040092 port = HCS_N_PORTS(ehci->hcs_params);
93 while (port--) {
94 if (test_bit(port, &ehci->owned_ports)) {
95 reg = &ehci->regs->port_status[port];
Alan Stern3c519b82007-05-04 11:55:31 -040096 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Alan Stern383975d2007-05-04 11:52:40 -040097
98 /* Port already owned by companion? */
99 if (status & PORT_OWNER)
100 clear_bit(port, &ehci->owned_ports);
Alan Stern3c519b82007-05-04 11:55:31 -0400101 else if (test_bit(port, &ehci->companion_ports))
102 ehci_writel(ehci, status & ~PORT_PE, reg);
Alan Sternc4f34762012-07-11 11:23:10 -0400103 else {
104 spin_unlock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -0400105 ehci_hub_control(hcd, SetPortFeature,
106 USB_PORT_FEAT_RESET, port + 1,
107 NULL, 0);
Alan Sternc4f34762012-07-11 11:23:10 -0400108 spin_lock_irq(&ehci->lock);
109 }
Alan Stern383975d2007-05-04 11:52:40 -0400110 }
111 }
Alan Sternc4f34762012-07-11 11:23:10 -0400112 spin_unlock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -0400113
114 if (!ehci->owned_ports)
115 return;
116 msleep(90); /* Wait for resets to complete */
117
Alan Sternc4f34762012-07-11 11:23:10 -0400118 spin_lock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -0400119 port = HCS_N_PORTS(ehci->hcs_params);
120 while (port--) {
121 if (test_bit(port, &ehci->owned_ports)) {
Alan Sternc4f34762012-07-11 11:23:10 -0400122 spin_unlock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -0400123 ehci_hub_control(hcd, GetPortStatus,
124 0, port + 1,
125 (char *) &buf, sizeof(buf));
Alan Sternc4f34762012-07-11 11:23:10 -0400126 spin_lock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -0400127
128 /* The companion should now own the port,
129 * but if something went wrong the port must not
130 * remain enabled.
131 */
132 reg = &ehci->regs->port_status[port];
133 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
134 if (status & PORT_OWNER)
135 ehci_writel(ehci, status | PORT_CSC, reg);
136 else {
137 ehci_dbg(ehci, "failed handover port %d: %x\n",
138 port + 1, status);
139 ehci_writel(ehci, status & ~PORT_PE, reg);
140 }
141 }
142 }
143
144 ehci->owned_ports = 0;
Alan Sternc4f34762012-07-11 11:23:10 -0400145 spin_unlock_irq(&ehci->lock);
Alan Stern383975d2007-05-04 11:52:40 -0400146}
147
Alan Sternc5cf9212012-06-28 11:19:02 -0400148static int ehci_port_change(struct ehci_hcd *ehci)
Matthew Garrett294d95f2011-01-11 12:26:48 -0500149{
150 int i = HCS_N_PORTS(ehci->hcs_params);
151
152 /* First check if the controller indicates a change event */
153
154 if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
155 return 1;
156
157 /*
158 * Not all controllers appear to update this while going from D3 to D0,
159 * so check the individual port status registers as well
160 */
161
162 while (i--)
163 if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
164 return 1;
165
166 return 0;
167}
168
Alan Sternc5cf9212012-06-28 11:19:02 -0400169static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
Alan Stern41472002010-06-25 14:02:14 -0400170 bool suspending, bool do_wakeup)
Alan Stern16032c42010-05-12 18:21:35 -0400171{
172 int port;
173 u32 temp;
174
175 /* If remote wakeup is enabled for the root hub but disabled
176 * for the controller, we must adjust all the port wakeup flags
177 * when the controller is suspended or resumed. In all other
178 * cases they don't need to be changed.
179 */
Alan Stern41472002010-06-25 14:02:14 -0400180 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
Alan Stern16032c42010-05-12 18:21:35 -0400181 return;
182
Alan Sternc4f34762012-07-11 11:23:10 -0400183 spin_lock_irq(&ehci->lock);
Yin Kangkai148fc552011-01-28 12:04:35 +0800184
Alan Stern16032c42010-05-12 18:21:35 -0400185 /* clear phy low-power mode before changing wakeup flags */
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +0300186 if (ehci->has_tdi_phy_lpm) {
Alan Stern16032c42010-05-12 18:21:35 -0400187 port = HCS_N_PORTS(ehci->hcs_params);
188 while (port--) {
Alan Sterna46af4e2012-06-25 12:19:03 -0400189 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
Alan Stern16032c42010-05-12 18:21:35 -0400190
Alan Stern16032c42010-05-12 18:21:35 -0400191 temp = ehci_readl(ehci, hostpc_reg);
192 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
193 }
Alan Sternc4f34762012-07-11 11:23:10 -0400194 spin_unlock_irq(&ehci->lock);
Alan Stern16032c42010-05-12 18:21:35 -0400195 msleep(5);
Alan Sternc4f34762012-07-11 11:23:10 -0400196 spin_lock_irq(&ehci->lock);
Alan Stern16032c42010-05-12 18:21:35 -0400197 }
198
199 port = HCS_N_PORTS(ehci->hcs_params);
200 while (port--) {
201 u32 __iomem *reg = &ehci->regs->port_status[port];
202 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
203 u32 t2 = t1 & ~PORT_WAKE_BITS;
204
205 /* If we are suspending the controller, clear the flags.
206 * If we are resuming the controller, set the wakeup flags.
207 */
208 if (!suspending) {
209 if (t1 & PORT_CONNECT)
210 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
211 else
212 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
213 }
Alan Stern16032c42010-05-12 18:21:35 -0400214 ehci_writel(ehci, t2, reg);
215 }
216
217 /* enter phy low-power mode again */
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +0300218 if (ehci->has_tdi_phy_lpm) {
Alan Stern16032c42010-05-12 18:21:35 -0400219 port = HCS_N_PORTS(ehci->hcs_params);
220 while (port--) {
Alan Sterna46af4e2012-06-25 12:19:03 -0400221 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
Alan Stern16032c42010-05-12 18:21:35 -0400222
Alan Stern16032c42010-05-12 18:21:35 -0400223 temp = ehci_readl(ehci, hostpc_reg);
224 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
225 }
226 }
Alan Sternee0b9be2010-06-25 14:02:24 -0400227
228 /* Does the root hub have a port wakeup pending? */
Matthew Garrett294d95f2011-01-11 12:26:48 -0500229 if (!suspending && ehci_port_change(ehci))
Alan Sternee0b9be2010-06-25 14:02:24 -0400230 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
Yin Kangkai148fc552011-01-28 12:04:35 +0800231
Alan Sternc4f34762012-07-11 11:23:10 -0400232 spin_unlock_irq(&ehci->lock);
Alan Stern16032c42010-05-12 18:21:35 -0400233}
234
Alan Stern0c0382e2005-10-13 17:08:02 -0400235static int ehci_bus_suspend (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
238 int port;
Alan Stern8c033562006-11-09 14:42:16 -0500239 int mask;
Alan Stern16032c42010-05-12 18:21:35 -0400240 int changed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Alan Stern8c774fe2007-02-01 16:09:59 -0500242 ehci_dbg(ehci, "suspend root hub\n");
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (time_before (jiffies, ehci->next_statechange))
245 msleep(5);
246
Alan Sternc4f34762012-07-11 11:23:10 -0400247 /* stop the schedules */
248 ehci_quiesce(ehci);
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 spin_lock_irq (&ehci->lock);
Alan Stern43fe3a92012-07-11 11:23:16 -0400251 if (ehci->rh_state < EHCI_RH_RUNNING)
252 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Alan Sterncec3a532010-01-08 11:18:20 -0500254 /* Once the controller is stopped, port resumes that are already
255 * in progress won't complete. Hence if remote wakeup is enabled
256 * for the root hub and any ports are in the middle of a resume or
257 * remote wakeup, we must fail the suspend.
258 */
259 if (hcd->self.root_hub->do_remote_wakeup) {
Alan Sterna448e4d2012-04-03 15:24:30 -0400260 if (ehci->resuming_ports) {
261 spin_unlock_irq(&ehci->lock);
262 ehci_dbg(ehci, "suspend failed because a port is resuming\n");
263 return -EBUSY;
Alan Sterncec3a532010-01-08 11:18:20 -0500264 }
265 }
266
Alan Stern8c033562006-11-09 14:42:16 -0500267 /* Unlike other USB host controller types, EHCI doesn't have
268 * any notion of "global" or bus-wide suspend. The driver has
269 * to manually suspend all the active unsuspended ports, and
270 * then manually resume them in the bus_resume() routine.
271 */
272 ehci->bus_suspended = 0;
Alan Stern383975d2007-05-04 11:52:40 -0400273 ehci->owned_ports = 0;
Alan Stern16032c42010-05-12 18:21:35 -0400274 changed = 0;
Alan Sterncec3a532010-01-08 11:18:20 -0500275 port = HCS_N_PORTS(ehci->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 while (port--) {
277 u32 __iomem *reg = &ehci->regs->port_status [port];
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100278 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Alan Stern16032c42010-05-12 18:21:35 -0400279 u32 t2 = t1 & ~PORT_WAKE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Alan Stern8c033562006-11-09 14:42:16 -0500281 /* keep track of which ports we suspend */
Alan Stern383975d2007-05-04 11:52:40 -0400282 if (t1 & PORT_OWNER)
283 set_bit(port, &ehci->owned_ports);
284 else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 t2 |= PORT_SUSPEND;
Alan Stern8c033562006-11-09 14:42:16 -0500286 set_bit(port, &ehci->bus_suspended);
287 }
288
Alan Stern16032c42010-05-12 18:21:35 -0400289 /* enable remote wakeup on all ports, if told to do so */
Alek Du331ac6b2009-07-13 12:41:20 +0800290 if (hcd->self.root_hub->do_remote_wakeup) {
291 /* only enable appropriate wake bits, otherwise the
292 * hardware can not go phy low power mode. If a race
293 * condition happens here(connection change during bits
294 * set), the port change detection will finally fix it.
295 */
Alan Stern16032c42010-05-12 18:21:35 -0400296 if (t1 & PORT_CONNECT)
Alek Du331ac6b2009-07-13 12:41:20 +0800297 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
Alan Stern16032c42010-05-12 18:21:35 -0400298 else
Alek Du331ac6b2009-07-13 12:41:20 +0800299 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
Alan Stern16032c42010-05-12 18:21:35 -0400300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (t1 != t2) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100303 ehci_writel(ehci, t2, reg);
Alan Stern16032c42010-05-12 18:21:35 -0400304 changed = 1;
305 }
306 }
Alek Du331ac6b2009-07-13 12:41:20 +0800307
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +0300308 if (changed && ehci->has_tdi_phy_lpm) {
Alan Stern16032c42010-05-12 18:21:35 -0400309 spin_unlock_irq(&ehci->lock);
310 msleep(5); /* 5 ms for HCD to enter low-power mode */
311 spin_lock_irq(&ehci->lock);
312
313 port = HCS_N_PORTS(ehci->hcs_params);
314 while (port--) {
Alan Sterna46af4e2012-06-25 12:19:03 -0400315 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
Alan Stern16032c42010-05-12 18:21:35 -0400316 u32 t3;
317
Alan Stern16032c42010-05-12 18:21:35 -0400318 t3 = ehci_readl(ehci, hostpc_reg);
319 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
320 t3 = ehci_readl(ehci, hostpc_reg);
321 ehci_dbg(ehci, "Port %d phy low-power mode %s\n",
Alek Du331ac6b2009-07-13 12:41:20 +0800322 port, (t3 & HOSTPC_PHCD) ?
323 "succeeded" : "failed");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325 }
Alan Sternc4f34762012-07-11 11:23:10 -0400326 spin_unlock_irq(&ehci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Alan Sterncd930c92008-01-10 11:14:53 -0500328 /* Apparently some devices need a >= 1-uframe delay here */
329 if (ehci->bus_suspended)
330 udelay(150);
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 /* turn off now-idle HC */
333 ehci_halt (ehci);
Alan Sternc4f34762012-07-11 11:23:10 -0400334
335 spin_lock_irq(&ehci->lock);
Alan Stern43fe3a92012-07-11 11:23:16 -0400336 if (ehci->enabled_hrtimer_events & BIT(EHCI_HRTIMER_POLL_DEAD))
337 ehci_handle_controller_death(ehci);
338 if (ehci->rh_state != EHCI_RH_RUNNING)
339 goto done;
Alan Sterne8799902011-08-18 16:31:30 -0400340 ehci->rh_state = EHCI_RH_SUSPENDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Alan Stern3c273a02012-07-11 11:22:49 -0400342 end_unlink_async(ehci);
Alan Stern2a40f322013-03-15 14:40:26 -0400343 unlink_empty_async_suspended(ehci);
Ming Lei9118f9e2013-07-03 22:53:10 +0800344 ehci_handle_start_intr_unlinks(ehci);
Alan Sterndf202252012-07-11 11:22:26 -0400345 ehci_handle_intr_unlinks(ehci);
Alan Stern55934eb2012-07-11 11:22:35 -0400346 end_free_itds(ehci);
David Brownellcdc647a2008-04-02 13:40:20 -0700347
Alan Stern8c033562006-11-09 14:42:16 -0500348 /* allow remote wakeup */
349 mask = INTR_MASK;
Alan Stern58a97ff2008-04-14 12:17:10 -0400350 if (!hcd->self.root_hub->do_remote_wakeup)
Alan Stern8c033562006-11-09 14:42:16 -0500351 mask &= ~STS_PCD;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100352 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
353 ehci_readl(ehci, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500354
Alan Stern43fe3a92012-07-11 11:23:16 -0400355 done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
Alan Sternd58b4bc2012-07-11 11:21:54 -0400357 ehci->enabled_hrtimer_events = 0;
358 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 spin_unlock_irq (&ehci->lock);
Jon Hunter015798b2009-08-12 11:57:59 -0400360
Alan Sternd58b4bc2012-07-11 11:21:54 -0400361 hrtimer_cancel(&ehci->hrtimer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return 0;
363}
364
365
366/* caller has locked the root hub, and should reset/reinit on error */
Alan Stern0c0382e2005-10-13 17:08:02 -0400367static int ehci_bus_resume (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
370 u32 temp;
Alan Stern383975d2007-05-04 11:52:40 -0400371 u32 power_okay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 int i;
Wang Zhid0f2fb22011-08-17 10:39:31 +0800373 unsigned long resume_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 if (time_before (jiffies, ehci->next_statechange))
376 msleep(5);
377 spin_lock_irq (&ehci->lock);
Alan Stern43fe3a92012-07-11 11:23:16 -0400378 if (!HCD_HW_ACCESSIBLE(hcd) || ehci->shutdown)
379 goto shutdown;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Jason Wesselad45f1d2009-08-20 15:39:58 -0500381 if (unlikely(ehci->debug)) {
Jan Beulich9fa57802012-09-18 12:23:02 +0100382 if (!dbgp_reset_prep(hcd))
Jason Wesselad45f1d2009-08-20 15:39:58 -0500383 ehci->debug = NULL;
384 else
Jan Beulich9fa57802012-09-18 12:23:02 +0100385 dbgp_external_startup(hcd);
Jason Wesselad45f1d2009-08-20 15:39:58 -0500386 }
387
David Brownellf03c17f2005-11-23 15:45:28 -0800388 /* Ideally and we've got a real resume here, and no port's power
389 * was lost. (For PCI, that means Vaux was maintained.) But we
390 * could instead be restoring a swsusp snapshot -- so that BIOS was
391 * the last user of the controller, not reset/pm hardware keeping
392 * state we gave to it.
393 */
Alan Stern383975d2007-05-04 11:52:40 -0400394 power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
395 ehci_dbg(ehci, "resume root hub%s\n",
396 power_okay ? "" : " after power loss");
David Brownellf03c17f2005-11-23 15:45:28 -0800397
Alan Stern8c033562006-11-09 14:42:16 -0500398 /* at least some APM implementations will try to deliver
399 * IRQs right away, so delay them until we're ready.
400 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100401 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500402
403 /* re-init operational registers */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100404 ehci_writel(ehci, 0, &ehci->regs->segment);
405 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
406 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 /* restore CMD_RUN, framelist size, and irq threshold */
Alan Stern3d9545c2012-04-23 13:54:36 -0400409 ehci->command |= CMD_RUN;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100410 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Alan Sterne8799902011-08-18 16:31:30 -0400411 ehci->rh_state = EHCI_RH_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Peter Chen6273f182012-10-18 12:24:43 +0800413 /*
414 * According to Bugzilla #8190, the port status for some controllers
415 * will be wrong without a delay. At their wrong status, the port
416 * is enabled, but not suspended neither resumed.
417 */
418 i = HCS_N_PORTS(ehci->hcs_params);
419 while (i--) {
420 temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
421 if ((temp & PORT_PE) &&
422 !(temp & (PORT_SUSPEND | PORT_RESUME))) {
423 ehci_dbg(ehci, "Port status(0x%x) is wrong\n", temp);
424 spin_unlock_irq(&ehci->lock);
425 msleep(8);
426 spin_lock_irq(&ehci->lock);
427 break;
428 }
429 }
430
Alan Stern43fe3a92012-07-11 11:23:16 -0400431 if (ehci->shutdown)
432 goto shutdown;
Alan Sterne198a312007-03-15 15:54:30 -0400433
Alan Stern16032c42010-05-12 18:21:35 -0400434 /* clear phy low-power mode before resume */
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +0300435 if (ehci->bus_suspended && ehci->has_tdi_phy_lpm) {
Alan Stern16032c42010-05-12 18:21:35 -0400436 i = HCS_N_PORTS(ehci->hcs_params);
437 while (i--) {
438 if (test_bit(i, &ehci->bus_suspended)) {
Alan Sterna46af4e2012-06-25 12:19:03 -0400439 u32 __iomem *hostpc_reg =
440 &ehci->regs->hostpc[i];
Alan Stern16032c42010-05-12 18:21:35 -0400441
Alan Stern16032c42010-05-12 18:21:35 -0400442 temp = ehci_readl(ehci, hostpc_reg);
443 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
444 hostpc_reg);
445 }
446 }
447 spin_unlock_irq(&ehci->lock);
448 msleep(5);
449 spin_lock_irq(&ehci->lock);
Alan Stern43fe3a92012-07-11 11:23:16 -0400450 if (ehci->shutdown)
451 goto shutdown;
Alan Stern16032c42010-05-12 18:21:35 -0400452 }
453
Alan Stern8c033562006-11-09 14:42:16 -0500454 /* manually resume the ports we suspended during bus_suspend() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 i = HCS_N_PORTS (ehci->hcs_params);
456 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100457 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern58a97ff2008-04-14 12:17:10 -0400458 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
Alan Stern8c033562006-11-09 14:42:16 -0500459 if (test_bit(i, &ehci->bus_suspended) &&
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530460 (temp & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 temp |= PORT_RESUME;
Wang Zhid0f2fb22011-08-17 10:39:31 +0800462 set_bit(i, &resume_needed);
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530463 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100464 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530466
467 /* msleep for 20ms only if code is trying to resume port */
468 if (resume_needed) {
469 spin_unlock_irq(&ehci->lock);
470 msleep(20);
471 spin_lock_irq(&ehci->lock);
Alan Stern43fe3a92012-07-11 11:23:16 -0400472 if (ehci->shutdown)
473 goto shutdown;
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530474 }
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 i = HCS_N_PORTS (ehci->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100478 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Wang Zhid0f2fb22011-08-17 10:39:31 +0800479 if (test_bit(i, &resume_needed)) {
Alan Stern24b90812013-03-18 12:05:42 -0400480 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100481 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Alan Stern8c033562006-11-09 14:42:16 -0500482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
Alan Sternc4f34762012-07-11 11:23:10 -0400486 spin_unlock_irq(&ehci->lock);
487
488 ehci_handover_companion_ports(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 /* Now we can safely re-enable irqs */
Alan Stern43fe3a92012-07-11 11:23:16 -0400491 spin_lock_irq(&ehci->lock);
492 if (ehci->shutdown)
493 goto shutdown;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100494 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
Alan Stern15be1052012-07-11 11:21:17 -0400495 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
Alan Stern43fe3a92012-07-11 11:23:16 -0400496 spin_unlock_irq(&ehci->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 return 0;
Alan Stern43fe3a92012-07-11 11:23:16 -0400499
500 shutdown:
501 spin_unlock_irq(&ehci->lock);
502 return -ESHUTDOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505#else
506
Alan Stern0c0382e2005-10-13 17:08:02 -0400507#define ehci_bus_suspend NULL
508#define ehci_bus_resume NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510#endif /* CONFIG_PM */
511
512/*-------------------------------------------------------------------------*/
513
Alan Stern57e06c12007-01-16 11:59:45 -0500514/*
Balaji Rao90da0962007-11-22 01:58:14 +0530515 * Sets the owner of a port
Alan Stern57e06c12007-01-16 11:59:45 -0500516 */
Balaji Rao90da0962007-11-22 01:58:14 +0530517static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
Alan Stern57e06c12007-01-16 11:59:45 -0500518{
Alan Stern57e06c12007-01-16 11:59:45 -0500519 u32 __iomem *status_reg;
520 u32 port_status;
Balaji Rao90da0962007-11-22 01:58:14 +0530521 int try;
Alan Stern57e06c12007-01-16 11:59:45 -0500522
Balaji Rao90da0962007-11-22 01:58:14 +0530523 status_reg = &ehci->regs->port_status[portnum];
Alan Stern57e06c12007-01-16 11:59:45 -0500524
525 /*
526 * The controller won't set the OWNER bit if the port is
527 * enabled, so this loop will sometimes require at least two
528 * iterations: one to disable the port and one to set OWNER.
529 */
Alan Stern57e06c12007-01-16 11:59:45 -0500530 for (try = 4; try > 0; --try) {
531 spin_lock_irq(&ehci->lock);
532 port_status = ehci_readl(ehci, status_reg);
533 if ((port_status & PORT_OWNER) == new_owner
534 || (port_status & (PORT_OWNER | PORT_CONNECT))
535 == 0)
536 try = 0;
537 else {
538 port_status ^= PORT_OWNER;
539 port_status &= ~(PORT_PE | PORT_RWC_BITS);
540 ehci_writel(ehci, port_status, status_reg);
541 }
542 spin_unlock_irq(&ehci->lock);
543 if (try > 1)
544 msleep(5);
545 }
Balaji Rao90da0962007-11-22 01:58:14 +0530546}
547
Alan Stern57e06c12007-01-16 11:59:45 -0500548/*-------------------------------------------------------------------------*/
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550static int check_reset_complete (
551 struct ehci_hcd *ehci,
552 int index,
Alan Sterne6316562007-01-16 11:58:00 -0500553 u32 __iomem *status_reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 int port_status
555) {
David Brownellcd4cdc92008-01-24 12:39:43 -0800556 if (!(port_status & PORT_CONNECT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return port_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 /* if reset finished and it's still not enabled -- handoff */
560 if (!(port_status & PORT_PE)) {
561
562 /* with integrated TT, there's nobody to hand it to! */
563 if (ehci_is_TDI(ehci)) {
564 ehci_dbg (ehci,
565 "Failed to enable port %d on root hub TT\n",
566 index+1);
567 return port_status;
568 }
569
570 ehci_dbg (ehci, "port %d full speed --> companion\n",
571 index + 1);
572
573 // what happens if HCS_N_CC(params) == 0 ?
574 port_status |= PORT_OWNER;
David Brownell10f65242005-08-31 10:55:38 -0700575 port_status &= ~PORT_RWC_BITS;
Alan Sterne6316562007-01-16 11:58:00 -0500576 ehci_writel(ehci, port_status, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Vitaly Bordug796bcae2008-11-09 19:43:30 +0100578 /* ensure 440EPX ohci controller state is operational */
579 if (ehci->has_amcc_usb23)
580 set_ohci_hcfs(ehci, 1);
581 } else {
Peter Chen0ca7eb22012-03-29 09:50:06 +0800582 ehci_dbg(ehci, "port %d reset complete, port enabled\n",
583 index + 1);
Vitaly Bordug796bcae2008-11-09 19:43:30 +0100584 /* ensure 440EPx ohci controller state is suspended */
585 if (ehci->has_amcc_usb23)
586 set_ohci_hcfs(ehci, 0);
587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 return port_status;
590}
591
592/*-------------------------------------------------------------------------*/
593
594
595/* build "status change" packet (one or two bytes) from HC registers */
596
597static int
598ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
599{
600 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
Alan Sterna448e4d2012-04-03 15:24:30 -0400601 u32 temp, status;
David Brownell93f1a472006-11-16 23:34:58 -0800602 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 int ports, i, retval = 1;
604 unsigned long flags;
Alan Stern4dd405a2013-03-18 12:05:08 -0400605 u32 ppcd = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 /* init status to no-changes */
608 buf [0] = 0;
609 ports = HCS_N_PORTS (ehci->hcs_params);
610 if (ports > 7) {
611 buf [1] = 0;
612 retval++;
613 }
David Brownell53bd6a62006-08-30 14:50:06 -0700614
Alan Sterna448e4d2012-04-03 15:24:30 -0400615 /* Inform the core about resumes-in-progress by returning
616 * a non-zero value even if there are no status changes.
617 */
618 status = ehci->resuming_ports;
619
David Brownell93f1a472006-11-16 23:34:58 -0800620 /* Some boards (mostly VIA?) report bogus overcurrent indications,
621 * causing massive log spam unless we completely ignore them. It
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200622 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
David Brownell93f1a472006-11-16 23:34:58 -0800623 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
624 * PORT_POWER; that's surprising, but maybe within-spec.
625 */
626 if (!ignore_oc)
627 mask = PORT_CSC | PORT_PEC | PORT_OCC;
628 else
629 mask = PORT_CSC | PORT_PEC;
630 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 /* no hub change reports (bit 0) for now (power, ...) */
633
634 /* port N changes (bit N)? */
635 spin_lock_irqsave (&ehci->lock, flags);
Alek Du5a9cdf32010-06-04 15:47:56 +0800636
637 /* get per-port change detect bits */
638 if (ehci->has_ppcd)
639 ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 for (i = 0; i < ports; i++) {
Alek Du5a9cdf32010-06-04 15:47:56 +0800642 /* leverage per-port change bits feature */
Alan Stern4dd405a2013-03-18 12:05:08 -0400643 if (ppcd & (1 << i))
644 temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
645 else
646 temp = 0;
Alan Stern625b5c92007-01-16 11:58:47 -0500647
648 /*
649 * Return status information even for ports with OWNER set.
650 * Otherwise khubd wouldn't see the disconnect event when a
651 * high-speed device is switched over to the companion
652 * controller by the user.
653 */
654
Alan Sterneafe5b92008-10-06 11:25:53 -0400655 if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend)
656 || (ehci->reset_done[i] && time_after_eq(
657 jiffies, ehci->reset_done[i]))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 if (i < 7)
659 buf [0] |= 1 << (i + 1);
660 else
661 buf [1] |= 1 << (i - 7);
662 status = STS_PCD;
663 }
664 }
Alan Sternee742902013-01-25 17:17:43 -0500665
666 /* If a resume is in progress, make sure it can finish */
667 if (ehci->resuming_ports)
668 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(25));
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 spin_unlock_irqrestore (&ehci->lock, flags);
671 return status ? retval : 0;
672}
673
674/*-------------------------------------------------------------------------*/
675
676static void
677ehci_hub_descriptor (
678 struct ehci_hcd *ehci,
679 struct usb_hub_descriptor *desc
680) {
681 int ports = HCS_N_PORTS (ehci->hcs_params);
682 u16 temp;
683
684 desc->bDescriptorType = 0x29;
685 desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
686 desc->bHubContrCurrent = 0;
687
688 desc->bNbrPorts = ports;
689 temp = 1 + (ports / 8);
690 desc->bDescLength = 7 + 2 * temp;
691
692 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
John Youndbe79bb2001-09-17 00:00:00 -0700693 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
694 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 temp = 0x0008; /* per-port overcurrent reporting */
697 if (HCS_PPC (ehci->hcs_params))
698 temp |= 0x0001; /* per-port power control */
David Brownell56c1e262005-04-09 09:00:29 -0700699 else
700 temp |= 0x0002; /* no power switching */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#if 0
702// re-enable when we support USB_PORT_FEAT_INDICATOR below.
703 if (HCS_INDICATOR (ehci->hcs_params))
704 temp |= 0x0080; /* per-port indicators (LEDs) */
705#endif
Al Virofd05e722008-04-28 07:00:16 +0100706 desc->wHubCharacteristics = cpu_to_le16(temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
709/*-------------------------------------------------------------------------*/
Jack Pham726a85c2013-08-13 13:40:13 -0700710#ifdef CONFIG_USB_HCD_TEST_MODE
711
Manu Gautam9841f372013-08-08 16:49:24 -0700712#define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06
713
714static void usb_ehset_completion(struct urb *urb)
715{
716 struct completion *done = urb->context;
717
718 complete(done);
719}
720static int submit_single_step_set_feature(
721 struct usb_hcd *hcd,
722 struct urb *urb,
723 int is_setup
724);
725
726/*
727 * Allocate and initialize a control URB. This request will be used by the
728 * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages
729 * of the GetDescriptor request are sent 15 seconds after the SETUP stage.
730 * Return NULL if failed.
731 */
732static struct urb *request_single_step_set_feature_urb(
733 struct usb_device *udev,
734 void *dr,
735 void *buf,
736 struct completion *done
737) {
738 struct urb *urb;
739 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
740 struct usb_host_endpoint *ep;
741
742 urb = usb_alloc_urb(0, GFP_KERNEL);
743 if (!urb)
744 return NULL;
745
746 urb->pipe = usb_rcvctrlpipe(udev, 0);
747 ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out)
748 [usb_pipeendpoint(urb->pipe)];
749 if (!ep) {
750 usb_free_urb(urb);
751 return NULL;
752 }
753
754 urb->ep = ep;
755 urb->dev = udev;
756 urb->setup_packet = (void *)dr;
757 urb->transfer_buffer = buf;
758 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE;
759 urb->complete = usb_ehset_completion;
760 urb->status = -EINPROGRESS;
761 urb->actual_length = 0;
762 urb->transfer_flags = URB_DIR_IN;
763 usb_get_urb(urb);
764 atomic_inc(&urb->use_count);
765 atomic_inc(&urb->dev->urbnum);
766 urb->setup_dma = dma_map_single(
767 hcd->self.controller,
768 urb->setup_packet,
769 sizeof(struct usb_ctrlrequest),
770 DMA_TO_DEVICE);
771 urb->transfer_dma = dma_map_single(
772 hcd->self.controller,
773 urb->transfer_buffer,
774 urb->transfer_buffer_length,
775 DMA_FROM_DEVICE);
776 urb->context = done;
777 return urb;
778}
779
780static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
781{
782 int retval = -ENOMEM;
783 struct usb_ctrlrequest *dr;
784 struct urb *urb;
785 struct usb_device *udev;
786 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
787 struct usb_device_descriptor *buf;
788 DECLARE_COMPLETION_ONSTACK(done);
789
790 /* Obtain udev of the rhub's child port */
791 udev = usb_hub_find_child(hcd->self.root_hub, port);
792 if (!udev) {
793 ehci_err(ehci, "No device attached to the RootHub\n");
794 return -ENODEV;
795 }
796 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
797 if (!buf)
798 return -ENOMEM;
799
800 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
801 if (!dr) {
802 kfree(buf);
803 return -ENOMEM;
804 }
805
806 /* Fill Setup packet for GetDescriptor */
807 dr->bRequestType = USB_DIR_IN;
808 dr->bRequest = USB_REQ_GET_DESCRIPTOR;
809 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8);
810 dr->wIndex = 0;
811 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE);
812 urb = request_single_step_set_feature_urb(udev, dr, buf, &done);
813 if (!urb)
814 goto cleanup;
815
816 /* Submit just the SETUP stage */
817 retval = submit_single_step_set_feature(hcd, urb, 1);
818 if (retval)
819 goto out1;
820 if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) {
821 usb_kill_urb(urb);
822 retval = -ETIMEDOUT;
823 ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__);
824 goto out1;
825 }
826 msleep(15 * 1000);
827
828 /* Complete remaining DATA and STATUS stages using the same URB */
829 urb->status = -EINPROGRESS;
830 usb_get_urb(urb);
831 atomic_inc(&urb->use_count);
832 atomic_inc(&urb->dev->urbnum);
833 retval = submit_single_step_set_feature(hcd, urb, 0);
834 if (!retval && !wait_for_completion_timeout(&done,
835 msecs_to_jiffies(2000))) {
836 usb_kill_urb(urb);
837 retval = -ETIMEDOUT;
838 ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__);
839 }
840out1:
841 usb_free_urb(urb);
842cleanup:
843 kfree(dr);
844 kfree(buf);
845 return retval;
846}
Jack Pham726a85c2013-08-13 13:40:13 -0700847#endif /* CONFIG_USB_HCD_TEST_MODE */
Manu Gautam9841f372013-08-08 16:49:24 -0700848/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850static int ehci_hub_control (
851 struct usb_hcd *hcd,
852 u16 typeReq,
853 u16 wValue,
854 u16 wIndex,
855 char *buf,
856 u16 wLength
857) {
858 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
859 int ports = HCS_N_PORTS (ehci->hcs_params);
Alan Stern383975d2007-05-04 11:52:40 -0400860 u32 __iomem *status_reg = &ehci->regs->port_status[
861 (wIndex & 0xff) - 1];
Alan Sterna46af4e2012-06-25 12:19:03 -0400862 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
Alek Du331ac6b2009-07-13 12:41:20 +0800863 u32 temp, temp1, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 unsigned long flags;
865 int retval = 0;
David Brownellf0d7f272006-11-16 23:56:15 -0800866 unsigned selector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 /*
869 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
870 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
871 * (track current state ourselves) ... blink for diagnostics,
872 * power, "this is the one", etc. EHCI spec supports this.
873 */
874
875 spin_lock_irqsave (&ehci->lock, flags);
876 switch (typeReq) {
877 case ClearHubFeature:
878 switch (wValue) {
879 case C_HUB_LOCAL_POWER:
880 case C_HUB_OVER_CURRENT:
881 /* no hub-wide feature/status flags */
882 break;
883 default:
884 goto error;
885 }
886 break;
887 case ClearPortFeature:
888 if (!wIndex || wIndex > ports)
889 goto error;
890 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -0500891 temp = ehci_readl(ehci, status_reg);
Stephen Warren6d5f89c2012-04-18 15:32:46 -0600892 temp &= ~PORT_RWC_BITS;
Alan Stern625b5c92007-01-16 11:58:47 -0500893
894 /*
895 * Even if OWNER is set, so the port is owned by the
896 * companion controller, khubd needs to be able to clear
897 * the port-change status bits (especially
Alan Stern749da5f2010-03-04 17:05:08 -0500898 * USB_PORT_STAT_C_CONNECTION).
Alan Stern625b5c92007-01-16 11:58:47 -0500899 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 switch (wValue) {
902 case USB_PORT_FEAT_ENABLE:
Alan Sterne6316562007-01-16 11:58:00 -0500903 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 break;
905 case USB_PORT_FEAT_C_ENABLE:
Stephen Warren6d5f89c2012-04-18 15:32:46 -0600906 ehci_writel(ehci, temp | PORT_PEC, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 break;
908 case USB_PORT_FEAT_SUSPEND:
909 if (temp & PORT_RESET)
910 goto error;
David Brownellf8aeb3b2006-01-20 13:55:14 -0800911 if (ehci->no_selective_suspend)
912 break;
Anatolij Gustschin83722bc2011-04-18 22:02:00 +0200913#ifdef CONFIG_USB_OTG
914 if ((hcd->self.otg_port == (wIndex + 1))
915 && hcd->self.b_hnp_enable) {
Richard Zhaoc2e935a2012-06-13 20:34:12 +0800916 otg_start_hnp(hcd->phy->otg);
Anatolij Gustschin83722bc2011-04-18 22:02:00 +0200917 break;
918 }
919#endif
Alan Stern16032c42010-05-12 18:21:35 -0400920 if (!(temp & PORT_SUSPEND))
921 break;
922 if ((temp & PORT_PE) == 0)
923 goto error;
924
925 /* clear phy low-power mode before resume */
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +0300926 if (ehci->has_tdi_phy_lpm) {
Alan Stern16032c42010-05-12 18:21:35 -0400927 temp1 = ehci_readl(ehci, hostpc_reg);
928 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
Alek Dueab80de2010-05-10 11:17:49 +0800929 hostpc_reg);
Alan Stern16032c42010-05-12 18:21:35 -0400930 spin_unlock_irqrestore(&ehci->lock, flags);
931 msleep(5);/* wait to leave low-power mode */
932 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
Alan Stern16032c42010-05-12 18:21:35 -0400934 /* resume signaling for 20 msec */
Stephen Warren6d5f89c2012-04-18 15:32:46 -0600935 temp &= ~PORT_WAKE_BITS;
Alan Stern16032c42010-05-12 18:21:35 -0400936 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
937 ehci->reset_done[wIndex] = jiffies
938 + msecs_to_jiffies(20);
Alan Stern3a204462013-08-01 17:09:23 -0400939 set_bit(wIndex, &ehci->resuming_ports);
940 usb_hcd_start_port_resume(&hcd->self, wIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 break;
942 case USB_PORT_FEAT_C_SUSPEND:
Alan Sternd1f114d2008-05-20 16:58:58 -0400943 clear_bit(wIndex, &ehci->port_c_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 break;
945 case USB_PORT_FEAT_POWER:
946 if (HCS_PPC (ehci->hcs_params))
Stephen Warren6d5f89c2012-04-18 15:32:46 -0600947 ehci_writel(ehci, temp & ~PORT_POWER,
948 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 break;
950 case USB_PORT_FEAT_C_CONNECTION:
Stephen Warren6d5f89c2012-04-18 15:32:46 -0600951 ehci_writel(ehci, temp | PORT_CSC, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 break;
953 case USB_PORT_FEAT_C_OVER_CURRENT:
Stephen Warren6d5f89c2012-04-18 15:32:46 -0600954 ehci_writel(ehci, temp | PORT_OCC, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 break;
956 case USB_PORT_FEAT_C_RESET:
957 /* GetPortStatus clears reset */
958 break;
959 default:
960 goto error;
961 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100962 ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 break;
964 case GetHubDescriptor:
965 ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
966 buf);
967 break;
968 case GetHubStatus:
969 /* no hub-wide feature/status flags */
970 memset (buf, 0, 4);
971 //cpu_to_le32s ((u32 *) buf);
972 break;
973 case GetPortStatus:
974 if (!wIndex || wIndex > ports)
975 goto error;
976 wIndex--;
977 status = 0;
Alan Sterne6316562007-01-16 11:58:00 -0500978 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 // wPortChange bits
981 if (temp & PORT_CSC)
Alan Stern749da5f2010-03-04 17:05:08 -0500982 status |= USB_PORT_STAT_C_CONNECTION << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (temp & PORT_PEC)
Alan Stern749da5f2010-03-04 17:05:08 -0500984 status |= USB_PORT_STAT_C_ENABLE << 16;
Christian Engelmayer756aa6b2007-05-30 11:04:48 -0700985
986 if ((temp & PORT_OCC) && !ignore_oc){
Alan Stern749da5f2010-03-04 17:05:08 -0500987 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Christian Engelmayer756aa6b2007-05-30 11:04:48 -0700989 /*
990 * Hubs should disable port power on over-current.
991 * However, not all EHCI implementations do this
992 * automatically, even if they _do_ support per-port
993 * power switching; they're allowed to just limit the
994 * current. khubd will turn the power back on.
995 */
Christian Engelmayere6604a72013-04-03 12:18:51 +0200996 if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
997 && HCS_PPC(ehci->hcs_params)) {
Christian Engelmayer756aa6b2007-05-30 11:04:48 -0700998 ehci_writel(ehci,
999 temp & ~(PORT_RWC_BITS | PORT_POWER),
1000 status_reg);
Sergei Shtylyov81463c12011-07-06 23:19:38 +04001001 temp = ehci_readl(ehci, status_reg);
Christian Engelmayer756aa6b2007-05-30 11:04:48 -07001002 }
1003 }
1004
Alan Stern6753f4c2013-08-01 17:09:28 -04001005 /* no reset or resume pending */
1006 if (!ehci->reset_done[wIndex]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Alan Stern629e4422007-01-22 16:08:53 -05001008 /* Remote Wakeup received? */
Alan Stern6753f4c2013-08-01 17:09:28 -04001009 if (temp & PORT_RESUME) {
Alan Stern629e4422007-01-22 16:08:53 -05001010 /* resume signaling for 20 msec */
1011 ehci->reset_done[wIndex] = jiffies
1012 + msecs_to_jiffies(20);
Alan Sternf292e7f2013-01-25 17:09:49 -05001013 usb_hcd_start_port_resume(&hcd->self, wIndex);
Roger Quadros47a64a12013-07-09 17:03:50 +03001014 set_bit(wIndex, &ehci->resuming_ports);
Alan Stern629e4422007-01-22 16:08:53 -05001015 /* check the port again */
1016 mod_timer(&ehci_to_hcd(ehci)->rh_timer,
1017 ehci->reset_done[wIndex]);
1018 }
1019
Alan Stern6753f4c2013-08-01 17:09:28 -04001020 /* reset or resume not yet complete */
1021 } else if (!time_after_eq(jiffies, ehci->reset_done[wIndex])) {
1022 ; /* wait until it is complete */
Alan Stern629e4422007-01-22 16:08:53 -05001023
Alan Stern6753f4c2013-08-01 17:09:28 -04001024 /* resume completed */
1025 } else if (test_bit(wIndex, &ehci->resuming_ports)) {
1026 clear_bit(wIndex, &ehci->suspended_ports);
1027 set_bit(wIndex, &ehci->port_c_suspend);
1028 ehci->reset_done[wIndex] = 0;
1029 usb_hcd_end_port_resume(&hcd->self, wIndex);
1030
1031 /* stop resume signaling */
1032 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
1033 ehci_writel(ehci, temp, status_reg);
1034 clear_bit(wIndex, &ehci->resuming_ports);
1035 retval = ehci_handshake(ehci, status_reg,
1036 PORT_RESUME, 0, 2000 /* 2msec */);
1037 if (retval != 0) {
1038 ehci_err(ehci, "port %d resume error %d\n",
Alan Stern629e4422007-01-22 16:08:53 -05001039 wIndex + 1, retval);
Alan Stern6753f4c2013-08-01 17:09:28 -04001040 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
Alan Stern6753f4c2013-08-01 17:09:28 -04001042 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 /* whoever resets must GetPortStatus to complete it!! */
Alan Stern6753f4c2013-08-01 17:09:28 -04001045 } else {
Alan Stern749da5f2010-03-04 17:05:08 -05001046 status |= USB_PORT_STAT_C_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 ehci->reset_done [wIndex] = 0;
1048
1049 /* force reset to complete */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001050 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
Alan Sterne6316562007-01-16 11:58:00 -05001051 status_reg);
David Brownellc22fa3a2005-06-13 07:15:28 -07001052 /* REVISIT: some hardware needs 550+ usec to clear
1053 * this bit; seems too long to spin routinely...
1054 */
Manjunath Goudar2f3a6b82013-06-13 11:24:09 -06001055 retval = ehci_handshake(ehci, status_reg,
Dinh Nguyen6307e092010-04-13 11:13:15 -05001056 PORT_RESET, 0, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (retval != 0) {
1058 ehci_err (ehci, "port %d reset error %d\n",
1059 wIndex + 1, retval);
1060 goto error;
1061 }
1062
1063 /* see what we found out */
Alan Sterne6316562007-01-16 11:58:00 -05001064 temp = check_reset_complete (ehci, wIndex, status_reg,
1065 ehci_readl(ehci, status_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 }
1067
Alan Stern57e06c12007-01-16 11:59:45 -05001068 /* transfer dedicated ports to the companion hc */
1069 if ((temp & PORT_CONNECT) &&
1070 test_bit(wIndex, &ehci->companion_ports)) {
1071 temp &= ~PORT_RWC_BITS;
1072 temp |= PORT_OWNER;
1073 ehci_writel(ehci, temp, status_reg);
1074 ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
1075 temp = ehci_readl(ehci, status_reg);
1076 }
1077
Alan Stern625b5c92007-01-16 11:58:47 -05001078 /*
1079 * Even if OWNER is set, there's no harm letting khubd
1080 * see the wPortStatus values (they should all be 0 except
1081 * for PORT_POWER anyway).
1082 */
1083
1084 if (temp & PORT_CONNECT) {
Alan Stern749da5f2010-03-04 17:05:08 -05001085 status |= USB_PORT_STAT_CONNECTION;
Alan Stern625b5c92007-01-16 11:58:47 -05001086 // status may be from integrated TT
Alek Du331ac6b2009-07-13 12:41:20 +08001087 if (ehci->has_hostpc) {
1088 temp1 = ehci_readl(ehci, hostpc_reg);
1089 status |= ehci_port_speed(ehci, temp1);
1090 } else
1091 status |= ehci_port_speed(ehci, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 }
Alan Stern625b5c92007-01-16 11:58:47 -05001093 if (temp & PORT_PE)
Alan Stern749da5f2010-03-04 17:05:08 -05001094 status |= USB_PORT_STAT_ENABLE;
Alan Sterneafe5b92008-10-06 11:25:53 -04001095
1096 /* maybe the port was unsuspended without our knowledge */
1097 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
Alan Stern749da5f2010-03-04 17:05:08 -05001098 status |= USB_PORT_STAT_SUSPEND;
Alan Sterneafe5b92008-10-06 11:25:53 -04001099 } else if (test_bit(wIndex, &ehci->suspended_ports)) {
1100 clear_bit(wIndex, &ehci->suspended_ports);
Alan Sterna448e4d2012-04-03 15:24:30 -04001101 clear_bit(wIndex, &ehci->resuming_ports);
Alan Sterneafe5b92008-10-06 11:25:53 -04001102 ehci->reset_done[wIndex] = 0;
1103 if (temp & PORT_PE)
1104 set_bit(wIndex, &ehci->port_c_suspend);
Alan Sternf292e7f2013-01-25 17:09:49 -05001105 usb_hcd_end_port_resume(&hcd->self, wIndex);
Alan Sterneafe5b92008-10-06 11:25:53 -04001106 }
1107
Alan Stern625b5c92007-01-16 11:58:47 -05001108 if (temp & PORT_OC)
Alan Stern749da5f2010-03-04 17:05:08 -05001109 status |= USB_PORT_STAT_OVERCURRENT;
Alan Stern625b5c92007-01-16 11:58:47 -05001110 if (temp & PORT_RESET)
Alan Stern749da5f2010-03-04 17:05:08 -05001111 status |= USB_PORT_STAT_RESET;
Alan Stern625b5c92007-01-16 11:58:47 -05001112 if (temp & PORT_POWER)
Alan Stern749da5f2010-03-04 17:05:08 -05001113 status |= USB_PORT_STAT_POWER;
Alan Sternd1f114d2008-05-20 16:58:58 -04001114 if (test_bit(wIndex, &ehci->port_c_suspend))
Alan Stern749da5f2010-03-04 17:05:08 -05001115 status |= USB_PORT_STAT_C_SUSPEND << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Oliver Neukumbbcd5ca2013-11-18 13:23:01 +01001117 if (status & ~0xffff) /* only if wPortChange is interesting */
1118 dbg_port(ehci, "GetStatus", wIndex + 1, temp);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001119 put_unaligned_le32(status, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 break;
1121 case SetHubFeature:
1122 switch (wValue) {
1123 case C_HUB_LOCAL_POWER:
1124 case C_HUB_OVER_CURRENT:
1125 /* no hub-wide feature/status flags */
1126 break;
1127 default:
1128 goto error;
1129 }
1130 break;
1131 case SetPortFeature:
David Brownellf0d7f272006-11-16 23:56:15 -08001132 selector = wIndex >> 8;
1133 wIndex &= 0xff;
Jason Wessel8d053c72009-08-20 15:39:54 -05001134 if (unlikely(ehci->debug)) {
1135 /* If the debug port is active any port
1136 * feature requests should get denied */
1137 if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
1138 (readl(&ehci->debug->control) & DBGP_ENABLED)) {
1139 retval = -ENODEV;
1140 goto error_exit;
1141 }
1142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 if (!wIndex || wIndex > ports)
1144 goto error;
1145 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -05001146 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 if (temp & PORT_OWNER)
1148 break;
1149
David Brownell10f65242005-08-31 10:55:38 -07001150 temp &= ~PORT_RWC_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 switch (wValue) {
1152 case USB_PORT_FEAT_SUSPEND:
David Brownellf8aeb3b2006-01-20 13:55:14 -08001153 if (ehci->no_selective_suspend)
1154 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if ((temp & PORT_PE) == 0
1156 || (temp & PORT_RESET) != 0)
1157 goto error;
Alek Dub9df79422010-01-19 16:31:31 +08001158
Alek Du331ac6b2009-07-13 12:41:20 +08001159 /* After above check the port must be connected.
1160 * Set appropriate bit thus could put phy into low power
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +03001161 * mode if we have tdi_phy_lpm feature
Alek Du331ac6b2009-07-13 12:41:20 +08001162 */
Alek Dub9df79422010-01-19 16:31:31 +08001163 temp &= ~PORT_WKCONN_E;
1164 temp |= PORT_WKDISC_E | PORT_WKOC_E;
1165 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
Tuomas Tynkkynen2cdcec42013-08-12 16:06:49 +03001166 if (ehci->has_tdi_phy_lpm) {
Alek Dub9df79422010-01-19 16:31:31 +08001167 spin_unlock_irqrestore(&ehci->lock, flags);
Alek Du331ac6b2009-07-13 12:41:20 +08001168 msleep(5);/* 5ms for HCD enter low pwr mode */
Alek Dub9df79422010-01-19 16:31:31 +08001169 spin_lock_irqsave(&ehci->lock, flags);
Alek Du331ac6b2009-07-13 12:41:20 +08001170 temp1 = ehci_readl(ehci, hostpc_reg);
1171 ehci_writel(ehci, temp1 | HOSTPC_PHCD,
1172 hostpc_reg);
1173 temp1 = ehci_readl(ehci, hostpc_reg);
1174 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
1175 wIndex, (temp1 & HOSTPC_PHCD) ?
1176 "succeeded" : "failed");
1177 }
Alan Sterneafe5b92008-10-06 11:25:53 -04001178 set_bit(wIndex, &ehci->suspended_ports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 break;
1180 case USB_PORT_FEAT_POWER:
1181 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001182 ehci_writel(ehci, temp | PORT_POWER,
Alan Sterne6316562007-01-16 11:58:00 -05001183 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 break;
1185 case USB_PORT_FEAT_RESET:
Alan Stern6753f4c2013-08-01 17:09:28 -04001186 if (temp & (PORT_SUSPEND|PORT_RESUME))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 goto error;
1188 /* line status bits may report this as low speed,
1189 * which can be fine if this root hub has a
1190 * transaction translator built in.
1191 */
1192 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1193 && !ehci_is_TDI(ehci)
1194 && PORT_USB11 (temp)) {
1195 ehci_dbg (ehci,
1196 "port %d low speed --> companion\n",
1197 wIndex + 1);
1198 temp |= PORT_OWNER;
1199 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 temp |= PORT_RESET;
1201 temp &= ~PORT_PE;
1202
1203 /*
1204 * caller must wait, then call GetPortStatus
1205 * usb 2.0 spec says 50 ms resets on root
1206 */
1207 ehci->reset_done [wIndex] = jiffies
1208 + msecs_to_jiffies (50);
1209 }
Alan Sterne6316562007-01-16 11:58:00 -05001210 ehci_writel(ehci, temp, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 break;
David Brownellf0d7f272006-11-16 23:56:15 -08001212
1213 /* For downstream facing ports (these): one hub port is put
1214 * into test mode according to USB2 11.24.2.13, then the hub
1215 * must be reset (which for root hub now means rmmod+modprobe,
1216 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1217 * about the EHCI-specific stuff.
1218 */
1219 case USB_PORT_FEAT_TEST:
Jack Pham726a85c2013-08-13 13:40:13 -07001220#ifdef CONFIG_USB_HCD_TEST_MODE
Manu Gautam9841f372013-08-08 16:49:24 -07001221 if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
1222 spin_unlock_irqrestore(&ehci->lock, flags);
1223 retval = ehset_single_step_set_feature(hcd,
1224 wIndex);
1225 spin_lock_irqsave(&ehci->lock, flags);
1226 break;
Jack Pham726a85c2013-08-13 13:40:13 -07001227 }
1228#endif
1229 if (!selector || selector > 5)
David Brownellf0d7f272006-11-16 23:56:15 -08001230 goto error;
Alan Sternc4f34762012-07-11 11:23:10 -04001231 spin_unlock_irqrestore(&ehci->lock, flags);
David Brownellf0d7f272006-11-16 23:56:15 -08001232 ehci_quiesce(ehci);
Alan Sternc4f34762012-07-11 11:23:10 -04001233 spin_lock_irqsave(&ehci->lock, flags);
Boris Todorov77636c82011-07-11 12:03:33 +03001234
1235 /* Put all enabled ports into suspend */
1236 while (ports--) {
1237 u32 __iomem *sreg =
1238 &ehci->regs->port_status[ports];
1239
1240 temp = ehci_readl(ehci, sreg) & ~PORT_RWC_BITS;
1241 if (temp & PORT_PE)
1242 ehci_writel(ehci, temp | PORT_SUSPEND,
1243 sreg);
1244 }
Alan Sternc4f34762012-07-11 11:23:10 -04001245
1246 spin_unlock_irqrestore(&ehci->lock, flags);
David Brownellf0d7f272006-11-16 23:56:15 -08001247 ehci_halt(ehci);
Alan Sternc4f34762012-07-11 11:23:10 -04001248 spin_lock_irqsave(&ehci->lock, flags);
1249
Boris Todorov77636c82011-07-11 12:03:33 +03001250 temp = ehci_readl(ehci, status_reg);
David Brownellf0d7f272006-11-16 23:56:15 -08001251 temp |= selector << 16;
Alan Sterne6316562007-01-16 11:58:00 -05001252 ehci_writel(ehci, temp, status_reg);
David Brownellf0d7f272006-11-16 23:56:15 -08001253 break;
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 default:
1256 goto error;
1257 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001258 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 break;
1260
1261 default:
1262error:
1263 /* "stall" on error */
1264 retval = -EPIPE;
1265 }
Jason Wessel8d053c72009-08-20 15:39:54 -05001266error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 spin_unlock_irqrestore (&ehci->lock, flags);
1268 return retval;
1269}
Balaji Rao90da0962007-11-22 01:58:14 +05301270
Alan Stern3e023202012-11-01 11:12:58 -04001271static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
Balaji Rao90da0962007-11-22 01:58:14 +05301272{
1273 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1274
1275 if (ehci_is_TDI(ehci))
1276 return;
1277 set_owner(ehci, --portnum, PORT_OWNER);
1278}
1279
Alan Stern3e023202012-11-01 11:12:58 -04001280static int ehci_port_handed_over(struct usb_hcd *hcd, int portnum)
Alan Stern3a311552008-05-20 16:58:29 -04001281{
1282 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1283 u32 __iomem *reg;
1284
1285 if (ehci_is_TDI(ehci))
1286 return 0;
1287 reg = &ehci->regs->port_status[portnum - 1];
1288 return ehci_readl(ehci, reg) & PORT_OWNER;
1289}