libpayload: usb: Allow direct instantiation of MMIO host controllers

The existing USB_MEMORY mechanism to instantiate non-PCI host
controllers is clunky and inflexible... most importantly, it doesn't
allow multiple host controllers of the same kind. This patch replaces it
with a function that allows payloads to directly instantiate as many
host controllers of whatever type they need.

Change-Id: Ic21d2016a4ef92c67fa420bdc0f0d8a6508b69e5
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/169454
Reviewed-by: Stefan Reinauer <reinauer@google.com>
(cherry picked from commit b6e95c39dd91f654f0a345f17b3196f56adf4891)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6644
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
diff --git a/payloads/libpayload/drivers/usb/usbinit.c b/payloads/libpayload/drivers/usb/usbinit.c
index 90c31d7..1710760 100644
--- a/payloads/libpayload/drivers/usb/usbinit.c
+++ b/payloads/libpayload/drivers/usb/usbinit.c
@@ -156,21 +156,6 @@
 }
 #endif
 
-#ifdef CONFIG_LP_USB_MEMORY
-static void usb_scan_memory(void)
-{
-#ifdef CONFIG_LP_USB_XHCI
-	xhci_init(CONFIG_LP_USB_XHCI_BASE_ADDRESS);
-#endif
-#ifdef CONFIG_LP_USB_EHCI
-	ehci_init(CONFIG_LP_USB_EHCI_BASE_ADDRESS);
-#endif
-#ifdef CONFIG_LP_USB_OHCI
-	ohci_init(CONFIG_LP_USB_OHCI_BASE_ADDRESS);
-#endif
-}
-#endif
-
 /**
  * Initialize all USB controllers attached to PCI.
  */
@@ -179,8 +164,26 @@
 #ifdef CONFIG_LP_USB_PCI
 	usb_scan_pci_bus(0);
 #endif
-#ifdef CONFIG_LP_USB_MEMORY
-	usb_scan_memory();
-#endif
 	return 0;
 }
+
+hci_t *usb_add_mmio_hc(hc_type type, void *bar)
+{
+	switch (type) {
+#ifdef CONFIG_LP_USB_OHCI
+	case OHCI:
+		return ohci_init(bar);
+#endif
+#ifdef CONFIG_LP_USB_EHCI
+	case EHCI:
+		return ehci_init(bar);
+#endif
+#ifdef CONFIG_LP_USB_XHCI
+	case XHCI:
+		return xhci_init(bar);
+#endif
+	default:
+		usb_debug("HC type %d (at %p) is not supported!\n", type, bar);
+		return NULL;
+	}
+}