blob: 4e7c35f25e16c9a16a3ec87735e1ac8b467aafb0 [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
45/* After a power loss, ports that were owned by the companion must be
46 * reset so that the companion can still own them.
47 */
48static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
49{
50 u32 __iomem *reg;
51 u32 status;
52 int port;
53 __le32 buf;
54 struct usb_hcd *hcd = ehci_to_hcd(ehci);
55
56 if (!ehci->owned_ports)
57 return;
58
59 /* Give the connections some time to appear */
60 msleep(20);
61
62 port = HCS_N_PORTS(ehci->hcs_params);
63 while (port--) {
64 if (test_bit(port, &ehci->owned_ports)) {
65 reg = &ehci->regs->port_status[port];
Alan Stern3c519b82007-05-04 11:55:31 -040066 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Alan Stern383975d2007-05-04 11:52:40 -040067
68 /* Port already owned by companion? */
69 if (status & PORT_OWNER)
70 clear_bit(port, &ehci->owned_ports);
Alan Stern3c519b82007-05-04 11:55:31 -040071 else if (test_bit(port, &ehci->companion_ports))
72 ehci_writel(ehci, status & ~PORT_PE, reg);
Alan Stern383975d2007-05-04 11:52:40 -040073 else
74 ehci_hub_control(hcd, SetPortFeature,
75 USB_PORT_FEAT_RESET, port + 1,
76 NULL, 0);
77 }
78 }
79
80 if (!ehci->owned_ports)
81 return;
82 msleep(90); /* Wait for resets to complete */
83
84 port = HCS_N_PORTS(ehci->hcs_params);
85 while (port--) {
86 if (test_bit(port, &ehci->owned_ports)) {
87 ehci_hub_control(hcd, GetPortStatus,
88 0, port + 1,
89 (char *) &buf, sizeof(buf));
90
91 /* The companion should now own the port,
92 * but if something went wrong the port must not
93 * remain enabled.
94 */
95 reg = &ehci->regs->port_status[port];
96 status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
97 if (status & PORT_OWNER)
98 ehci_writel(ehci, status | PORT_CSC, reg);
99 else {
100 ehci_dbg(ehci, "failed handover port %d: %x\n",
101 port + 1, status);
102 ehci_writel(ehci, status & ~PORT_PE, reg);
103 }
104 }
105 }
106
107 ehci->owned_ports = 0;
108}
109
Matthew Garrett294d95f2011-01-11 12:26:48 -0500110static int ehci_port_change(struct ehci_hcd *ehci)
111{
112 int i = HCS_N_PORTS(ehci->hcs_params);
113
114 /* First check if the controller indicates a change event */
115
116 if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
117 return 1;
118
119 /*
120 * Not all controllers appear to update this while going from D3 to D0,
121 * so check the individual port status registers as well
122 */
123
124 while (i--)
125 if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
126 return 1;
127
128 return 0;
129}
130
Fabio Estevam0b0cd6c2011-04-12 09:31:54 -0300131static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
Alan Stern41472002010-06-25 14:02:14 -0400132 bool suspending, bool do_wakeup)
Alan Stern16032c42010-05-12 18:21:35 -0400133{
134 int port;
135 u32 temp;
Yin Kangkai148fc552011-01-28 12:04:35 +0800136 unsigned long flags;
Alan Stern16032c42010-05-12 18:21:35 -0400137
138 /* If remote wakeup is enabled for the root hub but disabled
139 * for the controller, we must adjust all the port wakeup flags
140 * when the controller is suspended or resumed. In all other
141 * cases they don't need to be changed.
142 */
Alan Stern41472002010-06-25 14:02:14 -0400143 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
Alan Stern16032c42010-05-12 18:21:35 -0400144 return;
145
Yin Kangkai148fc552011-01-28 12:04:35 +0800146 spin_lock_irqsave(&ehci->lock, flags);
147
Alan Stern16032c42010-05-12 18:21:35 -0400148 /* clear phy low-power mode before changing wakeup flags */
149 if (ehci->has_hostpc) {
150 port = HCS_N_PORTS(ehci->hcs_params);
151 while (port--) {
152 u32 __iomem *hostpc_reg;
153
154 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
155 + HOSTPC0 + 4 * port);
156 temp = ehci_readl(ehci, hostpc_reg);
157 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
158 }
Yin Kangkai148fc552011-01-28 12:04:35 +0800159 spin_unlock_irqrestore(&ehci->lock, flags);
Alan Stern16032c42010-05-12 18:21:35 -0400160 msleep(5);
Yin Kangkai148fc552011-01-28 12:04:35 +0800161 spin_lock_irqsave(&ehci->lock, flags);
Alan Stern16032c42010-05-12 18:21:35 -0400162 }
163
164 port = HCS_N_PORTS(ehci->hcs_params);
165 while (port--) {
166 u32 __iomem *reg = &ehci->regs->port_status[port];
167 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
168 u32 t2 = t1 & ~PORT_WAKE_BITS;
169
170 /* If we are suspending the controller, clear the flags.
171 * If we are resuming the controller, set the wakeup flags.
172 */
173 if (!suspending) {
174 if (t1 & PORT_CONNECT)
175 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
176 else
177 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
178 }
179 ehci_vdbg(ehci, "port %d, %08x -> %08x\n",
180 port + 1, t1, t2);
181 ehci_writel(ehci, t2, reg);
182 }
183
184 /* enter phy low-power mode again */
185 if (ehci->has_hostpc) {
186 port = HCS_N_PORTS(ehci->hcs_params);
187 while (port--) {
188 u32 __iomem *hostpc_reg;
189
190 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
191 + HOSTPC0 + 4 * port);
192 temp = ehci_readl(ehci, hostpc_reg);
193 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
194 }
195 }
Alan Sternee0b9be2010-06-25 14:02:24 -0400196
197 /* Does the root hub have a port wakeup pending? */
Matthew Garrett294d95f2011-01-11 12:26:48 -0500198 if (!suspending && ehci_port_change(ehci))
Alan Sternee0b9be2010-06-25 14:02:24 -0400199 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
Yin Kangkai148fc552011-01-28 12:04:35 +0800200
201 spin_unlock_irqrestore(&ehci->lock, flags);
Alan Stern16032c42010-05-12 18:21:35 -0400202}
203
Alan Stern0c0382e2005-10-13 17:08:02 -0400204static int ehci_bus_suspend (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
207 int port;
Alan Stern8c033562006-11-09 14:42:16 -0500208 int mask;
Alan Stern16032c42010-05-12 18:21:35 -0400209 int changed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Alan Stern8c774fe2007-02-01 16:09:59 -0500211 ehci_dbg(ehci, "suspend root hub\n");
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 if (time_before (jiffies, ehci->next_statechange))
214 msleep(5);
Alan Sternf8fa7572008-01-10 16:43:15 -0500215 del_timer_sync(&ehci->watchdog);
216 del_timer_sync(&ehci->iaa_watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 spin_lock_irq (&ehci->lock);
219
Alan Sterncec3a532010-01-08 11:18:20 -0500220 /* Once the controller is stopped, port resumes that are already
221 * in progress won't complete. Hence if remote wakeup is enabled
222 * for the root hub and any ports are in the middle of a resume or
223 * remote wakeup, we must fail the suspend.
224 */
225 if (hcd->self.root_hub->do_remote_wakeup) {
226 port = HCS_N_PORTS(ehci->hcs_params);
227 while (port--) {
228 if (ehci->reset_done[port] != 0) {
229 spin_unlock_irq(&ehci->lock);
230 ehci_dbg(ehci, "suspend failed because "
231 "port %d is resuming\n",
232 port + 1);
233 return -EBUSY;
234 }
235 }
236 }
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /* stop schedules, clean any completed work */
239 if (HC_IS_RUNNING(hcd->state)) {
240 ehci_quiesce (ehci);
241 hcd->state = HC_STATE_QUIESCING;
242 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100243 ehci->command = ehci_readl(ehci, &ehci->regs->command);
David Howells7d12e782006-10-05 14:55:46 +0100244 ehci_work(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Alan Stern8c033562006-11-09 14:42:16 -0500246 /* Unlike other USB host controller types, EHCI doesn't have
247 * any notion of "global" or bus-wide suspend. The driver has
248 * to manually suspend all the active unsuspended ports, and
249 * then manually resume them in the bus_resume() routine.
250 */
251 ehci->bus_suspended = 0;
Alan Stern383975d2007-05-04 11:52:40 -0400252 ehci->owned_ports = 0;
Alan Stern16032c42010-05-12 18:21:35 -0400253 changed = 0;
Alan Sterncec3a532010-01-08 11:18:20 -0500254 port = HCS_N_PORTS(ehci->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 while (port--) {
256 u32 __iomem *reg = &ehci->regs->port_status [port];
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100257 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
Alan Stern16032c42010-05-12 18:21:35 -0400258 u32 t2 = t1 & ~PORT_WAKE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Alan Stern8c033562006-11-09 14:42:16 -0500260 /* keep track of which ports we suspend */
Alan Stern383975d2007-05-04 11:52:40 -0400261 if (t1 & PORT_OWNER)
262 set_bit(port, &ehci->owned_ports);
263 else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
Hemant Kumar38ce5d82012-05-29 13:00:58 -0700264 /*clear RS bit before setting SUSP bit
265 * and wait for HCH to get set*/
266 if (ehci->susp_sof_bug)
267 ehci_halt(ehci);
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 t2 |= PORT_SUSPEND;
Alan Stern8c033562006-11-09 14:42:16 -0500270 set_bit(port, &ehci->bus_suspended);
271 }
272
Alan Stern16032c42010-05-12 18:21:35 -0400273 /* enable remote wakeup on all ports, if told to do so */
Alek Du331ac6b2009-07-13 12:41:20 +0800274 if (hcd->self.root_hub->do_remote_wakeup) {
275 /* only enable appropriate wake bits, otherwise the
276 * hardware can not go phy low power mode. If a race
277 * condition happens here(connection change during bits
278 * set), the port change detection will finally fix it.
279 */
Alan Stern16032c42010-05-12 18:21:35 -0400280 if (t1 & PORT_CONNECT)
Alek Du331ac6b2009-07-13 12:41:20 +0800281 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
Alan Stern16032c42010-05-12 18:21:35 -0400282 else
Alek Du331ac6b2009-07-13 12:41:20 +0800283 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
Alan Stern16032c42010-05-12 18:21:35 -0400284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 if (t1 != t2) {
287 ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
288 port + 1, t1, t2);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100289 ehci_writel(ehci, t2, reg);
Alan Stern16032c42010-05-12 18:21:35 -0400290 changed = 1;
291 }
292 }
Alek Du331ac6b2009-07-13 12:41:20 +0800293
Alan Stern16032c42010-05-12 18:21:35 -0400294 if (changed && ehci->has_hostpc) {
295 spin_unlock_irq(&ehci->lock);
296 msleep(5); /* 5 ms for HCD to enter low-power mode */
297 spin_lock_irq(&ehci->lock);
298
299 port = HCS_N_PORTS(ehci->hcs_params);
300 while (port--) {
301 u32 __iomem *hostpc_reg;
302 u32 t3;
303
304 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
305 + HOSTPC0 + 4 * port);
306 t3 = ehci_readl(ehci, hostpc_reg);
307 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
308 t3 = ehci_readl(ehci, hostpc_reg);
309 ehci_dbg(ehci, "Port %d phy low-power mode %s\n",
Alek Du331ac6b2009-07-13 12:41:20 +0800310 port, (t3 & HOSTPC_PHCD) ?
311 "succeeded" : "failed");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
313 }
314
Alan Sterncd930c92008-01-10 11:14:53 -0500315 /* Apparently some devices need a >= 1-uframe delay here */
316 if (ehci->bus_suspended)
317 udelay(150);
318
Hemant Kumar38ce5d82012-05-29 13:00:58 -0700319 /*if this bit is set, controller is already haled*/
320 if (!ehci->susp_sof_bug)
321 ehci_halt(ehci); /* turn off now-idle HC */
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 hcd->state = HC_STATE_SUSPENDED;
324
David Brownellcdc647a2008-04-02 13:40:20 -0700325 if (ehci->reclaim)
326 end_unlink_async(ehci);
327
Alan Stern8c033562006-11-09 14:42:16 -0500328 /* allow remote wakeup */
329 mask = INTR_MASK;
Alan Stern58a97ff2008-04-14 12:17:10 -0400330 if (!hcd->self.root_hub->do_remote_wakeup)
Alan Stern8c033562006-11-09 14:42:16 -0500331 mask &= ~STS_PCD;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100332 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
333 ehci_readl(ehci, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
336 spin_unlock_irq (&ehci->lock);
Jon Hunter015798b2009-08-12 11:57:59 -0400337
338 /* ehci_work() may have re-enabled the watchdog timer, which we do not
339 * want, and so we must delete any pending watchdog timer events.
340 */
341 del_timer_sync(&ehci->watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return 0;
343}
344
345
346/* caller has locked the root hub, and should reset/reinit on error */
Alan Stern0c0382e2005-10-13 17:08:02 -0400347static int ehci_bus_resume (struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
350 u32 temp;
Alan Stern383975d2007-05-04 11:52:40 -0400351 u32 power_okay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 int i;
Wang Zhicde5eaf2011-08-17 10:39:31 +0800353 unsigned long resume_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 if (time_before (jiffies, ehci->next_statechange))
356 msleep(5);
357 spin_lock_irq (&ehci->lock);
Alan Stern541c7d42010-06-22 16:39:10 -0400358 if (!HCD_HW_ACCESSIBLE(hcd)) {
Alan Sterncfa59da2007-06-21 16:25:35 -0400359 spin_unlock_irq(&ehci->lock);
360 return -ESHUTDOWN;
361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Jason Wesselad45f1d2009-08-20 15:39:58 -0500363 if (unlikely(ehci->debug)) {
Jason Wessel872d3592009-09-23 18:32:44 -0500364 if (!dbgp_reset_prep())
Jason Wesselad45f1d2009-08-20 15:39:58 -0500365 ehci->debug = NULL;
366 else
367 dbgp_external_startup();
368 }
369
David Brownellf03c17f2005-11-23 15:45:28 -0800370 /* Ideally and we've got a real resume here, and no port's power
371 * was lost. (For PCI, that means Vaux was maintained.) But we
372 * could instead be restoring a swsusp snapshot -- so that BIOS was
373 * the last user of the controller, not reset/pm hardware keeping
374 * state we gave to it.
375 */
Alan Stern383975d2007-05-04 11:52:40 -0400376 power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
377 ehci_dbg(ehci, "resume root hub%s\n",
378 power_okay ? "" : " after power loss");
David Brownellf03c17f2005-11-23 15:45:28 -0800379
Alan Stern8c033562006-11-09 14:42:16 -0500380 /* at least some APM implementations will try to deliver
381 * IRQs right away, so delay them until we're ready.
382 */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100383 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
Alan Stern8c033562006-11-09 14:42:16 -0500384
385 /* re-init operational registers */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100386 ehci_writel(ehci, 0, &ehci->regs->segment);
387 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
388 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 /* restore CMD_RUN, framelist size, and irq threshold */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100391 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Alan Sterne198a312007-03-15 15:54:30 -0400393 /* Some controller/firmware combinations need a delay during which
394 * they set up the port statuses. See Bugzilla #8190. */
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530395 spin_unlock_irq(&ehci->lock);
396 msleep(8);
397 spin_lock_irq(&ehci->lock);
Alan Sterne198a312007-03-15 15:54:30 -0400398
Alan Stern16032c42010-05-12 18:21:35 -0400399 /* clear phy low-power mode before resume */
400 if (ehci->bus_suspended && ehci->has_hostpc) {
401 i = HCS_N_PORTS(ehci->hcs_params);
402 while (i--) {
403 if (test_bit(i, &ehci->bus_suspended)) {
404 u32 __iomem *hostpc_reg;
405
406 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
407 + HOSTPC0 + 4 * i);
408 temp = ehci_readl(ehci, hostpc_reg);
409 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
410 hostpc_reg);
411 }
412 }
413 spin_unlock_irq(&ehci->lock);
414 msleep(5);
415 spin_lock_irq(&ehci->lock);
416 }
417
Alan Stern8c033562006-11-09 14:42:16 -0500418 /* manually resume the ports we suspended during bus_suspend() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 i = HCS_N_PORTS (ehci->hcs_params);
420 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100421 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern58a97ff2008-04-14 12:17:10 -0400422 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
Alan Stern8c033562006-11-09 14:42:16 -0500423 if (test_bit(i, &ehci->bus_suspended) &&
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530424 (temp & PORT_SUSPEND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 temp |= PORT_RESUME;
Wang Zhicde5eaf2011-08-17 10:39:31 +0800426 set_bit(i, &resume_needed);
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530427 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100428 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
Vikram Pandita3a4e72c2008-10-24 23:41:30 +0530430
431 /* msleep for 20ms only if code is trying to resume port */
432 if (resume_needed) {
433 spin_unlock_irq(&ehci->lock);
434 msleep(20);
435 spin_lock_irq(&ehci->lock);
436 }
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 i = HCS_N_PORTS (ehci->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 while (i--) {
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100440 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Wang Zhicde5eaf2011-08-17 10:39:31 +0800441 if (test_bit(i, &resume_needed)) {
Alan Stern8c033562006-11-09 14:42:16 -0500442 temp &= ~(PORT_RWC_BITS | PORT_RESUME);
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100443 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
Alan Stern8c033562006-11-09 14:42:16 -0500444 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100447 (void) ehci_readl(ehci, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 /* maybe re-activate the schedule(s) */
450 temp = 0;
451 if (ehci->async->qh_next.qh)
452 temp |= CMD_ASE;
453 if (ehci->periodic_sched)
454 temp |= CMD_PSE;
455 if (temp) {
456 ehci->command |= temp;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100457 ehci_writel(ehci, ehci->command, &ehci->regs->command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459
460 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
461 hcd->state = HC_STATE_RUNNING;
462
463 /* Now we can safely re-enable irqs */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100464 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 spin_unlock_irq (&ehci->lock);
Alan Stern3bb1af52008-03-03 15:15:36 -0500467 ehci_handover_companion_ports(ehci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 return 0;
469}
470
471#else
472
Alan Stern0c0382e2005-10-13 17:08:02 -0400473#define ehci_bus_suspend NULL
474#define ehci_bus_resume NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476#endif /* CONFIG_PM */
477
478/*-------------------------------------------------------------------------*/
479
Alan Stern57e06c12007-01-16 11:59:45 -0500480/* Display the ports dedicated to the companion controller */
Tony Jones5a3201b2007-09-11 14:07:31 -0700481static ssize_t show_companion(struct device *dev,
482 struct device_attribute *attr,
483 char *buf)
Alan Stern57e06c12007-01-16 11:59:45 -0500484{
485 struct ehci_hcd *ehci;
486 int nports, index, n;
487 int count = PAGE_SIZE;
488 char *ptr = buf;
489
Tony Jones5a3201b2007-09-11 14:07:31 -0700490 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
Alan Stern57e06c12007-01-16 11:59:45 -0500491 nports = HCS_N_PORTS(ehci->hcs_params);
492
493 for (index = 0; index < nports; ++index) {
494 if (test_bit(index, &ehci->companion_ports)) {
495 n = scnprintf(ptr, count, "%d\n", index + 1);
496 ptr += n;
497 count -= n;
498 }
499 }
500 return ptr - buf;
501}
502
503/*
Balaji Rao90da0962007-11-22 01:58:14 +0530504 * Sets the owner of a port
Alan Stern57e06c12007-01-16 11:59:45 -0500505 */
Balaji Rao90da0962007-11-22 01:58:14 +0530506static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
Alan Stern57e06c12007-01-16 11:59:45 -0500507{
Alan Stern57e06c12007-01-16 11:59:45 -0500508 u32 __iomem *status_reg;
509 u32 port_status;
Balaji Rao90da0962007-11-22 01:58:14 +0530510 int try;
Alan Stern57e06c12007-01-16 11:59:45 -0500511
Balaji Rao90da0962007-11-22 01:58:14 +0530512 status_reg = &ehci->regs->port_status[portnum];
Alan Stern57e06c12007-01-16 11:59:45 -0500513
514 /*
515 * The controller won't set the OWNER bit if the port is
516 * enabled, so this loop will sometimes require at least two
517 * iterations: one to disable the port and one to set OWNER.
518 */
Alan Stern57e06c12007-01-16 11:59:45 -0500519 for (try = 4; try > 0; --try) {
520 spin_lock_irq(&ehci->lock);
521 port_status = ehci_readl(ehci, status_reg);
522 if ((port_status & PORT_OWNER) == new_owner
523 || (port_status & (PORT_OWNER | PORT_CONNECT))
524 == 0)
525 try = 0;
526 else {
527 port_status ^= PORT_OWNER;
528 port_status &= ~(PORT_PE | PORT_RWC_BITS);
529 ehci_writel(ehci, port_status, status_reg);
530 }
531 spin_unlock_irq(&ehci->lock);
532 if (try > 1)
533 msleep(5);
534 }
Balaji Rao90da0962007-11-22 01:58:14 +0530535}
536
537/*
538 * Dedicate or undedicate a port to the companion controller.
539 * Syntax is "[-]portnum", where a leading '-' sign means
540 * return control of the port to the EHCI controller.
541 */
542static ssize_t store_companion(struct device *dev,
543 struct device_attribute *attr,
544 const char *buf, size_t count)
545{
546 struct ehci_hcd *ehci;
547 int portnum, new_owner;
548
549 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
550 new_owner = PORT_OWNER; /* Owned by companion */
551 if (sscanf(buf, "%d", &portnum) != 1)
552 return -EINVAL;
553 if (portnum < 0) {
554 portnum = - portnum;
555 new_owner = 0; /* Owned by EHCI */
556 }
557 if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
558 return -ENOENT;
559 portnum--;
560 if (new_owner)
561 set_bit(portnum, &ehci->companion_ports);
562 else
563 clear_bit(portnum, &ehci->companion_ports);
564 set_owner(ehci, portnum, new_owner);
Alan Stern57e06c12007-01-16 11:59:45 -0500565 return count;
566}
Tony Jones5a3201b2007-09-11 14:07:31 -0700567static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
Alan Stern57e06c12007-01-16 11:59:45 -0500568
David Daneyac8d6742011-01-25 09:59:37 -0800569static inline int create_companion_file(struct ehci_hcd *ehci)
Alan Stern57e06c12007-01-16 11:59:45 -0500570{
David Daneyac8d6742011-01-25 09:59:37 -0800571 int i = 0;
Alan Stern57e06c12007-01-16 11:59:45 -0500572
573 /* with integrated TT there is no companion! */
574 if (!ehci_is_TDI(ehci))
Greg Kroah-Hartmaned14f032009-04-27 13:15:38 -0700575 i = device_create_file(ehci_to_hcd(ehci)->self.controller,
Tony Jones5a3201b2007-09-11 14:07:31 -0700576 &dev_attr_companion);
David Daneyac8d6742011-01-25 09:59:37 -0800577 return i;
Alan Stern57e06c12007-01-16 11:59:45 -0500578}
579
580static inline void remove_companion_file(struct ehci_hcd *ehci)
581{
582 /* with integrated TT there is no companion! */
583 if (!ehci_is_TDI(ehci))
Greg Kroah-Hartmaned14f032009-04-27 13:15:38 -0700584 device_remove_file(ehci_to_hcd(ehci)->self.controller,
Tony Jones5a3201b2007-09-11 14:07:31 -0700585 &dev_attr_companion);
Alan Stern57e06c12007-01-16 11:59:45 -0500586}
587
588
589/*-------------------------------------------------------------------------*/
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591static int check_reset_complete (
592 struct ehci_hcd *ehci,
593 int index,
Alan Sterne6316562007-01-16 11:58:00 -0500594 u32 __iomem *status_reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 int port_status
596) {
David Brownellcd4cdc92008-01-24 12:39:43 -0800597 if (!(port_status & PORT_CONNECT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return port_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 /* if reset finished and it's still not enabled -- handoff */
601 if (!(port_status & PORT_PE)) {
602
603 /* with integrated TT, there's nobody to hand it to! */
604 if (ehci_is_TDI(ehci)) {
605 ehci_dbg (ehci,
606 "Failed to enable port %d on root hub TT\n",
607 index+1);
608 return port_status;
609 }
610
611 ehci_dbg (ehci, "port %d full speed --> companion\n",
612 index + 1);
613
614 // what happens if HCS_N_CC(params) == 0 ?
615 port_status |= PORT_OWNER;
David Brownell10f65242005-08-31 10:55:38 -0700616 port_status &= ~PORT_RWC_BITS;
Alan Sterne6316562007-01-16 11:58:00 -0500617 ehci_writel(ehci, port_status, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Vitaly Bordug796bcae2008-11-09 19:43:30 +0100619 /* ensure 440EPX ohci controller state is operational */
620 if (ehci->has_amcc_usb23)
621 set_ohci_hcfs(ehci, 1);
622 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 ehci_dbg (ehci, "port %d high speed\n", index + 1);
Vitaly Bordug796bcae2008-11-09 19:43:30 +0100624 /* ensure 440EPx ohci controller state is suspended */
625 if (ehci->has_amcc_usb23)
626 set_ohci_hcfs(ehci, 0);
627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 return port_status;
630}
631
632/*-------------------------------------------------------------------------*/
633
634
635/* build "status change" packet (one or two bytes) from HC registers */
636
637static int
638ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
639{
640 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
641 u32 temp, status = 0;
David Brownell93f1a472006-11-16 23:34:58 -0800642 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 int ports, i, retval = 1;
644 unsigned long flags;
Alek Du5a9cdf32010-06-04 15:47:56 +0800645 u32 ppcd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
648 if (!HC_IS_RUNNING(hcd->state))
649 return 0;
650
651 /* init status to no-changes */
652 buf [0] = 0;
653 ports = HCS_N_PORTS (ehci->hcs_params);
654 if (ports > 7) {
655 buf [1] = 0;
656 retval++;
657 }
David Brownell53bd6a62006-08-30 14:50:06 -0700658
David Brownell93f1a472006-11-16 23:34:58 -0800659 /* Some boards (mostly VIA?) report bogus overcurrent indications,
660 * causing massive log spam unless we completely ignore them. It
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200661 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
David Brownell93f1a472006-11-16 23:34:58 -0800662 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
663 * PORT_POWER; that's surprising, but maybe within-spec.
664 */
665 if (!ignore_oc)
666 mask = PORT_CSC | PORT_PEC | PORT_OCC;
667 else
668 mask = PORT_CSC | PORT_PEC;
669 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /* no hub change reports (bit 0) for now (power, ...) */
672
673 /* port N changes (bit N)? */
674 spin_lock_irqsave (&ehci->lock, flags);
Alek Du5a9cdf32010-06-04 15:47:56 +0800675
676 /* get per-port change detect bits */
677 if (ehci->has_ppcd)
678 ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 for (i = 0; i < ports; i++) {
Alek Du5a9cdf32010-06-04 15:47:56 +0800681 /* leverage per-port change bits feature */
682 if (ehci->has_ppcd && !(ppcd & (1 << i)))
683 continue;
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100684 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
Alan Stern625b5c92007-01-16 11:58:47 -0500685
686 /*
687 * Return status information even for ports with OWNER set.
688 * Otherwise khubd wouldn't see the disconnect event when a
689 * high-speed device is switched over to the companion
690 * controller by the user.
691 */
692
Alan Sterneafe5b92008-10-06 11:25:53 -0400693 if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend)
694 || (ehci->reset_done[i] && time_after_eq(
695 jiffies, ehci->reset_done[i]))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (i < 7)
697 buf [0] |= 1 << (i + 1);
698 else
699 buf [1] |= 1 << (i - 7);
700 status = STS_PCD;
701 }
702 }
703 /* FIXME autosuspend idle root hubs */
704 spin_unlock_irqrestore (&ehci->lock, flags);
705 return status ? retval : 0;
706}
707
708/*-------------------------------------------------------------------------*/
709
710static void
711ehci_hub_descriptor (
712 struct ehci_hcd *ehci,
713 struct usb_hub_descriptor *desc
714) {
715 int ports = HCS_N_PORTS (ehci->hcs_params);
716 u16 temp;
717
718 desc->bDescriptorType = 0x29;
719 desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */
720 desc->bHubContrCurrent = 0;
721
722 desc->bNbrPorts = ports;
723 temp = 1 + (ports / 8);
724 desc->bDescLength = 7 + 2 * temp;
725
726 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
John Youndbe79bb2001-09-17 00:00:00 -0700727 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
728 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 temp = 0x0008; /* per-port overcurrent reporting */
731 if (HCS_PPC (ehci->hcs_params))
732 temp |= 0x0001; /* per-port power control */
David Brownell56c1e262005-04-09 09:00:29 -0700733 else
734 temp |= 0x0002; /* no power switching */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#if 0
736// re-enable when we support USB_PORT_FEAT_INDICATOR below.
737 if (HCS_INDICATOR (ehci->hcs_params))
738 temp |= 0x0080; /* per-port indicators (LEDs) */
739#endif
Al Virofd05e722008-04-28 07:00:16 +0100740 desc->wHubCharacteristics = cpu_to_le16(temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741}
742
743/*-------------------------------------------------------------------------*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744#ifdef CONFIG_USB_EHCI_EHSET
745
746#define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06
747
748static void usb_ehset_completion(struct urb *urb)
749{
750 struct completion *done = urb->context;
751
752 complete(done);
753}
754static int submit_single_step_set_feature(
755 struct usb_hcd *hcd,
756 struct urb *urb,
757 int is_setup
758);
759
760/* Allocate a URB and initialize the various fields of it.
761 * This API is used by the single_step_set_feature test of
762 * EHSET where IN packet of the GetDescriptor request is
763 * sent after 15secs of the SETUP packet.
764 * Return NULL if failed.
765 */
766static struct urb *
767request_single_step_set_feature_urb(
768 struct usb_device *udev,
769 void *dr,
770 void *buf,
771 struct completion *done
772) {
773 struct urb *urb;
774 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
775 struct usb_host_endpoint *ep;
776
777 urb = usb_alloc_urb(0, GFP_KERNEL);
778 if (!urb)
779 return NULL;
780
781 urb->pipe = usb_rcvctrlpipe(udev, 0);
782 ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out)
783 [usb_pipeendpoint(urb->pipe)];
784 if (!ep) {
785 usb_free_urb(urb);
786 return NULL;
787 }
788
789 /* Initialize the various URB fields as these are used
790 * by the HCD driver to queue it and as well as
791 * when completion happens.
792 */
793 urb->ep = ep;
794 urb->dev = udev;
795 urb->setup_packet = (void *)dr;
796 urb->transfer_buffer = buf;
797 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE;
798 urb->complete = usb_ehset_completion;
799 urb->status = -EINPROGRESS;
800 urb->actual_length = 0;
801 urb->transfer_flags = (urb->transfer_flags & ~URB_DIR_MASK)
802 | URB_DIR_IN ;
803 usb_get_urb(urb);
804 atomic_inc(&urb->use_count);
805 atomic_inc(&urb->dev->urbnum);
806 urb->setup_dma = dma_map_single(
807 hcd->self.controller,
808 urb->setup_packet,
809 sizeof(struct usb_ctrlrequest),
810 DMA_TO_DEVICE);
811 urb->transfer_dma = dma_map_single(
812 hcd->self.controller,
813 urb->transfer_buffer,
814 urb->transfer_buffer_length,
815 DMA_FROM_DEVICE);
816 urb->context = done;
817 return urb;
818}
819
820static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
821{
822 int retval = -ENOMEM;
823 struct usb_ctrlrequest *dr;
824 struct urb *urb;
825 struct usb_device *udev ;
826 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
827 struct usb_device_descriptor *buf;
828 DECLARE_COMPLETION_ONSTACK(done);
829
830 /*Obtain udev of the rhub's child port */
831 udev = hcd->self.root_hub->children[port];
832 if (!udev) {
833 ehci_err(ehci, "No device attached to the RootHub\n");
834 return -ENODEV;
835 }
836 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
837 if (!buf)
838 return -ENOMEM;
839
840 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
841 if (!dr) {
842 kfree(buf);
843 return -ENOMEM;
844 }
845
846 /* Fill Setup packet for GetDescriptor */
847 dr->bRequestType = USB_DIR_IN;
848 dr->bRequest = USB_REQ_GET_DESCRIPTOR;
849 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8);
850 dr->wIndex = 0;
851 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE);
852 urb = request_single_step_set_feature_urb(udev, dr, buf, &done);
853 if (!urb)
854 goto cleanup;
855
856 /* Now complete just the SETUP stage */
857 retval = submit_single_step_set_feature(hcd, urb, 1);
858 if (retval)
859 goto out1;
860 if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) {
861 usb_kill_urb(urb);
862 retval = -ETIMEDOUT;
863 ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__);
864 goto out1;
865 }
866 msleep(15 * 1000);
867 /* Complete remaining DATA and status stages */
868 /* No need to free the URB, we can reuse the same */
869 urb->status = -EINPROGRESS;
870 usb_get_urb(urb);
871 atomic_inc(&urb->use_count);
872 atomic_inc(&urb->dev->urbnum);
873 retval = submit_single_step_set_feature(hcd, urb, 0);
874 if (!retval && !wait_for_completion_timeout(&done,
875 msecs_to_jiffies(2000))) {
876 usb_kill_urb(urb);
877 retval = -ETIMEDOUT;
878 ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__);
879 }
880out1:
881 usb_free_urb(urb);
882cleanup:
883 kfree(dr);
884 kfree(buf);
885 return retval;
886}
887#endif
888/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890static int ehci_hub_control (
891 struct usb_hcd *hcd,
892 u16 typeReq,
893 u16 wValue,
894 u16 wIndex,
895 char *buf,
896 u16 wLength
897) {
898 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
899 int ports = HCS_N_PORTS (ehci->hcs_params);
Alan Stern383975d2007-05-04 11:52:40 -0400900 u32 __iomem *status_reg = &ehci->regs->port_status[
901 (wIndex & 0xff) - 1];
Alek Du331ac6b2009-07-13 12:41:20 +0800902 u32 __iomem *hostpc_reg = NULL;
903 u32 temp, temp1, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 unsigned long flags;
905 int retval = 0;
David Brownellf0d7f272006-11-16 23:56:15 -0800906 unsigned selector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 /*
909 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
910 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
911 * (track current state ourselves) ... blink for diagnostics,
912 * power, "this is the one", etc. EHCI spec supports this.
913 */
914
Alek Du331ac6b2009-07-13 12:41:20 +0800915 if (ehci->has_hostpc)
916 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
917 + HOSTPC0 + 4 * ((wIndex & 0xff) - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 spin_lock_irqsave (&ehci->lock, flags);
919 switch (typeReq) {
920 case ClearHubFeature:
921 switch (wValue) {
922 case C_HUB_LOCAL_POWER:
923 case C_HUB_OVER_CURRENT:
924 /* no hub-wide feature/status flags */
925 break;
926 default:
927 goto error;
928 }
929 break;
930 case ClearPortFeature:
931 if (!wIndex || wIndex > ports)
932 goto error;
933 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -0500934 temp = ehci_readl(ehci, status_reg);
Alan Stern625b5c92007-01-16 11:58:47 -0500935
936 /*
937 * Even if OWNER is set, so the port is owned by the
938 * companion controller, khubd needs to be able to clear
939 * the port-change status bits (especially
Alan Stern749da5f2010-03-04 17:05:08 -0500940 * USB_PORT_STAT_C_CONNECTION).
Alan Stern625b5c92007-01-16 11:58:47 -0500941 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 switch (wValue) {
944 case USB_PORT_FEAT_ENABLE:
Alan Sterne6316562007-01-16 11:58:00 -0500945 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 break;
947 case USB_PORT_FEAT_C_ENABLE:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100948 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC,
Alan Sterne6316562007-01-16 11:58:00 -0500949 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 break;
951 case USB_PORT_FEAT_SUSPEND:
952 if (temp & PORT_RESET)
953 goto error;
David Brownellf8aeb3b2006-01-20 13:55:14 -0800954 if (ehci->no_selective_suspend)
955 break;
Anatolij Gustschin83722bc2011-04-18 22:02:00 +0200956#ifdef CONFIG_USB_OTG
957 if ((hcd->self.otg_port == (wIndex + 1))
958 && hcd->self.b_hnp_enable) {
959 otg_start_hnp(ehci->transceiver);
960 break;
961 }
962#endif
Alan Stern16032c42010-05-12 18:21:35 -0400963 if (!(temp & PORT_SUSPEND))
964 break;
965 if ((temp & PORT_PE) == 0)
966 goto error;
967
968 /* clear phy low-power mode before resume */
969 if (hostpc_reg) {
970 temp1 = ehci_readl(ehci, hostpc_reg);
971 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
Alek Dueab80de2010-05-10 11:17:49 +0800972 hostpc_reg);
Alan Stern16032c42010-05-12 18:21:35 -0400973 spin_unlock_irqrestore(&ehci->lock, flags);
974 msleep(5);/* wait to leave low-power mode */
975 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
Alan Stern16032c42010-05-12 18:21:35 -0400977 /* resume signaling for 20 msec */
978 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
979 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
980 ehci->reset_done[wIndex] = jiffies
981 + msecs_to_jiffies(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 break;
983 case USB_PORT_FEAT_C_SUSPEND:
Alan Sternd1f114d2008-05-20 16:58:58 -0400984 clear_bit(wIndex, &ehci->port_c_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 break;
986 case USB_PORT_FEAT_POWER:
987 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100988 ehci_writel(ehci,
989 temp & ~(PORT_RWC_BITS | PORT_POWER),
Alan Sterne6316562007-01-16 11:58:00 -0500990 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 break;
992 case USB_PORT_FEAT_C_CONNECTION:
Alek Du48f24972010-06-04 15:47:55 +0800993 if (ehci->has_lpm) {
994 /* clear PORTSC bits on disconnect */
995 temp &= ~PORT_LPM;
996 temp &= ~PORT_DEV_ADDR;
997 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100998 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
Alan Sterne6316562007-01-16 11:58:00 -0500999 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 break;
1001 case USB_PORT_FEAT_C_OVER_CURRENT:
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001002 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC,
Alan Sterne6316562007-01-16 11:58:00 -05001003 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 break;
1005 case USB_PORT_FEAT_C_RESET:
1006 /* GetPortStatus clears reset */
1007 break;
1008 default:
1009 goto error;
1010 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001011 ehci_readl(ehci, &ehci->regs->command); /* unblock posted write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 break;
1013 case GetHubDescriptor:
1014 ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
1015 buf);
1016 break;
1017 case GetHubStatus:
1018 /* no hub-wide feature/status flags */
1019 memset (buf, 0, 4);
1020 //cpu_to_le32s ((u32 *) buf);
1021 break;
1022 case GetPortStatus:
1023 if (!wIndex || wIndex > ports)
1024 goto error;
1025 wIndex--;
1026 status = 0;
Alan Sterne6316562007-01-16 11:58:00 -05001027 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 // wPortChange bits
1030 if (temp & PORT_CSC)
Alan Stern749da5f2010-03-04 17:05:08 -05001031 status |= USB_PORT_STAT_C_CONNECTION << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (temp & PORT_PEC)
Alan Stern749da5f2010-03-04 17:05:08 -05001033 status |= USB_PORT_STAT_C_ENABLE << 16;
Christian Engelmayer756aa6b2007-05-30 11:04:48 -07001034
1035 if ((temp & PORT_OCC) && !ignore_oc){
Alan Stern749da5f2010-03-04 17:05:08 -05001036 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Christian Engelmayer756aa6b2007-05-30 11:04:48 -07001038 /*
1039 * Hubs should disable port power on over-current.
1040 * However, not all EHCI implementations do this
1041 * automatically, even if they _do_ support per-port
1042 * power switching; they're allowed to just limit the
1043 * current. khubd will turn the power back on.
1044 */
Sergei Shtylyove151a2a2011-07-06 23:19:38 +04001045 if ((temp & PORT_OC) && HCS_PPC(ehci->hcs_params)) {
Christian Engelmayer756aa6b2007-05-30 11:04:48 -07001046 ehci_writel(ehci,
1047 temp & ~(PORT_RWC_BITS | PORT_POWER),
1048 status_reg);
Sergei Shtylyove151a2a2011-07-06 23:19:38 +04001049 temp = ehci_readl(ehci, status_reg);
Christian Engelmayer756aa6b2007-05-30 11:04:48 -07001050 }
1051 }
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 /* whoever resumes must GetPortStatus to complete it!! */
Alan Stern629e4422007-01-22 16:08:53 -05001054 if (temp & PORT_RESUME) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Alan Stern629e4422007-01-22 16:08:53 -05001056 /* Remote Wakeup received? */
1057 if (!ehci->reset_done[wIndex]) {
1058 /* resume signaling for 20 msec */
1059 ehci->reset_done[wIndex] = jiffies
1060 + msecs_to_jiffies(20);
1061 /* check the port again */
1062 mod_timer(&ehci_to_hcd(ehci)->rh_timer,
1063 ehci->reset_done[wIndex]);
1064 }
1065
1066 /* resume completed? */
1067 else if (time_after_eq(jiffies,
1068 ehci->reset_done[wIndex])) {
Alan Sterneafe5b92008-10-06 11:25:53 -04001069 clear_bit(wIndex, &ehci->suspended_ports);
Alan Sternd1f114d2008-05-20 16:58:58 -04001070 set_bit(wIndex, &ehci->port_c_suspend);
Alan Stern629e4422007-01-22 16:08:53 -05001071 ehci->reset_done[wIndex] = 0;
1072
1073 /* stop resume signaling */
1074 temp = ehci_readl(ehci, status_reg);
1075 ehci_writel(ehci,
Alan Sterne6316562007-01-16 11:58:00 -05001076 temp & ~(PORT_RWC_BITS | PORT_RESUME),
1077 status_reg);
Alan Stern629e4422007-01-22 16:08:53 -05001078 retval = handshake(ehci, status_reg,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001079 PORT_RESUME, 0, 2000 /* 2msec */);
Alan Stern629e4422007-01-22 16:08:53 -05001080 if (retval != 0) {
1081 ehci_err(ehci,
1082 "port %d resume error %d\n",
1083 wIndex + 1, retval);
1084 goto error;
1085 }
1086 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089
1090 /* whoever resets must GetPortStatus to complete it!! */
1091 if ((temp & PORT_RESET)
Alan Stern629e4422007-01-22 16:08:53 -05001092 && time_after_eq(jiffies,
1093 ehci->reset_done[wIndex])) {
Alan Stern749da5f2010-03-04 17:05:08 -05001094 status |= USB_PORT_STAT_C_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 ehci->reset_done [wIndex] = 0;
1096
1097 /* force reset to complete */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001098 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
Alan Sterne6316562007-01-16 11:58:00 -05001099 status_reg);
David Brownellc22fa3a2005-06-13 07:15:28 -07001100 /* REVISIT: some hardware needs 550+ usec to clear
1101 * this bit; seems too long to spin routinely...
1102 */
Alan Sterne6316562007-01-16 11:58:00 -05001103 retval = handshake(ehci, status_reg,
Dinh Nguyen6307e092010-04-13 11:13:15 -05001104 PORT_RESET, 0, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (retval != 0) {
1106 ehci_err (ehci, "port %d reset error %d\n",
1107 wIndex + 1, retval);
1108 goto error;
1109 }
1110
1111 /* see what we found out */
Alan Sterne6316562007-01-16 11:58:00 -05001112 temp = check_reset_complete (ehci, wIndex, status_reg,
1113 ehci_readl(ehci, status_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
1115
Alan Sterneafe5b92008-10-06 11:25:53 -04001116 if (!(temp & (PORT_RESUME|PORT_RESET)))
1117 ehci->reset_done[wIndex] = 0;
1118
Alan Stern57e06c12007-01-16 11:59:45 -05001119 /* transfer dedicated ports to the companion hc */
1120 if ((temp & PORT_CONNECT) &&
1121 test_bit(wIndex, &ehci->companion_ports)) {
1122 temp &= ~PORT_RWC_BITS;
1123 temp |= PORT_OWNER;
1124 ehci_writel(ehci, temp, status_reg);
1125 ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
1126 temp = ehci_readl(ehci, status_reg);
1127 }
1128
Alan Stern625b5c92007-01-16 11:58:47 -05001129 /*
1130 * Even if OWNER is set, there's no harm letting khubd
1131 * see the wPortStatus values (they should all be 0 except
1132 * for PORT_POWER anyway).
1133 */
1134
1135 if (temp & PORT_CONNECT) {
Alan Stern749da5f2010-03-04 17:05:08 -05001136 status |= USB_PORT_STAT_CONNECTION;
Alan Stern625b5c92007-01-16 11:58:47 -05001137 // status may be from integrated TT
Alek Du331ac6b2009-07-13 12:41:20 +08001138 if (ehci->has_hostpc) {
1139 temp1 = ehci_readl(ehci, hostpc_reg);
1140 status |= ehci_port_speed(ehci, temp1);
1141 } else
1142 status |= ehci_port_speed(ehci, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
Alan Stern625b5c92007-01-16 11:58:47 -05001144 if (temp & PORT_PE)
Alan Stern749da5f2010-03-04 17:05:08 -05001145 status |= USB_PORT_STAT_ENABLE;
Alan Sterneafe5b92008-10-06 11:25:53 -04001146
1147 /* maybe the port was unsuspended without our knowledge */
1148 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
Alan Stern749da5f2010-03-04 17:05:08 -05001149 status |= USB_PORT_STAT_SUSPEND;
Alan Sterneafe5b92008-10-06 11:25:53 -04001150 } else if (test_bit(wIndex, &ehci->suspended_ports)) {
1151 clear_bit(wIndex, &ehci->suspended_ports);
1152 ehci->reset_done[wIndex] = 0;
1153 if (temp & PORT_PE)
1154 set_bit(wIndex, &ehci->port_c_suspend);
1155 }
1156
Alan Stern625b5c92007-01-16 11:58:47 -05001157 if (temp & PORT_OC)
Alan Stern749da5f2010-03-04 17:05:08 -05001158 status |= USB_PORT_STAT_OVERCURRENT;
Alan Stern625b5c92007-01-16 11:58:47 -05001159 if (temp & PORT_RESET)
Alan Stern749da5f2010-03-04 17:05:08 -05001160 status |= USB_PORT_STAT_RESET;
Alan Stern625b5c92007-01-16 11:58:47 -05001161 if (temp & PORT_POWER)
Alan Stern749da5f2010-03-04 17:05:08 -05001162 status |= USB_PORT_STAT_POWER;
Alan Sternd1f114d2008-05-20 16:58:58 -04001163 if (test_bit(wIndex, &ehci->port_c_suspend))
Alan Stern749da5f2010-03-04 17:05:08 -05001164 status |= USB_PORT_STAT_C_SUSPEND << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
David Brownell9776afc2008-02-01 11:42:05 -08001166#ifndef VERBOSE_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 if (status & ~0xffff) /* only if wPortChange is interesting */
1168#endif
1169 dbg_port (ehci, "GetStatus", wIndex + 1, temp);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001170 put_unaligned_le32(status, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 break;
1172 case SetHubFeature:
1173 switch (wValue) {
1174 case C_HUB_LOCAL_POWER:
1175 case C_HUB_OVER_CURRENT:
1176 /* no hub-wide feature/status flags */
1177 break;
1178 default:
1179 goto error;
1180 }
1181 break;
1182 case SetPortFeature:
David Brownellf0d7f272006-11-16 23:56:15 -08001183 selector = wIndex >> 8;
1184 wIndex &= 0xff;
Jason Wessel8d053c72009-08-20 15:39:54 -05001185 if (unlikely(ehci->debug)) {
1186 /* If the debug port is active any port
1187 * feature requests should get denied */
1188 if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
1189 (readl(&ehci->debug->control) & DBGP_ENABLED)) {
1190 retval = -ENODEV;
1191 goto error_exit;
1192 }
1193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 if (!wIndex || wIndex > ports)
1195 goto error;
1196 wIndex--;
Alan Sterne6316562007-01-16 11:58:00 -05001197 temp = ehci_readl(ehci, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (temp & PORT_OWNER)
1199 break;
1200
David Brownell10f65242005-08-31 10:55:38 -07001201 temp &= ~PORT_RWC_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 switch (wValue) {
1203 case USB_PORT_FEAT_SUSPEND:
David Brownellf8aeb3b2006-01-20 13:55:14 -08001204 if (ehci->no_selective_suspend)
1205 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 if ((temp & PORT_PE) == 0
1207 || (temp & PORT_RESET) != 0)
1208 goto error;
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001209 /*port gets suspended as part of bus suspend routine*/
1210 if (!ehci->susp_sof_bug)
1211 ehci_writel(ehci, temp | PORT_SUSPEND,
1212 status_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213#ifdef CONFIG_USB_OTG
1214 if (hcd->self.otg_port == (wIndex + 1) &&
Vijayavardhan Vennapusaa36dc2c2012-03-05 16:09:40 +05301215 hcd->self.b_hnp_enable) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001216 set_bit(wIndex, &ehci->suspended_ports);
Vijayavardhan Vennapusaa36dc2c2012-03-05 16:09:40 +05301217 otg_start_hnp(ehci->transceiver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001218 break;
1219 }
1220#endif
Alek Du331ac6b2009-07-13 12:41:20 +08001221 /* After above check the port must be connected.
1222 * Set appropriate bit thus could put phy into low power
1223 * mode if we have hostpc feature
1224 */
Alek Dub9df7942010-01-19 16:31:31 +08001225 temp &= ~PORT_WKCONN_E;
1226 temp |= PORT_WKDISC_E | PORT_WKOC_E;
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001227 if (ehci->susp_sof_bug)
1228 ehci_writel(ehci, temp, status_reg);
1229 else
1230 ehci_writel(ehci, temp | PORT_SUSPEND,
1231 status_reg);
Alek Du331ac6b2009-07-13 12:41:20 +08001232 if (hostpc_reg) {
Alek Dub9df7942010-01-19 16:31:31 +08001233 spin_unlock_irqrestore(&ehci->lock, flags);
Alek Du331ac6b2009-07-13 12:41:20 +08001234 msleep(5);/* 5ms for HCD enter low pwr mode */
Alek Dub9df7942010-01-19 16:31:31 +08001235 spin_lock_irqsave(&ehci->lock, flags);
Alek Du331ac6b2009-07-13 12:41:20 +08001236 temp1 = ehci_readl(ehci, hostpc_reg);
1237 ehci_writel(ehci, temp1 | HOSTPC_PHCD,
1238 hostpc_reg);
1239 temp1 = ehci_readl(ehci, hostpc_reg);
1240 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
1241 wIndex, (temp1 & HOSTPC_PHCD) ?
1242 "succeeded" : "failed");
1243 }
Alan Sterneafe5b92008-10-06 11:25:53 -04001244 set_bit(wIndex, &ehci->suspended_ports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 break;
1246 case USB_PORT_FEAT_POWER:
1247 if (HCS_PPC (ehci->hcs_params))
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001248 ehci_writel(ehci, temp | PORT_POWER,
Alan Sterne6316562007-01-16 11:58:00 -05001249 status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 break;
1251 case USB_PORT_FEAT_RESET:
1252 if (temp & PORT_RESUME)
1253 goto error;
1254 /* line status bits may report this as low speed,
1255 * which can be fine if this root hub has a
1256 * transaction translator built in.
1257 */
1258 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1259 && !ehci_is_TDI(ehci)
1260 && PORT_USB11 (temp)) {
1261 ehci_dbg (ehci,
1262 "port %d low speed --> companion\n",
1263 wIndex + 1);
1264 temp |= PORT_OWNER;
1265 } else {
1266 ehci_vdbg (ehci, "port %d reset\n", wIndex + 1);
1267 temp |= PORT_RESET;
1268 temp &= ~PORT_PE;
1269
1270 /*
1271 * caller must wait, then call GetPortStatus
1272 * usb 2.0 spec says 50 ms resets on root
1273 */
1274 ehci->reset_done [wIndex] = jiffies
1275 + msecs_to_jiffies (50);
1276 }
Alan Sterne6316562007-01-16 11:58:00 -05001277 ehci_writel(ehci, temp, status_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 break;
David Brownellf0d7f272006-11-16 23:56:15 -08001279
1280 /* For downstream facing ports (these): one hub port is put
1281 * into test mode according to USB2 11.24.2.13, then the hub
1282 * must be reset (which for root hub now means rmmod+modprobe,
1283 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1284 * about the EHCI-specific stuff.
1285 */
1286 case USB_PORT_FEAT_TEST:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001287 if (selector && selector <= 5) {
1288 ehci_quiesce(ehci);
Boris Todorov00c37d52011-07-11 12:03:33 +03001289
1290 /* Put all enabled ports into suspend */
Rohit Vaswania76e99a2012-03-30 00:09:34 -07001291 while (ports--) {
1292 u32 __iomem *sreg =
Boris Todorov00c37d52011-07-11 12:03:33 +03001293 &ehci->regs->port_status[ports];
1294
Rohit Vaswania76e99a2012-03-30 00:09:34 -07001295 temp = ehci_readl(ehci, sreg)
1296 & ~PORT_RWC_BITS;
1297 if (temp & PORT_PE)
1298 ehci_writel(ehci,
1299 temp | PORT_SUSPEND,
Boris Todorov00c37d52011-07-11 12:03:33 +03001300 sreg);
Rohit Vaswania76e99a2012-03-30 00:09:34 -07001301 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001302 ehci_halt(ehci);
Rohit Vaswania76e99a2012-03-30 00:09:34 -07001303 temp = ehci_readl(ehci, status_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001304 temp |= selector << 16;
1305 ehci_writel(ehci, temp, status_reg);
1306 }
1307#ifdef CONFIG_USB_EHCI_EHSET
1308 else if (selector
1309 == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
1310 spin_unlock_irqrestore(&ehci->lock, flags);
1311 retval = ehset_single_step_set_feature(hcd,
1312 wIndex);
1313 spin_lock_irqsave(&ehci->lock, flags);
1314 }
1315#endif
1316 else
David Brownellf0d7f272006-11-16 23:56:15 -08001317 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 default:
1319 goto error;
1320 }
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +11001321 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 break;
1323
1324 default:
1325error:
1326 /* "stall" on error */
1327 retval = -EPIPE;
1328 }
Jason Wessel8d053c72009-08-20 15:39:54 -05001329error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 spin_unlock_irqrestore (&ehci->lock, flags);
1331 return retval;
1332}
Balaji Rao90da0962007-11-22 01:58:14 +05301333
1334static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
1335{
1336 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1337
1338 if (ehci_is_TDI(ehci))
1339 return;
1340 set_owner(ehci, --portnum, PORT_OWNER);
1341}
1342
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001343static int __maybe_unused ehci_port_handed_over(struct usb_hcd *hcd, int portnum)
Alan Stern3a311552008-05-20 16:58:29 -04001344{
1345 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1346 u32 __iomem *reg;
1347
1348 if (ehci_is_TDI(ehci))
1349 return 0;
1350 reg = &ehci->regs->port_status[portnum - 1];
1351 return ehci_readl(ehci, reg) & PORT_OWNER;
1352}