diff mbox

[U-Boot,v5,08/15] dm: usb: Add support for companion controllers

Message ID 1431259827-8109-9-git-send-email-hdegoede@redhat.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Hans de Goede May 10, 2015, 12:10 p.m. UTC
USB companion controllers must be scanned after the main controller has
been scanned, so that any devices which the main controller which to hand
over to the companion have actually been handed over before we scan the
companion.

As there are no guarantees that this will magically happen in the right
order, split the scanning of the buses in 2 phases, first main controllers,
and then companion controllers.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/usb/host/usb-uclass.c | 33 ++++++++++++++++++++++++++++-----
 include/usb.h                 |  3 +++
 2 files changed, 31 insertions(+), 5 deletions(-)

Comments

Simon Glass May 11, 2015, 10:33 p.m. UTC | #1
On 10 May 2015 at 06:10, Hans de Goede <hdegoede@redhat.com> wrote:
> USB companion controllers must be scanned after the main controller has
> been scanned, so that any devices which the main controller which to hand
> over to the companion have actually been handed over before we scan the
> companion.
>
> As there are no guarantees that this will magically happen in the right
> order, split the scanning of the buses in 2 phases, first main controllers,
> and then companion controllers.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/usb/host/usb-uclass.c | 33 ++++++++++++++++++++++++++++-----
>  include/usb.h                 |  3 +++
>  2 files changed, 31 insertions(+), 5 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass May 11, 2015, 10:37 p.m. UTC | #2
On 11 May 2015 at 16:33, Simon Glass <sjg@chromium.org> wrote:
> On 10 May 2015 at 06:10, Hans de Goede <hdegoede@redhat.com> wrote:
>> USB companion controllers must be scanned after the main controller has
>> been scanned, so that any devices which the main controller which to hand
>> over to the companion have actually been handed over before we scan the
>> companion.
>>
>> As there are no guarantees that this will magically happen in the right
>> order, split the scanning of the buses in 2 phases, first main controllers,
>> and then companion controllers.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/usb/host/usb-uclass.c | 33 ++++++++++++++++++++++++++++-----
>>  include/usb.h                 |  3 +++
>>  2 files changed, 31 insertions(+), 5 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox

Patch

diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index ad778b4..749257c 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -171,6 +171,7 @@  static void usb_scan_bus(struct udevice *bus, bool recurse)
 int usb_init(void)
 {
 	int controllers_initialized = 0;
+	struct usb_bus_priv *priv;
 	struct udevice *bus;
 	struct uclass *uc;
 	int count = 0;
@@ -198,15 +199,37 @@  int usb_init(void)
 			printf("probe failed, error %d\n", ret);
 			continue;
 		}
-		/*
-		 * lowlevel init is OK, now scan the bus for devices
-		 * i.e. search HUBs and configure them
-		 */
 		controllers_initialized++;
-		usb_scan_bus(bus, true);
 		usb_started = true;
 	}
 
+	/*
+	 * lowlevel init done, now scan the bus for devices i.e. search HUBs
+	 * and configure them, first scan primary controllers.
+	 */
+	uclass_foreach_dev(bus, uc) {
+		if (!device_active(bus))
+			continue;
+
+		priv = dev_get_uclass_priv(bus);
+		if (!priv->companion)
+			usb_scan_bus(bus, true);
+	}
+
+	/*
+	 * Now that the primary controllers have been scanned and have handed
+	 * over any devices they do not understand to their companions, scan
+	 * the companions.
+	 */
+	uclass_foreach_dev(bus, uc) {
+		if (!device_active(bus))
+			continue;
+
+		priv = dev_get_uclass_priv(bus);
+		if (priv->companion)
+			usb_scan_bus(bus, true);
+	}
+
 	debug("scan end\n");
 	/* if we were not able to find at least one working bus, bail out */
 	if (!count)
diff --git a/include/usb.h b/include/usb.h
index 609b13d..5043bc3 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -608,10 +608,13 @@  struct usb_dev_platdata {
  * @desc_before_addr:	true if we can read a device descriptor before it
  *		has been assigned an address. For XHCI this is not possible
  *		so this will be false.
+ * @companion:  True if this is a companion controller to another USB
+ *		controller
  */
 struct usb_bus_priv {
 	int next_addr;
 	bool desc_before_addr;
+	bool companion;
 };
 
 /**