mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-07-23 23:33:01 +00:00
usb: add device connection/disconnection detection
Provide a function to detect USB device insertion/removal in order to avoid having to do USB enumeration in a tight loop when trying to detect peripheral hotplugging. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Tested-by: Stefan Reinauer <reinauer@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
6a72e804a2
commit
08f3bb0bcd
3 changed files with 29 additions and 1 deletions
26
common/usb.c
26
common/usb.c
|
@ -148,6 +148,32 @@ int usb_stop(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Detect if a USB device has been plugged or unplugged.
|
||||
*/
|
||||
int usb_detect_change(void)
|
||||
{
|
||||
int i, j;
|
||||
int change = 0;
|
||||
|
||||
for (j = 0; j < USB_MAX_DEVICE; j++) {
|
||||
for (i = 0; i < usb_dev[j].maxchild; i++) {
|
||||
struct usb_port_status status;
|
||||
|
||||
if (usb_get_port_status(&usb_dev[j], i + 1,
|
||||
&status) < 0)
|
||||
/* USB request failed */
|
||||
continue;
|
||||
|
||||
if (le16_to_cpu(status.wPortChange) &
|
||||
USB_PORT_STAT_C_CONNECTION)
|
||||
change++;
|
||||
}
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
/*
|
||||
* disables the asynch behaviour of the control message. This is used for data
|
||||
* transfers that uses the exclusiv access to the control and bulk messages.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue