All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 01/24] usb: add device connection/disconnection detection
@ 2015-05-04 17:30 Simon Glass
  2015-05-04 17:30 ` [U-Boot] [PATCH 02/24] dm: usb: Implement usb_detect_change() for driver model Simon Glass
                   ` (23 more replies)
  0 siblings, 24 replies; 76+ messages in thread
From: Simon Glass @ 2015-05-04 17:30 UTC (permalink / raw)
  To: u-boot

From: Vincent Palatin <vpalatin@chromium.org>

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>
---

 common/usb.c     | 26 ++++++++++++++++++++++++++
 common/usb_hub.c |  2 +-
 include/usb.h    |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/common/usb.c b/common/usb.c
index a4820d3..bde8f31 100644
--- a/common/usb.c
+++ b/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.
diff --git a/common/usb_hub.c b/common/usb_hub.c
index c9be530..bbed1c8 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -79,7 +79,7 @@ static int usb_get_hub_status(struct usb_device *dev, void *data)
 			data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
 }
 
-static int usb_get_port_status(struct usb_device *dev, int port, void *data)
+int usb_get_port_status(struct usb_device *dev, int port, void *data)
 {
 	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
 			USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port,
diff --git a/include/usb.h b/include/usb.h
index 1984e8f..25dddb8 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -265,6 +265,7 @@ int usb_kbd_deregister(int force);
 /* 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);
@@ -290,6 +291,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 */
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2015-05-12 22:41 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-04 17:30 [U-Boot] [PATCH 01/24] usb: add device connection/disconnection detection Simon Glass
2015-05-04 17:30 ` [U-Boot] [PATCH 02/24] dm: usb: Implement usb_detect_change() for driver model Simon Glass
2015-05-04 20:55   ` Joe Hershberger
2015-05-04 17:30 ` [U-Boot] [PATCH 03/24] bootstage: Add IDs for SPI flash reading and decompression Simon Glass
2015-05-04 20:57   ` Joe Hershberger
2015-05-08  5:58     ` Jagan Teki
2015-05-12 22:40       ` Simon Glass
2015-05-04 17:30 ` [U-Boot] [PATCH 04/24] dm: i2c: Implement 'i2c bus' command for driver model Simon Glass
2015-05-04 20:35   ` Joe Hershberger
2015-05-06  5:44   ` Heiko Schocher
2015-05-06 14:34     ` Simon Glass
2015-05-12 22:40       ` Simon Glass
2015-05-04 17:30 ` [U-Boot] [PATCH 05/24] dm: i2c: Add a function to find out the chip offset length Simon Glass
2015-05-04 20:43   ` Joe Hershberger
2015-05-06  5:37   ` Heiko Schocher
2015-05-12 22:40     ` Simon Glass
2015-05-04 17:30 ` [U-Boot] [PATCH 06/24] tpm: Support using driver model with I2C Simon Glass
2015-05-12 22:40   ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 07/24] tpm: Rename Infineon TPM to slb9645tt Simon Glass
2015-05-12 22:41   ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 08/24] dm: gpio: Fix comment typo in GPIOD_IS_IN Simon Glass
2015-05-12 22:41   ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 09/24] arm: Include the .got section in the binary Simon Glass
2015-05-12 22:41   ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 10/24] arm: Add a prototype for save_boot_params_ret() Simon Glass
2015-05-04 21:09   ` Joe Hershberger
2015-05-12 22:41     ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 11/24] arm: spl: Enable detecting when U-Boot is started from SPL Simon Glass
2015-05-04 20:39   ` Joe Hershberger
2015-05-04 17:31 ` [U-Boot] [PATCH 12/24] arm: Allow cleanup_before_linux() without disabling caches Simon Glass
2015-05-04 17:36   ` Marek Vasut
2015-05-04 17:49     ` Simon Glass
2015-05-04 18:02       ` Marek Vasut
2015-05-04 17:31 ` [U-Boot] [PATCH 13/24] sandbox: Add an implementation for cleanup_before_linux_select() Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 14/24] sandbox: Correct error handling in state_read_file() Simon Glass
2015-05-04 21:12   ` Joe Hershberger
2015-05-12 22:41     ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 15/24] sandbox: Add missing errno.h includes in a few files Simon Glass
2015-05-12 22:41   ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 16/24] sandbox: cros_ec: Support EC_CMD_ENTERING_MODE emulation Simon Glass
2015-05-12 22:41   ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 17/24] sandbox: spi: Add newline to printf() in sandbox_sf_probe Simon Glass
2015-05-04 21:06   ` Joe Hershberger
2015-05-08  5:58     ` Jagan Teki
2015-05-12 22:41       ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 18/24] sandbox: Fix warning in display_options Simon Glass
2015-05-04 21:45   ` Joe Hershberger
2015-05-12 22:41     ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 19/24] sandbox: Support wide-screen LCD emulation Simon Glass
2015-05-04 21:27   ` Joe Hershberger
2015-05-04 21:36     ` Simon Glass
2015-05-12 22:41       ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 20/24] lcd: Support colour lookup table on 16bpp display in BMP images Simon Glass
2015-05-04 21:42   ` Joe Hershberger
2015-05-04 17:31 ` [U-Boot] [PATCH 21/24] tegra124: Implement spl_was_boot_source() Simon Glass
2015-05-05 15:54   ` Stephen Warren
2015-05-05 16:02     ` Simon Glass
2015-05-05 16:10       ` Stephen Warren
2015-05-05 16:19         ` Simon Glass
2015-05-05 18:07           ` Stephen Warren
2015-05-06 19:04             ` Simon Glass
2015-05-04 17:31 ` [U-Boot] [PATCH 22/24] tegra: nyan-big: Allow TPM on I2C Simon Glass
2015-05-04 17:52   ` Stephen Warren
2015-05-04 17:31 ` [U-Boot] [PATCH 23/24] tegra: mmc: Set the removable flag correctly Simon Glass
2015-05-04 22:00   ` Joe Hershberger
2015-05-05  9:39   ` Pantelis Antoniou
2015-05-04 17:31 ` [U-Boot] [PATCH 24/24] tegra124: Expand SPL space by 8KB Simon Glass
2015-05-05 15:59   ` Stephen Warren
2015-05-05 16:03     ` Simon Glass
2015-05-05 16:12       ` Stephen Warren
2015-05-05 16:26         ` Simon Glass
2015-05-05 18:20           ` Stephen Warren
2015-05-06 19:04             ` Simon Glass
2015-05-05 16:03   ` Simon Glass
2015-05-05 16:13     ` Tom Warren
2015-05-12 22:40 ` [U-Boot] [PATCH 01/24] usb: add device connection/disconnection detection Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.