According to the USB2 specification, a device may take up to 100ms (USB_TIME_SIGATT) after port power stabilizes to be detected. So, continually recheck for a device connection event.
Technically, the uhci root hub ports are always powered up, but it's not possible to know how long the machine has been on, so it's better to be safer here.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/usb-uhci.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index 9d7ef6a..406af90 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -44,10 +44,17 @@ uhci_hub_detect(struct usbhub_s *hub, u32 port) struct usb_uhci_s *cntl = container_of(hub->cntl, struct usb_uhci_s, usb); u16 ioport = cntl->iobase + USBPORTSC1 + port * 2;
- u16 status = inw(ioport); - if (!(status & USBPORTSC_CCS)) - // No device - return -1; + u32 end = timer_calc(USB_TIME_SIGATT); + for (;;) { + u16 status = inw(ioport); + if (status & USBPORTSC_CCS) + // Device connected. + break; + if (timer_check(end)) + // No device found. + return -1; + msleep(5); + }
// XXX - if just powered up, need to wait for USB_TIME_ATTDB?