Merge branch 'master' of git://git.denx.de/u-boot-socfpga
diff --git a/common/usb.c b/common/usb.c
index 9f67cc1..c7b8b0e 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -456,7 +456,7 @@
 			}
 			epno = dev->config.if_desc[ifno].no_of_ep;
 			if_desc = &dev->config.if_desc[ifno];
-			if (epno > USB_MAXENDPOINTS) {
+			if (epno >= USB_MAXENDPOINTS) {
 				printf("Interface %d has too many endpoints!\n",
 					if_desc->desc.bInterfaceNumber);
 				return -EINVAL;
diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index 1ba5054..d36bcf6 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -1018,18 +1018,10 @@
 		return ret;
 
 	ret = ci_udc_probe();
-#if defined(CONFIG_USB_EHCI_MX6) || defined(CONFIG_USB_EHCI_MXS)
-	/*
-	 * FIXME: usb_lowlevel_init()->ehci_hcd_init() should be doing all
-	 * HW-specific initialization, e.g. ULPI-vs-UTMI PHY selection
-	 */
-	if (!ret) {
-		struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
-
-		/* select ULPI phy */
-		writel(PTS(PTS_ENABLE) | PFSC, &udc->portsc);
+	if (ret) {
+		DBG("udc probe failed, returned %d\n", ret);
+		return ret;
 	}
-#endif
 
 	ret = driver->bind(&controller.gadget);
 	if (ret) {
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 98e0fc6..335e303 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -121,6 +121,11 @@
 	setbits_le32(ctrl, UCTRL_OVER_CUR_DIS);
 }
 
+int __weak board_usb_phy_mode(int port)
+{
+	return 0;
+}
+
 int __weak board_ehci_hcd_init(int port)
 {
 	return 0;
@@ -130,15 +135,11 @@
 		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
 	struct usb_ehci *ehci;
+	enum usb_init_type type;
 
 	if (index >= ARRAY_SIZE(nc_reg_bases))
 		return -EINVAL;
 
-	if (init == USB_INIT_DEVICE && index == 1)
-		return -ENODEV;
-	if (init == USB_INIT_HOST && index == 0)
-		return -ENODEV;
-
 	ehci = (struct usb_ehci *)nc_reg_bases[index];
 
 	/* Do board specific initialisation */
@@ -153,6 +154,10 @@
 	*hcor = (struct ehci_hcor *)((uint32_t)*hccr +
 			HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
 
+	type = board_usb_phy_mode(index);
+	if (type != init)
+		return -ENODEV;
+
 	if (init == USB_INIT_DEVICE) {
 		setbits_le32(&ehci->usbmode, CM_DEVICE);
 		writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);