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:

committed by
Tom Rini

parent
dbb22f541a
commit
4634346e3e
@@ -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,46 +344,10 @@ 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;
|
||||
}
|
||||
usb_init_bus(bus);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* lowlevel init done, now scan the bus for devices i.e. search HUBs
|
||||
@@ -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);
|
||||
|
Reference in New Issue
Block a user