dm: usb: move bus initialization into new static function usb_init_bus()

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.forissier@linaro.org>
This commit is contained in:
Jerome Forissier
2025-04-18 16:09:40 +02:00
committed by Tom Rini
parent dbb22f541a
commit 4634346e3e

View File

@@ -287,6 +287,45 @@ static int usb_probe_companion(struct udevice *bus)
return 0; 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 usb_init(void)
{ {
int controllers_initialized = 0; int controllers_initialized = 0;
@@ -305,47 +344,11 @@ int usb_init(void)
uc_priv = uclass_get_priv(uc); uc_priv = uclass_get_priv(uc);
uclass_foreach_dev(bus, uc) { uclass_foreach_dev(bus, uc) {
/* init low_level USB */ usb_init_bus(bus);
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_started = true;
/* /*
* lowlevel init done, now scan the bus for devices i.e. search HUBs * lowlevel init done, now scan the bus for devices i.e. search HUBs
* and configure them, first scan primary controllers. * and configure them, first scan primary controllers.
@@ -354,6 +357,8 @@ int usb_init(void)
if (!device_active(bus)) if (!device_active(bus))
continue; continue;
controllers_initialized++;
priv = dev_get_uclass_priv(bus); priv = dev_get_uclass_priv(bus);
if (!priv->companion) if (!priv->companion)
usb_scan_bus(bus, true); usb_scan_bus(bus, true);