2 * Copyright (C) 2001-2004 by David Brownell
4 * 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.
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
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.
19 /* this file is part of ehci-hcd.c */
21 /*-------------------------------------------------------------------------*/
24 * EHCI Root Hub ... the nonsharable stuff
26 * Registers don't need cpu_to_le32, that happens transparently
29 /*-------------------------------------------------------------------------*/
31 #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
35 static int ehci_hub_control(
44 /* After a power loss, ports that were owned by the companion must be
45 * reset so that the companion can still own them.
47 static void ehci_handover_companion_ports(struct ehci_hcd
*ehci
)
53 struct usb_hcd
*hcd
= ehci_to_hcd(ehci
);
55 if (!ehci
->owned_ports
)
58 /* Give the connections some time to appear */
61 port
= HCS_N_PORTS(ehci
->hcs_params
);
63 if (test_bit(port
, &ehci
->owned_ports
)) {
64 reg
= &ehci
->regs
->port_status
[port
];
65 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
67 /* Port already owned by companion? */
68 if (status
& PORT_OWNER
)
69 clear_bit(port
, &ehci
->owned_ports
);
70 else if (test_bit(port
, &ehci
->companion_ports
))
71 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
73 ehci_hub_control(hcd
, SetPortFeature
,
74 USB_PORT_FEAT_RESET
, port
+ 1,
79 if (!ehci
->owned_ports
)
81 msleep(90); /* Wait for resets to complete */
83 port
= HCS_N_PORTS(ehci
->hcs_params
);
85 if (test_bit(port
, &ehci
->owned_ports
)) {
86 ehci_hub_control(hcd
, GetPortStatus
,
88 (char *) &buf
, sizeof(buf
));
90 /* The companion should now own the port,
91 * but if something went wrong the port must not
94 reg
= &ehci
->regs
->port_status
[port
];
95 status
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
96 if (status
& PORT_OWNER
)
97 ehci_writel(ehci
, status
| PORT_CSC
, reg
);
99 ehci_dbg(ehci
, "failed handover port %d: %x\n",
101 ehci_writel(ehci
, status
& ~PORT_PE
, reg
);
106 ehci
->owned_ports
= 0;
109 static int ehci_port_change(struct ehci_hcd
*ehci
)
111 int i
= HCS_N_PORTS(ehci
->hcs_params
);
113 /* First check if the controller indicates a change event */
115 if (ehci_readl(ehci
, &ehci
->regs
->status
) & STS_PCD
)
119 * Not all controllers appear to update this while going from D3 to D0,
120 * so check the individual port status registers as well
124 if (ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]) & PORT_CSC
)
130 static void ehci_adjust_port_wakeup_flags(struct ehci_hcd
*ehci
,
131 bool suspending
, bool do_wakeup
)
137 /* If remote wakeup is enabled for the root hub but disabled
138 * for the controller, we must adjust all the port wakeup flags
139 * when the controller is suspended or resumed. In all other
140 * cases they don't need to be changed.
142 if (!ehci_to_hcd(ehci
)->self
.root_hub
->do_remote_wakeup
|| do_wakeup
)
145 spin_lock_irqsave(&ehci
->lock
, flags
);
147 /* clear phy low-power mode before changing wakeup flags */
148 if (ehci
->has_hostpc
) {
149 port
= HCS_N_PORTS(ehci
->hcs_params
);
151 u32 __iomem
*hostpc_reg
;
153 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
154 + HOSTPC0
+ 4 * port
);
155 temp
= ehci_readl(ehci
, hostpc_reg
);
156 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
, hostpc_reg
);
158 spin_unlock_irqrestore(&ehci
->lock
, flags
);
160 spin_lock_irqsave(&ehci
->lock
, flags
);
163 port
= HCS_N_PORTS(ehci
->hcs_params
);
165 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
166 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
167 u32 t2
= t1
& ~PORT_WAKE_BITS
;
169 /* If we are suspending the controller, clear the flags.
170 * If we are resuming the controller, set the wakeup flags.
173 if (t1
& PORT_CONNECT
)
174 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
176 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
178 ehci_vdbg(ehci
, "port %d, %08x -> %08x\n",
180 ehci_writel(ehci
, t2
, reg
);
183 /* enter phy low-power mode again */
184 if (ehci
->has_hostpc
) {
185 port
= HCS_N_PORTS(ehci
->hcs_params
);
187 u32 __iomem
*hostpc_reg
;
189 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
190 + HOSTPC0
+ 4 * port
);
191 temp
= ehci_readl(ehci
, hostpc_reg
);
192 ehci_writel(ehci
, temp
| HOSTPC_PHCD
, hostpc_reg
);
196 /* Does the root hub have a port wakeup pending? */
197 if (!suspending
&& ehci_port_change(ehci
))
198 usb_hcd_resume_root_hub(ehci_to_hcd(ehci
));
200 spin_unlock_irqrestore(&ehci
->lock
, flags
);
203 static int ehci_bus_suspend (struct usb_hcd
*hcd
)
205 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
210 ehci_dbg(ehci
, "suspend root hub\n");
212 if (time_before (jiffies
, ehci
->next_statechange
))
214 del_timer_sync(&ehci
->watchdog
);
215 del_timer_sync(&ehci
->iaa_watchdog
);
217 spin_lock_irq (&ehci
->lock
);
219 /* Once the controller is stopped, port resumes that are already
220 * in progress won't complete. Hence if remote wakeup is enabled
221 * for the root hub and any ports are in the middle of a resume or
222 * remote wakeup, we must fail the suspend.
224 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
225 port
= HCS_N_PORTS(ehci
->hcs_params
);
227 if (ehci
->reset_done
[port
] != 0) {
228 spin_unlock_irq(&ehci
->lock
);
229 ehci_dbg(ehci
, "suspend failed because "
230 "port %d is resuming\n",
237 /* stop schedules, clean any completed work */
238 if (HC_IS_RUNNING(hcd
->state
)) {
240 hcd
->state
= HC_STATE_QUIESCING
;
242 ehci
->command
= ehci_readl(ehci
, &ehci
->regs
->command
);
245 /* Unlike other USB host controller types, EHCI doesn't have
246 * any notion of "global" or bus-wide suspend. The driver has
247 * to manually suspend all the active unsuspended ports, and
248 * then manually resume them in the bus_resume() routine.
250 ehci
->bus_suspended
= 0;
251 ehci
->owned_ports
= 0;
253 port
= HCS_N_PORTS(ehci
->hcs_params
);
255 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
256 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
257 u32 t2
= t1
& ~PORT_WAKE_BITS
;
259 /* keep track of which ports we suspend */
261 set_bit(port
, &ehci
->owned_ports
);
262 else if ((t1
& PORT_PE
) && !(t1
& PORT_SUSPEND
)) {
264 set_bit(port
, &ehci
->bus_suspended
);
267 /* enable remote wakeup on all ports, if told to do so */
268 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
269 /* only enable appropriate wake bits, otherwise the
270 * hardware can not go phy low power mode. If a race
271 * condition happens here(connection change during bits
272 * set), the port change detection will finally fix it.
274 if (t1
& PORT_CONNECT
)
275 t2
|= PORT_WKOC_E
| PORT_WKDISC_E
;
277 t2
|= PORT_WKOC_E
| PORT_WKCONN_E
;
281 ehci_vdbg (ehci
, "port %d, %08x -> %08x\n",
283 ehci_writel(ehci
, t2
, reg
);
288 if (changed
&& ehci
->has_hostpc
) {
289 spin_unlock_irq(&ehci
->lock
);
290 msleep(5); /* 5 ms for HCD to enter low-power mode */
291 spin_lock_irq(&ehci
->lock
);
293 port
= HCS_N_PORTS(ehci
->hcs_params
);
295 u32 __iomem
*hostpc_reg
;
298 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
299 + HOSTPC0
+ 4 * port
);
300 t3
= ehci_readl(ehci
, hostpc_reg
);
301 ehci_writel(ehci
, t3
| HOSTPC_PHCD
, hostpc_reg
);
302 t3
= ehci_readl(ehci
, hostpc_reg
);
303 ehci_dbg(ehci
, "Port %d phy low-power mode %s\n",
304 port
, (t3
& HOSTPC_PHCD
) ?
305 "succeeded" : "failed");
309 /* Apparently some devices need a >= 1-uframe delay here */
310 if (ehci
->bus_suspended
)
313 /* turn off now-idle HC */
315 hcd
->state
= HC_STATE_SUSPENDED
;
318 end_unlink_async(ehci
);
320 /* allow remote wakeup */
322 if (!hcd
->self
.root_hub
->do_remote_wakeup
)
324 ehci_writel(ehci
, mask
, &ehci
->regs
->intr_enable
);
325 ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
327 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(10);
328 spin_unlock_irq (&ehci
->lock
);
330 /* ehci_work() may have re-enabled the watchdog timer, which we do not
331 * want, and so we must delete any pending watchdog timer events.
333 del_timer_sync(&ehci
->watchdog
);
338 /* caller has locked the root hub, and should reset/reinit on error */
339 static int ehci_bus_resume (struct usb_hcd
*hcd
)
341 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
345 u8 resume_needed
= 0;
347 if (time_before (jiffies
, ehci
->next_statechange
))
349 spin_lock_irq (&ehci
->lock
);
350 if (!HCD_HW_ACCESSIBLE(hcd
)) {
351 spin_unlock_irq(&ehci
->lock
);
355 if (unlikely(ehci
->debug
)) {
356 if (!dbgp_reset_prep())
359 dbgp_external_startup();
362 /* Ideally and we've got a real resume here, and no port's power
363 * was lost. (For PCI, that means Vaux was maintained.) But we
364 * could instead be restoring a swsusp snapshot -- so that BIOS was
365 * the last user of the controller, not reset/pm hardware keeping
366 * state we gave to it.
368 power_okay
= ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
369 ehci_dbg(ehci
, "resume root hub%s\n",
370 power_okay
? "" : " after power loss");
372 /* at least some APM implementations will try to deliver
373 * IRQs right away, so delay them until we're ready.
375 ehci_writel(ehci
, 0, &ehci
->regs
->intr_enable
);
377 /* re-init operational registers */
378 ehci_writel(ehci
, 0, &ehci
->regs
->segment
);
379 ehci_writel(ehci
, ehci
->periodic_dma
, &ehci
->regs
->frame_list
);
380 ehci_writel(ehci
, (u32
) ehci
->async
->qh_dma
, &ehci
->regs
->async_next
);
382 /* restore CMD_RUN, framelist size, and irq threshold */
383 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
385 /* Some controller/firmware combinations need a delay during which
386 * they set up the port statuses. See Bugzilla #8190. */
387 spin_unlock_irq(&ehci
->lock
);
389 spin_lock_irq(&ehci
->lock
);
391 /* clear phy low-power mode before resume */
392 if (ehci
->bus_suspended
&& ehci
->has_hostpc
) {
393 i
= HCS_N_PORTS(ehci
->hcs_params
);
395 if (test_bit(i
, &ehci
->bus_suspended
)) {
396 u32 __iomem
*hostpc_reg
;
398 hostpc_reg
= (u32 __iomem
*)((u8
*) ehci
->regs
400 temp
= ehci_readl(ehci
, hostpc_reg
);
401 ehci_writel(ehci
, temp
& ~HOSTPC_PHCD
,
405 spin_unlock_irq(&ehci
->lock
);
407 spin_lock_irq(&ehci
->lock
);
410 /* manually resume the ports we suspended during bus_suspend() */
411 i
= HCS_N_PORTS (ehci
->hcs_params
);
413 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
414 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
415 if (test_bit(i
, &ehci
->bus_suspended
) &&
416 (temp
& PORT_SUSPEND
)) {
420 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
423 /* msleep for 20ms only if code is trying to resume port */
425 spin_unlock_irq(&ehci
->lock
);
427 spin_lock_irq(&ehci
->lock
);
430 i
= HCS_N_PORTS (ehci
->hcs_params
);
432 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
433 if (test_bit(i
, &ehci
->bus_suspended
) &&
434 (temp
& PORT_SUSPEND
)) {
435 temp
&= ~(PORT_RWC_BITS
| PORT_RESUME
);
436 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
437 ehci_vdbg (ehci
, "resumed port %d\n", i
+ 1);
440 (void) ehci_readl(ehci
, &ehci
->regs
->command
);
442 /* maybe re-activate the schedule(s) */
444 if (ehci
->async
->qh_next
.qh
)
446 if (ehci
->periodic_sched
)
449 ehci
->command
|= temp
;
450 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
453 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
454 hcd
->state
= HC_STATE_RUNNING
;
456 /* Now we can safely re-enable irqs */
457 ehci_writel(ehci
, INTR_MASK
, &ehci
->regs
->intr_enable
);
459 spin_unlock_irq (&ehci
->lock
);
460 ehci_handover_companion_ports(ehci
);
466 #define ehci_bus_suspend NULL
467 #define ehci_bus_resume NULL
469 #endif /* CONFIG_PM */
471 /*-------------------------------------------------------------------------*/
473 /* Display the ports dedicated to the companion controller */
474 static ssize_t
show_companion(struct device
*dev
,
475 struct device_attribute
*attr
,
478 struct ehci_hcd
*ehci
;
479 int nports
, index
, n
;
480 int count
= PAGE_SIZE
;
483 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
484 nports
= HCS_N_PORTS(ehci
->hcs_params
);
486 for (index
= 0; index
< nports
; ++index
) {
487 if (test_bit(index
, &ehci
->companion_ports
)) {
488 n
= scnprintf(ptr
, count
, "%d\n", index
+ 1);
497 * Sets the owner of a port
499 static void set_owner(struct ehci_hcd
*ehci
, int portnum
, int new_owner
)
501 u32 __iomem
*status_reg
;
505 status_reg
= &ehci
->regs
->port_status
[portnum
];
508 * The controller won't set the OWNER bit if the port is
509 * enabled, so this loop will sometimes require at least two
510 * iterations: one to disable the port and one to set OWNER.
512 for (try = 4; try > 0; --try) {
513 spin_lock_irq(&ehci
->lock
);
514 port_status
= ehci_readl(ehci
, status_reg
);
515 if ((port_status
& PORT_OWNER
) == new_owner
516 || (port_status
& (PORT_OWNER
| PORT_CONNECT
))
520 port_status
^= PORT_OWNER
;
521 port_status
&= ~(PORT_PE
| PORT_RWC_BITS
);
522 ehci_writel(ehci
, port_status
, status_reg
);
524 spin_unlock_irq(&ehci
->lock
);
531 * Dedicate or undedicate a port to the companion controller.
532 * Syntax is "[-]portnum", where a leading '-' sign means
533 * return control of the port to the EHCI controller.
535 static ssize_t
store_companion(struct device
*dev
,
536 struct device_attribute
*attr
,
537 const char *buf
, size_t count
)
539 struct ehci_hcd
*ehci
;
540 int portnum
, new_owner
;
542 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
543 new_owner
= PORT_OWNER
; /* Owned by companion */
544 if (sscanf(buf
, "%d", &portnum
) != 1)
548 new_owner
= 0; /* Owned by EHCI */
550 if (portnum
<= 0 || portnum
> HCS_N_PORTS(ehci
->hcs_params
))
554 set_bit(portnum
, &ehci
->companion_ports
);
556 clear_bit(portnum
, &ehci
->companion_ports
);
557 set_owner(ehci
, portnum
, new_owner
);
560 static DEVICE_ATTR(companion
, 0644, show_companion
, store_companion
);
562 static inline int create_companion_file(struct ehci_hcd
*ehci
)
566 /* with integrated TT there is no companion! */
567 if (!ehci_is_TDI(ehci
))
568 i
= device_create_file(ehci_to_hcd(ehci
)->self
.controller
,
569 &dev_attr_companion
);
573 static inline void remove_companion_file(struct ehci_hcd
*ehci
)
575 /* with integrated TT there is no companion! */
576 if (!ehci_is_TDI(ehci
))
577 device_remove_file(ehci_to_hcd(ehci
)->self
.controller
,
578 &dev_attr_companion
);
582 /*-------------------------------------------------------------------------*/
584 static int check_reset_complete (
585 struct ehci_hcd
*ehci
,
587 u32 __iomem
*status_reg
,
590 if (!(port_status
& PORT_CONNECT
))
593 /* if reset finished and it's still not enabled -- handoff */
594 if (!(port_status
& PORT_PE
)) {
596 /* with integrated TT, there's nobody to hand it to! */
597 if (ehci_is_TDI(ehci
)) {
599 "Failed to enable port %d on root hub TT\n",
604 ehci_dbg (ehci
, "port %d full speed --> companion\n",
607 // what happens if HCS_N_CC(params) == 0 ?
608 port_status
|= PORT_OWNER
;
609 port_status
&= ~PORT_RWC_BITS
;
610 ehci_writel(ehci
, port_status
, status_reg
);
612 /* ensure 440EPX ohci controller state is operational */
613 if (ehci
->has_amcc_usb23
)
614 set_ohci_hcfs(ehci
, 1);
616 ehci_dbg (ehci
, "port %d high speed\n", index
+ 1);
617 /* ensure 440EPx ohci controller state is suspended */
618 if (ehci
->has_amcc_usb23
)
619 set_ohci_hcfs(ehci
, 0);
625 /*-------------------------------------------------------------------------*/
628 /* build "status change" packet (one or two bytes) from HC registers */
631 ehci_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
633 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
634 u32 temp
, status
= 0;
636 int ports
, i
, retval
= 1;
640 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
641 if (!HC_IS_RUNNING(hcd
->state
))
644 /* init status to no-changes */
646 ports
= HCS_N_PORTS (ehci
->hcs_params
);
652 /* Some boards (mostly VIA?) report bogus overcurrent indications,
653 * causing massive log spam unless we completely ignore them. It
654 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
655 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
656 * PORT_POWER; that's surprising, but maybe within-spec.
659 mask
= PORT_CSC
| PORT_PEC
| PORT_OCC
;
661 mask
= PORT_CSC
| PORT_PEC
;
662 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
664 /* no hub change reports (bit 0) for now (power, ...) */
666 /* port N changes (bit N)? */
667 spin_lock_irqsave (&ehci
->lock
, flags
);
669 /* get per-port change detect bits */
671 ppcd
= ehci_readl(ehci
, &ehci
->regs
->status
) >> 16;
673 for (i
= 0; i
< ports
; i
++) {
674 /* leverage per-port change bits feature */
675 if (ehci
->has_ppcd
&& !(ppcd
& (1 << i
)))
677 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
680 * Return status information even for ports with OWNER set.
681 * Otherwise khubd wouldn't see the disconnect event when a
682 * high-speed device is switched over to the companion
683 * controller by the user.
686 if ((temp
& mask
) != 0 || test_bit(i
, &ehci
->port_c_suspend
)
687 || (ehci
->reset_done
[i
] && time_after_eq(
688 jiffies
, ehci
->reset_done
[i
]))) {
690 buf
[0] |= 1 << (i
+ 1);
692 buf
[1] |= 1 << (i
- 7);
696 /* FIXME autosuspend idle root hubs */
697 spin_unlock_irqrestore (&ehci
->lock
, flags
);
698 return status
? retval
: 0;
701 /*-------------------------------------------------------------------------*/
704 ehci_hub_descriptor (
705 struct ehci_hcd
*ehci
,
706 struct usb_hub_descriptor
*desc
708 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
711 desc
->bDescriptorType
= 0x29;
712 desc
->bPwrOn2PwrGood
= 10; /* ehci 1.0, 2.3.9 says 20ms max */
713 desc
->bHubContrCurrent
= 0;
715 desc
->bNbrPorts
= ports
;
716 temp
= 1 + (ports
/ 8);
717 desc
->bDescLength
= 7 + 2 * temp
;
719 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
720 memset (&desc
->bitmap
[0], 0, temp
);
721 memset (&desc
->bitmap
[temp
], 0xff, temp
);
723 temp
= 0x0008; /* per-port overcurrent reporting */
724 if (HCS_PPC (ehci
->hcs_params
))
725 temp
|= 0x0001; /* per-port power control */
727 temp
|= 0x0002; /* no power switching */
729 // re-enable when we support USB_PORT_FEAT_INDICATOR below.
730 if (HCS_INDICATOR (ehci
->hcs_params
))
731 temp
|= 0x0080; /* per-port indicators (LEDs) */
733 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
736 /*-------------------------------------------------------------------------*/
738 static int ehci_hub_control (
746 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
747 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
748 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
749 (wIndex
& 0xff) - 1];
750 u32 __iomem
*hostpc_reg
= NULL
;
751 u32 temp
, temp1
, status
;
757 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
758 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
759 * (track current state ourselves) ... blink for diagnostics,
760 * power, "this is the one", etc. EHCI spec supports this.
763 if (ehci
->has_hostpc
)
764 hostpc_reg
= (u32 __iomem
*)((u8
*)ehci
->regs
765 + HOSTPC0
+ 4 * ((wIndex
& 0xff) - 1));
766 spin_lock_irqsave (&ehci
->lock
, flags
);
768 case ClearHubFeature
:
770 case C_HUB_LOCAL_POWER
:
771 case C_HUB_OVER_CURRENT
:
772 /* no hub-wide feature/status flags */
778 case ClearPortFeature
:
779 if (!wIndex
|| wIndex
> ports
)
782 temp
= ehci_readl(ehci
, status_reg
);
785 * Even if OWNER is set, so the port is owned by the
786 * companion controller, khubd needs to be able to clear
787 * the port-change status bits (especially
788 * USB_PORT_STAT_C_CONNECTION).
792 case USB_PORT_FEAT_ENABLE
:
793 ehci_writel(ehci
, temp
& ~PORT_PE
, status_reg
);
795 case USB_PORT_FEAT_C_ENABLE
:
796 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_PEC
,
799 case USB_PORT_FEAT_SUSPEND
:
800 if (temp
& PORT_RESET
)
802 if (ehci
->no_selective_suspend
)
804 if (!(temp
& PORT_SUSPEND
))
806 if ((temp
& PORT_PE
) == 0)
809 /* clear phy low-power mode before resume */
811 temp1
= ehci_readl(ehci
, hostpc_reg
);
812 ehci_writel(ehci
, temp1
& ~HOSTPC_PHCD
,
814 spin_unlock_irqrestore(&ehci
->lock
, flags
);
815 msleep(5);/* wait to leave low-power mode */
816 spin_lock_irqsave(&ehci
->lock
, flags
);
818 /* resume signaling for 20 msec */
819 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
820 ehci_writel(ehci
, temp
| PORT_RESUME
, status_reg
);
821 ehci
->reset_done
[wIndex
] = jiffies
822 + msecs_to_jiffies(20);
824 case USB_PORT_FEAT_C_SUSPEND
:
825 clear_bit(wIndex
, &ehci
->port_c_suspend
);
827 case USB_PORT_FEAT_POWER
:
828 if (HCS_PPC (ehci
->hcs_params
))
830 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
833 case USB_PORT_FEAT_C_CONNECTION
:
835 /* clear PORTSC bits on disconnect */
837 temp
&= ~PORT_DEV_ADDR
;
839 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_CSC
,
842 case USB_PORT_FEAT_C_OVER_CURRENT
:
843 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_OCC
,
846 case USB_PORT_FEAT_C_RESET
:
847 /* GetPortStatus clears reset */
852 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted write */
854 case GetHubDescriptor
:
855 ehci_hub_descriptor (ehci
, (struct usb_hub_descriptor
*)
859 /* no hub-wide feature/status flags */
861 //cpu_to_le32s ((u32 *) buf);
864 if (!wIndex
|| wIndex
> ports
)
868 temp
= ehci_readl(ehci
, status_reg
);
872 status
|= USB_PORT_STAT_C_CONNECTION
<< 16;
874 status
|= USB_PORT_STAT_C_ENABLE
<< 16;
876 if ((temp
& PORT_OCC
) && !ignore_oc
){
877 status
|= USB_PORT_STAT_C_OVERCURRENT
<< 16;
880 * Hubs should disable port power on over-current.
881 * However, not all EHCI implementations do this
882 * automatically, even if they _do_ support per-port
883 * power switching; they're allowed to just limit the
884 * current. khubd will turn the power back on.
886 if (HCS_PPC (ehci
->hcs_params
)){
888 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
893 /* whoever resumes must GetPortStatus to complete it!! */
894 if (temp
& PORT_RESUME
) {
896 /* Remote Wakeup received? */
897 if (!ehci
->reset_done
[wIndex
]) {
898 /* resume signaling for 20 msec */
899 ehci
->reset_done
[wIndex
] = jiffies
900 + msecs_to_jiffies(20);
901 /* check the port again */
902 mod_timer(&ehci_to_hcd(ehci
)->rh_timer
,
903 ehci
->reset_done
[wIndex
]);
906 /* resume completed? */
907 else if (time_after_eq(jiffies
,
908 ehci
->reset_done
[wIndex
])) {
909 clear_bit(wIndex
, &ehci
->suspended_ports
);
910 set_bit(wIndex
, &ehci
->port_c_suspend
);
911 ehci
->reset_done
[wIndex
] = 0;
913 /* stop resume signaling */
914 temp
= ehci_readl(ehci
, status_reg
);
916 temp
& ~(PORT_RWC_BITS
| PORT_RESUME
),
918 retval
= handshake(ehci
, status_reg
,
919 PORT_RESUME
, 0, 2000 /* 2msec */);
922 "port %d resume error %d\n",
926 temp
&= ~(PORT_SUSPEND
|PORT_RESUME
|(3<<10));
930 /* whoever resets must GetPortStatus to complete it!! */
931 if ((temp
& PORT_RESET
)
932 && time_after_eq(jiffies
,
933 ehci
->reset_done
[wIndex
])) {
934 status
|= USB_PORT_STAT_C_RESET
<< 16;
935 ehci
->reset_done
[wIndex
] = 0;
937 /* force reset to complete */
938 ehci_writel(ehci
, temp
& ~(PORT_RWC_BITS
| PORT_RESET
),
940 /* REVISIT: some hardware needs 550+ usec to clear
941 * this bit; seems too long to spin routinely...
943 retval
= handshake(ehci
, status_reg
,
944 PORT_RESET
, 0, 1000);
946 ehci_err (ehci
, "port %d reset error %d\n",
951 /* see what we found out */
952 temp
= check_reset_complete (ehci
, wIndex
, status_reg
,
953 ehci_readl(ehci
, status_reg
));
956 if (!(temp
& (PORT_RESUME
|PORT_RESET
)))
957 ehci
->reset_done
[wIndex
] = 0;
959 /* transfer dedicated ports to the companion hc */
960 if ((temp
& PORT_CONNECT
) &&
961 test_bit(wIndex
, &ehci
->companion_ports
)) {
962 temp
&= ~PORT_RWC_BITS
;
964 ehci_writel(ehci
, temp
, status_reg
);
965 ehci_dbg(ehci
, "port %d --> companion\n", wIndex
+ 1);
966 temp
= ehci_readl(ehci
, status_reg
);
970 * Even if OWNER is set, there's no harm letting khubd
971 * see the wPortStatus values (they should all be 0 except
972 * for PORT_POWER anyway).
975 if (temp
& PORT_CONNECT
) {
976 status
|= USB_PORT_STAT_CONNECTION
;
977 // status may be from integrated TT
978 if (ehci
->has_hostpc
) {
979 temp1
= ehci_readl(ehci
, hostpc_reg
);
980 status
|= ehci_port_speed(ehci
, temp1
);
982 status
|= ehci_port_speed(ehci
, temp
);
985 status
|= USB_PORT_STAT_ENABLE
;
987 /* maybe the port was unsuspended without our knowledge */
988 if (temp
& (PORT_SUSPEND
|PORT_RESUME
)) {
989 status
|= USB_PORT_STAT_SUSPEND
;
990 } else if (test_bit(wIndex
, &ehci
->suspended_ports
)) {
991 clear_bit(wIndex
, &ehci
->suspended_ports
);
992 ehci
->reset_done
[wIndex
] = 0;
994 set_bit(wIndex
, &ehci
->port_c_suspend
);
998 status
|= USB_PORT_STAT_OVERCURRENT
;
999 if (temp
& PORT_RESET
)
1000 status
|= USB_PORT_STAT_RESET
;
1001 if (temp
& PORT_POWER
)
1002 status
|= USB_PORT_STAT_POWER
;
1003 if (test_bit(wIndex
, &ehci
->port_c_suspend
))
1004 status
|= USB_PORT_STAT_C_SUSPEND
<< 16;
1006 #ifndef VERBOSE_DEBUG
1007 if (status
& ~0xffff) /* only if wPortChange is interesting */
1009 dbg_port (ehci
, "GetStatus", wIndex
+ 1, temp
);
1010 put_unaligned_le32(status
, buf
);
1014 case C_HUB_LOCAL_POWER
:
1015 case C_HUB_OVER_CURRENT
:
1016 /* no hub-wide feature/status flags */
1022 case SetPortFeature
:
1023 selector
= wIndex
>> 8;
1025 if (unlikely(ehci
->debug
)) {
1026 /* If the debug port is active any port
1027 * feature requests should get denied */
1028 if (wIndex
== HCS_DEBUG_PORT(ehci
->hcs_params
) &&
1029 (readl(&ehci
->debug
->control
) & DBGP_ENABLED
)) {
1034 if (!wIndex
|| wIndex
> ports
)
1037 temp
= ehci_readl(ehci
, status_reg
);
1038 if (temp
& PORT_OWNER
)
1041 temp
&= ~PORT_RWC_BITS
;
1043 case USB_PORT_FEAT_SUSPEND
:
1044 if (ehci
->no_selective_suspend
)
1046 if ((temp
& PORT_PE
) == 0
1047 || (temp
& PORT_RESET
) != 0)
1050 /* After above check the port must be connected.
1051 * Set appropriate bit thus could put phy into low power
1052 * mode if we have hostpc feature
1054 temp
&= ~PORT_WKCONN_E
;
1055 temp
|= PORT_WKDISC_E
| PORT_WKOC_E
;
1056 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
1058 spin_unlock_irqrestore(&ehci
->lock
, flags
);
1059 msleep(5);/* 5ms for HCD enter low pwr mode */
1060 spin_lock_irqsave(&ehci
->lock
, flags
);
1061 temp1
= ehci_readl(ehci
, hostpc_reg
);
1062 ehci_writel(ehci
, temp1
| HOSTPC_PHCD
,
1064 temp1
= ehci_readl(ehci
, hostpc_reg
);
1065 ehci_dbg(ehci
, "Port%d phy low pwr mode %s\n",
1066 wIndex
, (temp1
& HOSTPC_PHCD
) ?
1067 "succeeded" : "failed");
1069 set_bit(wIndex
, &ehci
->suspended_ports
);
1071 case USB_PORT_FEAT_POWER
:
1072 if (HCS_PPC (ehci
->hcs_params
))
1073 ehci_writel(ehci
, temp
| PORT_POWER
,
1076 case USB_PORT_FEAT_RESET
:
1077 if (temp
& PORT_RESUME
)
1079 /* line status bits may report this as low speed,
1080 * which can be fine if this root hub has a
1081 * transaction translator built in.
1083 if ((temp
& (PORT_PE
|PORT_CONNECT
)) == PORT_CONNECT
1084 && !ehci_is_TDI(ehci
)
1085 && PORT_USB11 (temp
)) {
1087 "port %d low speed --> companion\n",
1091 ehci_vdbg (ehci
, "port %d reset\n", wIndex
+ 1);
1096 * caller must wait, then call GetPortStatus
1097 * usb 2.0 spec says 50 ms resets on root
1099 ehci
->reset_done
[wIndex
] = jiffies
1100 + msecs_to_jiffies (50);
1102 ehci_writel(ehci
, temp
, status_reg
);
1105 /* For downstream facing ports (these): one hub port is put
1106 * into test mode according to USB2 11.24.2.13, then the hub
1107 * must be reset (which for root hub now means rmmod+modprobe,
1108 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1109 * about the EHCI-specific stuff.
1111 case USB_PORT_FEAT_TEST
:
1112 if (!selector
|| selector
> 5)
1116 temp
|= selector
<< 16;
1117 ehci_writel(ehci
, temp
, status_reg
);
1123 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted writes */
1128 /* "stall" on error */
1132 spin_unlock_irqrestore (&ehci
->lock
, flags
);
1136 static void ehci_relinquish_port(struct usb_hcd
*hcd
, int portnum
)
1138 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1140 if (ehci_is_TDI(ehci
))
1142 set_owner(ehci
, --portnum
, PORT_OWNER
);
1145 static int ehci_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
1147 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
1150 if (ehci_is_TDI(ehci
))
1152 reg
= &ehci
->regs
->port_status
[portnum
- 1];
1153 return ehci_readl(ehci
, reg
) & PORT_OWNER
;