To prepare for the introduction of threads in the USB initialization
sequence, move code out of usb_init() into a new helper function:
usb_init_bus() and count the number of USB controllers initialized
successfully by using the DM device_active() function.

Signed-off-by: Jerome Forissier <jerome.foriss...@linaro.org>
---

(no changes since v1)

 drivers/usb/host/usb-uclass.c | 83 +++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 39 deletions(-)

diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index bfec303e7af..fa1af8f555a 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -287,6 +287,45 @@ static int usb_probe_companion(struct udevice *bus)
        return 0;
 }
 
+static void usb_init_bus(struct udevice *bus)
+{
+       int ret;
+
+       /* init low_level USB */
+       printf("Bus %s: ", bus->name);
+
+       /*
+        * For Sandbox, we need scan the device tree each time when we
+        * start the USB stack, in order to re-create the emulated USB
+        * devices and bind drivers for them before we actually do the
+        * driver probe.
+        *
+        * For USB onboard HUB, we need to do some non-trivial init
+        * like enabling a power regulator, before enumeration.
+        */
+       if (IS_ENABLED(CONFIG_SANDBOX) ||
+           IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) {
+               ret = dm_scan_fdt_dev(bus);
+               if (ret) {
+                       printf("USB device scan from fdt failed (%d)", ret);
+                       return;
+               }
+       }
+
+       ret = device_probe(bus);
+       if (ret == -ENODEV) {   /* No such device. */
+               puts("Port not available.\n");
+               return;
+       }
+
+       if (ret) {              /* Other error. */
+               printf("probe failed, error %d\n", ret);
+               return;
+       }
+
+       usb_probe_companion(bus);
+}
+
 int usb_init(void)
 {
        int controllers_initialized = 0;
@@ -305,47 +344,11 @@ int usb_init(void)
        uc_priv = uclass_get_priv(uc);
 
        uclass_foreach_dev(bus, uc) {
-               /* init low_level USB */
-               printf("Bus %s: ", bus->name);
-
-               /*
-                * For Sandbox, we need scan the device tree each time when we
-                * start the USB stack, in order to re-create the emulated USB
-                * devices and bind drivers for them before we actually do the
-                * driver probe.
-                *
-                * For USB onboard HUB, we need to do some non-trivial init
-                * like enabling a power regulator, before enumeration.
-                */
-               if (IS_ENABLED(CONFIG_SANDBOX) ||
-                   IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) {
-                       ret = dm_scan_fdt_dev(bus);
-                       if (ret) {
-                               printf("USB device scan from fdt failed (%d)", 
ret);
-                               continue;
-                       }
-               }
-
-               ret = device_probe(bus);
-               if (ret == -ENODEV) {   /* No such device. */
-                       puts("Port not available.\n");
-                       controllers_initialized++;
-                       continue;
-               }
-
-               if (ret) {              /* Other error. */
-                       printf("probe failed, error %d\n", ret);
-                       continue;
-               }
-
-               ret = usb_probe_companion(bus);
-               if (ret)
-                       continue;
-
-               controllers_initialized++;
-               usb_started = true;
+               usb_init_bus(bus);
        }
 
+       usb_started = true;
+
        /*
         * lowlevel init done, now scan the bus for devices i.e. search HUBs
         * and configure them, first scan primary controllers.
@@ -354,6 +357,8 @@ int usb_init(void)
                if (!device_active(bus))
                        continue;
 
+               controllers_initialized++;
+
                priv = dev_get_uclass_priv(bus);
                if (!priv->companion)
                        usb_scan_bus(bus, true);
-- 
2.43.0

Reply via email to