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 safe here.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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?