diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2011-12-08 19:58:11 +0000 |
---|---|---|
committer | Stefan Reinauer <reinauer@chromium.org> | 2011-12-20 16:52:09 -0800 |
commit | c64225be59d7f12f38bf9b6a721a4ce82ecdfd19 (patch) | |
tree | c655c61182275350657657f96503eb850c8e3af7 | |
parent | e039e5b9a50b26e1a8edf5bbdd2c7ebf87b107ec (diff) |
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>
BUG=chrome-os-partner:5752 chrome-os-partner:6344
TEST=on Lumpy, insert and remove a USB key in recovery mode.
Change-Id: I18dc97d54cd909acea754fd9b3a4b7f4fc3219ec
Reviewed-on: https://gerrit.chromium.org/gerrit/13249
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
Tested-by: Stefan Reinauer <reinauer@chromium.org>
-rw-r--r-- | common/usb.c | 26 | ||||
-rw-r--r-- | include/usb.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/common/usb.c b/common/usb.c index 47a1118448..4fc3925dec 100644 --- a/common/usb.c +++ b/common/usb.c @@ -169,6 +169,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. diff --git a/include/usb.h b/include/usb.h index 71341780fd..6fd14fcf0e 100644 --- a/include/usb.h +++ b/include/usb.h @@ -201,6 +201,7 @@ int usb_kbd_deregister(void); /* routines */ int usb_init(void); /* initialize the USB Controller */ int usb_stop(void); /* stop the USB Controller */ +int usb_detect_change(void); /* detect if a USB device has been (un)plugged */ int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol); @@ -228,6 +229,7 @@ int usb_get_class_descriptor(struct usb_device *dev, int ifnum, int usb_clear_halt(struct usb_device *dev, int pipe); int usb_string(struct usb_device *dev, int index, char *buf, size_t size); int usb_set_interface(struct usb_device *dev, int interface, int alternate); +int usb_get_port_status(struct usb_device *dev, int port, void *data); /* big endian -> little endian conversion */ /* some CPUs are already little endian e.g. the ARM920T */ |