[vim3] Fix usb 2.0 flaky enumeration

Fixed: 99845
Test: /boot/test/device-enumeration-test
Change-Id: I8d7f5f69af2df4083f592fb7057749ebe0de0380
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/692797
Reviewed-by: Braden Kell <bradenkell@google.com>
Reviewed-by: Sam Hansen <hansens@google.com>
Reviewed-by: Ruby Zhuang <rdzhuang@google.com>
Commit-Queue: Puneetha Ramachandra <puneetha@google.com>
diff --git a/src/devices/board/drivers/vim3/vim3-usb.cc b/src/devices/board/drivers/vim3/vim3-usb.cc
index 8d1d3f5..437d4fd 100644
--- a/src/devices/board/drivers/vim3/vim3-usb.cc
+++ b/src/devices/board/drivers/vim3/vim3-usb.cc
@@ -161,6 +161,19 @@
   return dev;
 }();
 
+static const zx_bind_inst_t xhci_phy_match[] = {
+    BI_ABORT_IF(NE, BIND_PROTOCOL, ZX_PROTOCOL_USB_PHY),
+    BI_ABORT_IF(NE, BIND_PLATFORM_DEV_VID, PDEV_VID_GENERIC),
+    BI_ABORT_IF(NE, BIND_PLATFORM_DEV_PID, PDEV_PID_GENERIC),
+    BI_MATCH_IF(EQ, BIND_PLATFORM_DEV_DID, PDEV_DID_USB_XHCI_COMPOSITE),
+};
+static const device_fragment_part_t xhci_phy_fragment[] = {
+    {std::size(xhci_phy_match), xhci_phy_match},
+};
+static const device_fragment_t xhci_fragments[] = {
+    {"xhci-phy", std::size(xhci_phy_fragment), xhci_phy_fragment},
+};
+
 using FunctionDescriptor = fuchsia_hardware_usb_peripheral_FunctionDescriptor;
 
 static pbus_metadata_t usb_metadata[] = {
@@ -238,9 +251,8 @@
     return status;
   }
 
-  // Power on USB and wait for 30 ms (sleep duration derived from trial and error).
+  // Power on USB.
   gpio_impl_.ConfigOut(VIM3_USB_PWR, 1);
-  zx::nanosleep(zx::deadline_after(zx::msec(30)));
 
   // Create USB Phy Device
   status = pbus_.CompositeDeviceAdd(&usb_phy_dev, reinterpret_cast<uint64_t>(usb_phy_fragments),
@@ -280,9 +292,10 @@
   }
 
   // Create XHCI device.
-  status = pbus_.DeviceAdd(&xhci_dev);
+  status = pbus_.CompositeDeviceAdd(&xhci_dev, reinterpret_cast<uint64_t>(xhci_fragments),
+                                    std::size(xhci_fragments), "xhci-phy");
   if (status != ZX_OK) {
-    zxlogf(ERROR, "%s: DeviceAdd(xhci) failed %d", __func__, status);
+    zxlogf(ERROR, "%s: CompositeDeviceAdd(xhci) failed %d", __func__, status);
     return status;
   }
 
diff --git a/src/devices/usb/drivers/vim3-usb-phy/vim3-usb-phy.cc b/src/devices/usb/drivers/vim3-usb-phy/vim3-usb-phy.cc
index 4a992692..d45351f 100644
--- a/src/devices/usb/drivers/vim3-usb-phy/vim3-usb-phy.cc
+++ b/src/devices/usb/drivers/vim3-usb-phy/vim3-usb-phy.cc
@@ -215,13 +215,8 @@
     PLL_REGISTER::Get(0x34).FromValue(pll_settings_[5]).WriteTo(phy_mmio);
   }
 
-  if (mode == UsbMode::HOST) {
-    AddXhciDevice();
-    RemoveDwc2Device(std::move(completion));
-  } else {
-    AddDwc2Device();
-    RemoveXhciDevice(std::move(completion));
-  }
+  AddXhciDevice();
+  AddDwc2Device();
 }
 
 int Vim3UsbPhy::IrqThread() {