diff options
author | Nico Huber <nico.huber@secunet.com> | 2012-05-21 14:53:43 +0200 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2012-06-08 00:01:25 +0200 |
commit | 0421dc84dfba3b4eaa045b595320d6468b3206ef (patch) | |
tree | fad8e07e2a023cc9aacf3a1bd81a25191b26e282 /payloads/libpayload/drivers/usb/ehci_rh.c | |
parent | afe86c0b74cc7f5dcaefc34155daf299e8377353 (diff) | |
download | coreboot-0421dc84dfba3b4eaa045b595320d6468b3206ef.tar.xz |
libpayload: Add timeouts in the EHCI USB driver
We should always have some timeout when we wait for the hardware. This adds
missing timeouts to the EHCI driver.
Change-Id: I13ba532a6daf47510b16b8fdbe572a21f1d8b09c
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: http://review.coreboot.org/1077
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'payloads/libpayload/drivers/usb/ehci_rh.c')
-rw-r--r-- | payloads/libpayload/drivers/usb/ehci_rh.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/payloads/libpayload/drivers/usb/ehci_rh.c b/payloads/libpayload/drivers/usb/ehci_rh.c index d84069e613..5f92bd7894 100644 --- a/payloads/libpayload/drivers/usb/ehci_rh.c +++ b/payloads/libpayload/drivers/usb/ehci_rh.c @@ -55,9 +55,21 @@ ehci_rh_hand_over_port (usbdev_t *dev, int port) { debug("giving up port %x, it's USB1\n", port+1); + /* Clear ConnectStatusChange before evaluation */ + /* RW/C register, so clear it by writing 1 */ + RH_INST(dev)->ports[port] |= P_CONN_STATUS_CHANGE; + /* Lowspeed device. Hand over to companion */ RH_INST(dev)->ports[port] |= P_PORT_OWNER; - do {} while (!(RH_INST(dev)->ports[port] & P_CONN_STATUS_CHANGE)); + + /* TOTEST: how long to wait? trying 100ms for now */ + int timeout = 10; /* timeout after 10 * 10ms == 100ms */ + while (!(RH_INST(dev)->ports[port] & P_CONN_STATUS_CHANGE) && timeout--) + mdelay(10); + if (!(RH_INST(dev)->ports[port] & P_CONN_STATUS_CHANGE)) { + debug("Warning: Handing port over to companion timed out.\n"); + } + /* RW/C register, so clear it by writing 1 */ RH_INST(dev)->ports[port] |= P_CONN_STATUS_CHANGE; return; @@ -73,7 +85,7 @@ ehci_rh_scanport (usbdev_t *dev, int port) } /* device connected, handle */ if (RH_INST(dev)->ports[port] & P_CURR_CONN_STATUS) { - mdelay(100); + mdelay(100); // usb20 spec 9.1.2 if ((RH_INST(dev)->ports[port] & P_LINE_STATUS) == P_LINE_STATUS_LOWSPEED) { ehci_rh_hand_over_port(dev, port); return; @@ -85,13 +97,23 @@ ehci_rh_scanport (usbdev_t *dev, int port) RH_INST(dev)->ports[port] = (RH_INST(dev)->ports[port] & ~P_PORT_ENABLE) | P_PORT_RESET; /* Wait a bit while reset is active. */ - mdelay(50); + mdelay(50); // usb20 spec 7.1.7.5 (TDRSTR) /* Deassert reset. */ RH_INST(dev)->ports[port] &= ~P_PORT_RESET; - /* Wait for flag change to finish. The controller might take a while */ - while (RH_INST(dev)->ports[port] & P_PORT_RESET) ; + /* Wait max. 2ms (ehci spec 2.3.9) for flag change to finish. */ + int timeout = 20; /* time out after 20 * 100us == 2ms */ + while ((RH_INST(dev)->ports[port] & P_PORT_RESET) && timeout--) + udelay(100); + if (RH_INST(dev)->ports[port] & P_PORT_RESET) { + printf("Error: ehci_rh: port reset timed out.\n"); + return; + } + + /* If the host controller enabled the port, it's a high-speed + * device, otherwise it's full-speed. + */ if (!(RH_INST(dev)->ports[port] & P_PORT_ENABLE)) { ehci_rh_hand_over_port(dev, port); return; |