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_bus_suspend (struct usb_hcd
*hcd
)
111 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
115 ehci_dbg(ehci
, "suspend root hub\n");
117 if (time_before (jiffies
, ehci
->next_statechange
))
119 del_timer_sync(&ehci
->watchdog
);
120 del_timer_sync(&ehci
->iaa_watchdog
);
122 spin_lock_irq (&ehci
->lock
);
124 /* Once the controller is stopped, port resumes that are already
125 * in progress won't complete. Hence if remote wakeup is enabled
126 * for the root hub and any ports are in the middle of a resume or
127 * remote wakeup, we must fail the suspend.
129 if (hcd
->self
.root_hub
->do_remote_wakeup
) {
130 port
= HCS_N_PORTS(ehci
->hcs_params
);
132 if (ehci
->reset_done
[port
] != 0) {
133 spin_unlock_irq(&ehci
->lock
);
134 ehci_dbg(ehci
, "suspend failed because "
135 "port %d is resuming\n",
142 /* stop schedules, clean any completed work */
143 if (HC_IS_RUNNING(hcd
->state
)) {
145 hcd
->state
= HC_STATE_QUIESCING
;
147 ehci
->command
= ehci_readl(ehci
, &ehci
->regs
->command
);
150 /* Unlike other USB host controller types, EHCI doesn't have
151 * any notion of "global" or bus-wide suspend. The driver has
152 * to manually suspend all the active unsuspended ports, and
153 * then manually resume them in the bus_resume() routine.
155 ehci
->bus_suspended
= 0;
156 ehci
->owned_ports
= 0;
157 port
= HCS_N_PORTS(ehci
->hcs_params
);
159 u32 __iomem
*reg
= &ehci
->regs
->port_status
[port
];
160 u32 t1
= ehci_readl(ehci
, reg
) & ~PORT_RWC_BITS
;
163 /* keep track of which ports we suspend */
165 set_bit(port
, &ehci
->owned_ports
);
166 else if ((t1
& PORT_PE
) && !(t1
& PORT_SUSPEND
)) {
168 set_bit(port
, &ehci
->bus_suspended
);
171 /* enable remote wakeup on all ports */
172 if (hcd
->self
.root_hub
->do_remote_wakeup
)
173 t2
|= PORT_WAKE_BITS
;
175 t2
&= ~PORT_WAKE_BITS
;
178 ehci_vdbg (ehci
, "port %d, %08x -> %08x\n",
180 ehci_writel(ehci
, t2
, reg
);
184 /* Apparently some devices need a >= 1-uframe delay here */
185 if (ehci
->bus_suspended
)
188 /* turn off now-idle HC */
190 hcd
->state
= HC_STATE_SUSPENDED
;
193 end_unlink_async(ehci
);
195 /* allow remote wakeup */
197 if (!hcd
->self
.root_hub
->do_remote_wakeup
)
199 ehci_writel(ehci
, mask
, &ehci
->regs
->intr_enable
);
200 ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
202 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(10);
203 spin_unlock_irq (&ehci
->lock
);
205 /* ehci_work() may have re-enabled the watchdog timer, which we do not
206 * want, and so we must delete any pending watchdog timer events.
208 del_timer_sync(&ehci
->watchdog
);
213 /* caller has locked the root hub, and should reset/reinit on error */
214 static int ehci_bus_resume (struct usb_hcd
*hcd
)
216 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
220 u8 resume_needed
= 0;
222 if (time_before (jiffies
, ehci
->next_statechange
))
224 spin_lock_irq (&ehci
->lock
);
225 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)) {
226 spin_unlock_irq(&ehci
->lock
);
230 /* Ideally and we've got a real resume here, and no port's power
231 * was lost. (For PCI, that means Vaux was maintained.) But we
232 * could instead be restoring a swsusp snapshot -- so that BIOS was
233 * the last user of the controller, not reset/pm hardware keeping
234 * state we gave to it.
236 power_okay
= ehci_readl(ehci
, &ehci
->regs
->intr_enable
);
237 ehci_dbg(ehci
, "resume root hub%s\n",
238 power_okay
? "" : " after power loss");
240 /* at least some APM implementations will try to deliver
241 * IRQs right away, so delay them until we're ready.
243 ehci_writel(ehci
, 0, &ehci
->regs
->intr_enable
);
245 /* re-init operational registers */
246 ehci_writel(ehci
, 0, &ehci
->regs
->segment
);
247 ehci_writel(ehci
, ehci
->periodic_dma
, &ehci
->regs
->frame_list
);
248 ehci_writel(ehci
, (u32
) ehci
->async
->qh_dma
, &ehci
->regs
->async_next
);
250 /* restore CMD_RUN, framelist size, and irq threshold */
251 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
253 /* Some controller/firmware combinations need a delay during which
254 * they set up the port statuses. See Bugzilla #8190. */
255 spin_unlock_irq(&ehci
->lock
);
257 spin_lock_irq(&ehci
->lock
);
259 /* manually resume the ports we suspended during bus_suspend() */
260 i
= HCS_N_PORTS (ehci
->hcs_params
);
262 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
263 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
264 if (test_bit(i
, &ehci
->bus_suspended
) &&
265 (temp
& PORT_SUSPEND
)) {
269 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
272 /* msleep for 20ms only if code is trying to resume port */
274 spin_unlock_irq(&ehci
->lock
);
276 spin_lock_irq(&ehci
->lock
);
279 i
= HCS_N_PORTS (ehci
->hcs_params
);
281 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
282 if (test_bit(i
, &ehci
->bus_suspended
) &&
283 (temp
& PORT_SUSPEND
)) {
284 temp
&= ~(PORT_RWC_BITS
| PORT_RESUME
);
285 ehci_writel(ehci
, temp
, &ehci
->regs
->port_status
[i
]);
286 ehci_vdbg (ehci
, "resumed port %d\n", i
+ 1);
289 (void) ehci_readl(ehci
, &ehci
->regs
->command
);
291 /* maybe re-activate the schedule(s) */
293 if (ehci
->async
->qh_next
.qh
)
295 if (ehci
->periodic_sched
)
298 ehci
->command
|= temp
;
299 ehci_writel(ehci
, ehci
->command
, &ehci
->regs
->command
);
302 ehci
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
303 hcd
->state
= HC_STATE_RUNNING
;
305 /* Now we can safely re-enable irqs */
306 ehci_writel(ehci
, INTR_MASK
, &ehci
->regs
->intr_enable
);
308 spin_unlock_irq (&ehci
->lock
);
309 ehci_handover_companion_ports(ehci
);
315 #define ehci_bus_suspend NULL
316 #define ehci_bus_resume NULL
318 #endif /* CONFIG_PM */
320 /*-------------------------------------------------------------------------*/
322 /* Display the ports dedicated to the companion controller */
323 static ssize_t
show_companion(struct device
*dev
,
324 struct device_attribute
*attr
,
327 struct ehci_hcd
*ehci
;
328 int nports
, index
, n
;
329 int count
= PAGE_SIZE
;
332 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
333 nports
= HCS_N_PORTS(ehci
->hcs_params
);
335 for (index
= 0; index
< nports
; ++index
) {
336 if (test_bit(index
, &ehci
->companion_ports
)) {
337 n
= scnprintf(ptr
, count
, "%d\n", index
+ 1);
346 * Sets the owner of a port
348 static void set_owner(struct ehci_hcd
*ehci
, int portnum
, int new_owner
)
350 u32 __iomem
*status_reg
;
354 status_reg
= &ehci
->regs
->port_status
[portnum
];
357 * The controller won't set the OWNER bit if the port is
358 * enabled, so this loop will sometimes require at least two
359 * iterations: one to disable the port and one to set OWNER.
361 for (try = 4; try > 0; --try) {
362 spin_lock_irq(&ehci
->lock
);
363 port_status
= ehci_readl(ehci
, status_reg
);
364 if ((port_status
& PORT_OWNER
) == new_owner
365 || (port_status
& (PORT_OWNER
| PORT_CONNECT
))
369 port_status
^= PORT_OWNER
;
370 port_status
&= ~(PORT_PE
| PORT_RWC_BITS
);
371 ehci_writel(ehci
, port_status
, status_reg
);
373 spin_unlock_irq(&ehci
->lock
);
380 * Dedicate or undedicate a port to the companion controller.
381 * Syntax is "[-]portnum", where a leading '-' sign means
382 * return control of the port to the EHCI controller.
384 static ssize_t
store_companion(struct device
*dev
,
385 struct device_attribute
*attr
,
386 const char *buf
, size_t count
)
388 struct ehci_hcd
*ehci
;
389 int portnum
, new_owner
;
391 ehci
= hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev
)));
392 new_owner
= PORT_OWNER
; /* Owned by companion */
393 if (sscanf(buf
, "%d", &portnum
) != 1)
397 new_owner
= 0; /* Owned by EHCI */
399 if (portnum
<= 0 || portnum
> HCS_N_PORTS(ehci
->hcs_params
))
403 set_bit(portnum
, &ehci
->companion_ports
);
405 clear_bit(portnum
, &ehci
->companion_ports
);
406 set_owner(ehci
, portnum
, new_owner
);
409 static DEVICE_ATTR(companion
, 0644, show_companion
, store_companion
);
411 static inline void create_companion_file(struct ehci_hcd
*ehci
)
415 /* with integrated TT there is no companion! */
416 if (!ehci_is_TDI(ehci
))
417 i
= device_create_file(ehci_to_hcd(ehci
)->self
.controller
,
418 &dev_attr_companion
);
421 static inline void remove_companion_file(struct ehci_hcd
*ehci
)
423 /* with integrated TT there is no companion! */
424 if (!ehci_is_TDI(ehci
))
425 device_remove_file(ehci_to_hcd(ehci
)->self
.controller
,
426 &dev_attr_companion
);
430 /*-------------------------------------------------------------------------*/
432 static int check_reset_complete (
433 struct ehci_hcd
*ehci
,
435 u32 __iomem
*status_reg
,
438 if (!(port_status
& PORT_CONNECT
))
441 /* if reset finished and it's still not enabled -- handoff */
442 if (!(port_status
& PORT_PE
)) {
444 /* with integrated TT, there's nobody to hand it to! */
445 if (ehci_is_TDI(ehci
)) {
447 "Failed to enable port %d on root hub TT\n",
452 ehci_dbg (ehci
, "port %d full speed --> companion\n",
455 // what happens if HCS_N_CC(params) == 0 ?
456 port_status
|= PORT_OWNER
;
457 port_status
&= ~PORT_RWC_BITS
;
458 ehci_writel(ehci
, port_status
, status_reg
);
461 ehci_dbg (ehci
, "port %d high speed\n", index
+ 1);
466 /*-------------------------------------------------------------------------*/
469 /* build "status change" packet (one or two bytes) from HC registers */
472 ehci_hub_status_data (struct usb_hcd
*hcd
, char *buf
)
474 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
475 u32 temp
, status
= 0;
477 int ports
, i
, retval
= 1;
480 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
481 if (!HC_IS_RUNNING(hcd
->state
))
484 /* init status to no-changes */
486 ports
= HCS_N_PORTS (ehci
->hcs_params
);
492 /* Some boards (mostly VIA?) report bogus overcurrent indications,
493 * causing massive log spam unless we completely ignore them. It
494 * may be relevant that VIA VT8235 controlers, where PORT_POWER is
495 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
496 * PORT_POWER; that's surprising, but maybe within-spec.
499 mask
= PORT_CSC
| PORT_PEC
| PORT_OCC
;
501 mask
= PORT_CSC
| PORT_PEC
;
502 // PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
504 /* no hub change reports (bit 0) for now (power, ...) */
506 /* port N changes (bit N)? */
507 spin_lock_irqsave (&ehci
->lock
, flags
);
508 for (i
= 0; i
< ports
; i
++) {
509 temp
= ehci_readl(ehci
, &ehci
->regs
->port_status
[i
]);
512 * Return status information even for ports with OWNER set.
513 * Otherwise khubd wouldn't see the disconnect event when a
514 * high-speed device is switched over to the companion
515 * controller by the user.
518 if ((temp
& mask
) != 0 || test_bit(i
, &ehci
->port_c_suspend
)
519 || (ehci
->reset_done
[i
] && time_after_eq(
520 jiffies
, ehci
->reset_done
[i
]))) {
522 buf
[0] |= 1 << (i
+ 1);
524 buf
[1] |= 1 << (i
- 7);
528 /* FIXME autosuspend idle root hubs */
529 spin_unlock_irqrestore (&ehci
->lock
, flags
);
530 return status
? retval
: 0;
533 /*-------------------------------------------------------------------------*/
536 ehci_hub_descriptor (
537 struct ehci_hcd
*ehci
,
538 struct usb_hub_descriptor
*desc
540 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
543 desc
->bDescriptorType
= 0x29;
544 desc
->bPwrOn2PwrGood
= 10; /* ehci 1.0, 2.3.9 says 20ms max */
545 desc
->bHubContrCurrent
= 0;
547 desc
->bNbrPorts
= ports
;
548 temp
= 1 + (ports
/ 8);
549 desc
->bDescLength
= 7 + 2 * temp
;
551 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
552 memset (&desc
->bitmap
[0], 0, temp
);
553 memset (&desc
->bitmap
[temp
], 0xff, temp
);
555 temp
= 0x0008; /* per-port overcurrent reporting */
556 if (HCS_PPC (ehci
->hcs_params
))
557 temp
|= 0x0001; /* per-port power control */
559 temp
|= 0x0002; /* no power switching */
561 // re-enable when we support USB_PORT_FEAT_INDICATOR below.
562 if (HCS_INDICATOR (ehci
->hcs_params
))
563 temp
|= 0x0080; /* per-port indicators (LEDs) */
565 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
568 /*-------------------------------------------------------------------------*/
570 static int ehci_hub_control (
578 struct ehci_hcd
*ehci
= hcd_to_ehci (hcd
);
579 int ports
= HCS_N_PORTS (ehci
->hcs_params
);
580 u32 __iomem
*status_reg
= &ehci
->regs
->port_status
[
581 (wIndex
& 0xff) - 1];
588 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
589 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
590 * (track current state ourselves) ... blink for diagnostics,
591 * power, "this is the one", etc. EHCI spec supports this.
594 spin_lock_irqsave (&ehci
->lock
, flags
);
596 case ClearHubFeature
:
598 case C_HUB_LOCAL_POWER
:
599 case C_HUB_OVER_CURRENT
:
600 /* no hub-wide feature/status flags */
606 case ClearPortFeature
:
607 if (!wIndex
|| wIndex
> ports
)
610 temp
= ehci_readl(ehci
, status_reg
);
613 * Even if OWNER is set, so the port is owned by the
614 * companion controller, khubd needs to be able to clear
615 * the port-change status bits (especially
616 * USB_PORT_FEAT_C_CONNECTION).
620 case USB_PORT_FEAT_ENABLE
:
621 ehci_writel(ehci
, temp
& ~PORT_PE
, status_reg
);
623 case USB_PORT_FEAT_C_ENABLE
:
624 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_PEC
,
627 case USB_PORT_FEAT_SUSPEND
:
628 if (temp
& PORT_RESET
)
630 if (ehci
->no_selective_suspend
)
632 if (temp
& PORT_SUSPEND
) {
633 if ((temp
& PORT_PE
) == 0)
635 /* resume signaling for 20 msec */
636 temp
&= ~(PORT_RWC_BITS
| PORT_WAKE_BITS
);
637 ehci_writel(ehci
, temp
| PORT_RESUME
,
639 ehci
->reset_done
[wIndex
] = jiffies
640 + msecs_to_jiffies (20);
643 case USB_PORT_FEAT_C_SUSPEND
:
644 clear_bit(wIndex
, &ehci
->port_c_suspend
);
646 case USB_PORT_FEAT_POWER
:
647 if (HCS_PPC (ehci
->hcs_params
))
649 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
652 case USB_PORT_FEAT_C_CONNECTION
:
653 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_CSC
,
656 case USB_PORT_FEAT_C_OVER_CURRENT
:
657 ehci_writel(ehci
, (temp
& ~PORT_RWC_BITS
) | PORT_OCC
,
660 case USB_PORT_FEAT_C_RESET
:
661 /* GetPortStatus clears reset */
666 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted write */
668 case GetHubDescriptor
:
669 ehci_hub_descriptor (ehci
, (struct usb_hub_descriptor
*)
673 /* no hub-wide feature/status flags */
675 //cpu_to_le32s ((u32 *) buf);
678 if (!wIndex
|| wIndex
> ports
)
682 temp
= ehci_readl(ehci
, status_reg
);
686 status
|= 1 << USB_PORT_FEAT_C_CONNECTION
;
688 status
|= 1 << USB_PORT_FEAT_C_ENABLE
;
690 if ((temp
& PORT_OCC
) && !ignore_oc
){
691 status
|= 1 << USB_PORT_FEAT_C_OVER_CURRENT
;
694 * Hubs should disable port power on over-current.
695 * However, not all EHCI implementations do this
696 * automatically, even if they _do_ support per-port
697 * power switching; they're allowed to just limit the
698 * current. khubd will turn the power back on.
700 if (HCS_PPC (ehci
->hcs_params
)){
702 temp
& ~(PORT_RWC_BITS
| PORT_POWER
),
707 /* whoever resumes must GetPortStatus to complete it!! */
708 if (temp
& PORT_RESUME
) {
710 /* Remote Wakeup received? */
711 if (!ehci
->reset_done
[wIndex
]) {
712 /* resume signaling for 20 msec */
713 ehci
->reset_done
[wIndex
] = jiffies
714 + msecs_to_jiffies(20);
715 /* check the port again */
716 mod_timer(&ehci_to_hcd(ehci
)->rh_timer
,
717 ehci
->reset_done
[wIndex
]);
720 /* resume completed? */
721 else if (time_after_eq(jiffies
,
722 ehci
->reset_done
[wIndex
])) {
723 clear_bit(wIndex
, &ehci
->suspended_ports
);
724 set_bit(wIndex
, &ehci
->port_c_suspend
);
725 ehci
->reset_done
[wIndex
] = 0;
727 /* stop resume signaling */
728 temp
= ehci_readl(ehci
, status_reg
);
730 temp
& ~(PORT_RWC_BITS
| PORT_RESUME
),
732 retval
= handshake(ehci
, status_reg
,
733 PORT_RESUME
, 0, 2000 /* 2msec */);
736 "port %d resume error %d\n",
740 temp
&= ~(PORT_SUSPEND
|PORT_RESUME
|(3<<10));
744 /* whoever resets must GetPortStatus to complete it!! */
745 if ((temp
& PORT_RESET
)
746 && time_after_eq(jiffies
,
747 ehci
->reset_done
[wIndex
])) {
748 status
|= 1 << USB_PORT_FEAT_C_RESET
;
749 ehci
->reset_done
[wIndex
] = 0;
751 /* force reset to complete */
752 ehci_writel(ehci
, temp
& ~(PORT_RWC_BITS
| PORT_RESET
),
754 /* REVISIT: some hardware needs 550+ usec to clear
755 * this bit; seems too long to spin routinely...
757 retval
= handshake(ehci
, status_reg
,
758 PORT_RESET
, 0, 1000);
760 ehci_err (ehci
, "port %d reset error %d\n",
765 /* see what we found out */
766 temp
= check_reset_complete (ehci
, wIndex
, status_reg
,
767 ehci_readl(ehci
, status_reg
));
770 if (!(temp
& (PORT_RESUME
|PORT_RESET
)))
771 ehci
->reset_done
[wIndex
] = 0;
773 /* transfer dedicated ports to the companion hc */
774 if ((temp
& PORT_CONNECT
) &&
775 test_bit(wIndex
, &ehci
->companion_ports
)) {
776 temp
&= ~PORT_RWC_BITS
;
778 ehci_writel(ehci
, temp
, status_reg
);
779 ehci_dbg(ehci
, "port %d --> companion\n", wIndex
+ 1);
780 temp
= ehci_readl(ehci
, status_reg
);
784 * Even if OWNER is set, there's no harm letting khubd
785 * see the wPortStatus values (they should all be 0 except
786 * for PORT_POWER anyway).
789 if (temp
& PORT_CONNECT
) {
790 status
|= 1 << USB_PORT_FEAT_CONNECTION
;
791 // status may be from integrated TT
792 status
|= ehci_port_speed(ehci
, temp
);
795 status
|= 1 << USB_PORT_FEAT_ENABLE
;
797 /* maybe the port was unsuspended without our knowledge */
798 if (temp
& (PORT_SUSPEND
|PORT_RESUME
)) {
799 status
|= 1 << USB_PORT_FEAT_SUSPEND
;
800 } else if (test_bit(wIndex
, &ehci
->suspended_ports
)) {
801 clear_bit(wIndex
, &ehci
->suspended_ports
);
802 ehci
->reset_done
[wIndex
] = 0;
804 set_bit(wIndex
, &ehci
->port_c_suspend
);
808 status
|= 1 << USB_PORT_FEAT_OVER_CURRENT
;
809 if (temp
& PORT_RESET
)
810 status
|= 1 << USB_PORT_FEAT_RESET
;
811 if (temp
& PORT_POWER
)
812 status
|= 1 << USB_PORT_FEAT_POWER
;
813 if (test_bit(wIndex
, &ehci
->port_c_suspend
))
814 status
|= 1 << USB_PORT_FEAT_C_SUSPEND
;
816 #ifndef VERBOSE_DEBUG
817 if (status
& ~0xffff) /* only if wPortChange is interesting */
819 dbg_port (ehci
, "GetStatus", wIndex
+ 1, temp
);
820 put_unaligned(cpu_to_le32 (status
), (__le32
*) buf
);
824 case C_HUB_LOCAL_POWER
:
825 case C_HUB_OVER_CURRENT
:
826 /* no hub-wide feature/status flags */
833 selector
= wIndex
>> 8;
835 if (!wIndex
|| wIndex
> ports
)
838 temp
= ehci_readl(ehci
, status_reg
);
839 if (temp
& PORT_OWNER
)
842 temp
&= ~PORT_RWC_BITS
;
844 case USB_PORT_FEAT_SUSPEND
:
845 if (ehci
->no_selective_suspend
)
847 if ((temp
& PORT_PE
) == 0
848 || (temp
& PORT_RESET
) != 0)
850 ehci_writel(ehci
, temp
| PORT_SUSPEND
, status_reg
);
851 set_bit(wIndex
, &ehci
->suspended_ports
);
853 case USB_PORT_FEAT_POWER
:
854 if (HCS_PPC (ehci
->hcs_params
))
855 ehci_writel(ehci
, temp
| PORT_POWER
,
858 case USB_PORT_FEAT_RESET
:
859 if (temp
& PORT_RESUME
)
861 /* line status bits may report this as low speed,
862 * which can be fine if this root hub has a
863 * transaction translator built in.
865 if ((temp
& (PORT_PE
|PORT_CONNECT
)) == PORT_CONNECT
866 && !ehci_is_TDI(ehci
)
867 && PORT_USB11 (temp
)) {
869 "port %d low speed --> companion\n",
873 ehci_vdbg (ehci
, "port %d reset\n", wIndex
+ 1);
878 * caller must wait, then call GetPortStatus
879 * usb 2.0 spec says 50 ms resets on root
881 ehci
->reset_done
[wIndex
] = jiffies
882 + msecs_to_jiffies (50);
884 ehci_writel(ehci
, temp
, status_reg
);
887 /* For downstream facing ports (these): one hub port is put
888 * into test mode according to USB2 11.24.2.13, then the hub
889 * must be reset (which for root hub now means rmmod+modprobe,
890 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
891 * about the EHCI-specific stuff.
893 case USB_PORT_FEAT_TEST
:
894 if (!selector
|| selector
> 5)
898 temp
|= selector
<< 16;
899 ehci_writel(ehci
, temp
, status_reg
);
905 ehci_readl(ehci
, &ehci
->regs
->command
); /* unblock posted writes */
910 /* "stall" on error */
913 spin_unlock_irqrestore (&ehci
->lock
, flags
);
917 static void ehci_relinquish_port(struct usb_hcd
*hcd
, int portnum
)
919 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
921 if (ehci_is_TDI(ehci
))
923 set_owner(ehci
, --portnum
, PORT_OWNER
);
926 static int ehci_port_handed_over(struct usb_hcd
*hcd
, int portnum
)
928 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
931 if (ehci_is_TDI(ehci
))
933 reg
= &ehci
->regs
->port_status
[portnum
- 1];
934 return ehci_readl(ehci
, reg
) & PORT_OWNER
;