Merge https://gitlab.denx.de/u-boot/custodians/u-boot-usb

- OMAP EHCI updates
diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
index f970bba..2b51b5e 100644
--- a/arch/arm/include/asm/ehci-omap.h
+++ b/arch/arm/include/asm/ehci-omap.h
@@ -123,17 +123,4 @@
 	u32 insreg08;		/* 0xb0 */
 };
 
-#if !CONFIG_IS_ENABLED(DM_USB) || !CONFIG_IS_ENABLED(OF_CONTROL)
-/*
- * FIXME: forward declaration of this structs needed because omap got the
- * ehci implementation backwards. move out ehci_hcd_x from board files
- */
-struct ehci_hccr;
-struct ehci_hcor;
-
-int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
-		       struct ehci_hccr **hccr, struct ehci_hcor **hcor);
-int omap_ehci_hcd_stop(void);
-#endif
-
 #endif /* _OMAP_COMMON_EHCI_H_ */
diff --git a/configs/am3517_evm_defconfig b/configs/am3517_evm_defconfig
index a38dd4b..e287e8e 100644
--- a/configs/am3517_evm_defconfig
+++ b/configs/am3517_evm_defconfig
@@ -84,8 +84,6 @@
 CONFIG_OMAP3_SPI=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
-CONFIG_HAS_OMAP_EHCI_PHY1_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY1_RESET_GPIO=57
 CONFIG_USB_MUSB_HOST=y
 CONFIG_USB_MUSB_AM35X=y
 CONFIG_BCH=y
diff --git a/configs/omap35_logic_somlv_defconfig b/configs/omap35_logic_somlv_defconfig
index 3937299..846b30a 100644
--- a/configs/omap35_logic_somlv_defconfig
+++ b/configs/omap35_logic_somlv_defconfig
@@ -90,8 +90,6 @@
 CONFIG_USB=y
 # CONFIG_SPL_DM_USB is not set
 CONFIG_USB_EHCI_HCD=y
-CONFIG_HAS_OMAP_EHCI_PHY1_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY1_RESET_GPIO=4
 CONFIG_USB_MUSB_HOST=y
 CONFIG_USB_MUSB_OMAP2PLUS=y
 CONFIG_TWL4030_USB=y
diff --git a/configs/omap3_beagle_defconfig b/configs/omap3_beagle_defconfig
index 80e2cc6..206118e 100644
--- a/configs/omap3_beagle_defconfig
+++ b/configs/omap3_beagle_defconfig
@@ -89,8 +89,6 @@
 CONFIG_USB=y
 # CONFIG_SPL_DM_USB is not set
 CONFIG_USB_EHCI_HCD=y
-CONFIG_HAS_OMAP_EHCI_PHY1_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY1_RESET_GPIO=147
 CONFIG_USB_OMAP3=y
 CONFIG_USB_MUSB_GADGET=y
 CONFIG_USB_MUSB_OMAP2PLUS=y
diff --git a/configs/omap3_logic_somlv_defconfig b/configs/omap3_logic_somlv_defconfig
index e5c94f0..ecb3d47 100644
--- a/configs/omap3_logic_somlv_defconfig
+++ b/configs/omap3_logic_somlv_defconfig
@@ -91,8 +91,6 @@
 CONFIG_USB=y
 # CONFIG_SPL_DM_USB is not set
 CONFIG_USB_EHCI_HCD=y
-CONFIG_HAS_OMAP_EHCI_PHY1_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY1_RESET_GPIO=4
 CONFIG_USB_MUSB_HOST=y
 CONFIG_USB_MUSB_OMAP2PLUS=y
 CONFIG_TWL4030_USB=y
diff --git a/configs/omap4_panda_defconfig b/configs/omap4_panda_defconfig
index 13df606..03e1a6b 100644
--- a/configs/omap4_panda_defconfig
+++ b/configs/omap4_panda_defconfig
@@ -42,10 +42,6 @@
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
-CONFIG_HAS_OMAP_EHCI_PHY1_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY1_RESET_GPIO=1
-CONFIG_HAS_OMAP_EHCI_PHY2_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY2_RESET_GPIO=62
 CONFIG_USB_OMAP3=y
 CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_SMSC95XX=y
diff --git a/configs/omap5_uevm_defconfig b/configs/omap5_uevm_defconfig
index 52f3784..4c66a4c 100644
--- a/configs/omap5_uevm_defconfig
+++ b/configs/omap5_uevm_defconfig
@@ -52,10 +52,6 @@
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
-CONFIG_HAS_OMAP_EHCI_PHY2_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY2_RESET_GPIO=80
-CONFIG_HAS_OMAP_EHCI_PHY3_RESET_GPIO=y
-CONFIG_OMAP_EHCI_PHY3_RESET_GPIO=79
 CONFIG_USB_DWC3=y
 CONFIG_USB_DWC3_OMAP=y
 CONFIG_USB_DWC3_PHY_OMAP=y
diff --git a/drivers/phy/nop-phy.c b/drivers/phy/nop-phy.c
index b08eedd..e2ee6e9 100644
--- a/drivers/phy/nop-phy.c
+++ b/drivers/phy/nop-phy.c
@@ -28,7 +28,7 @@
 	if (!dm_gpio_is_valid(&priv->reset_gpio))
 		return 0;
 
-	return dm_gpio_set_value(&priv->reset_gpio, false);
+	return dm_gpio_set_value(&priv->reset_gpio, true);
 }
 #endif
 
@@ -44,7 +44,8 @@
 	}
 
 #if CONFIG_IS_ENABLED(DM_GPIO)
-	ret = nop_phy_reset(phy);
+	/* Take phy out of reset */
+	ret = dm_gpio_set_value(&priv->reset_gpio, false);
 	if (ret) {
 		if (CONFIG_IS_ENABLED(CLK))
 			clk_disable_bulk(&priv->bulk);
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 7743c96..8f77412 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -191,45 +191,13 @@
 config USB_EHCI_OMAP
 	bool "Support for OMAP3+ on-chip EHCI USB controller"
 	depends on ARCH_OMAP2PLUS
+	select PHY
+	imply NOP_PHY
 	default y
 	---help---
 	  Enables support for the on-chip EHCI controller on OMAP3 and later
 	  SoCs.
 
-if USB_EHCI_OMAP
-
-config HAS_OMAP_EHCI_PHY1_RESET_GPIO
-	bool "PHY #1 requires a GPIO hold to it in RESET while PHY settles"
-	help
-	  Enable this to be able to configure the GPIO number used to hold the
-	  PHY in RESET for enough time until the PHY is settled and ready.
-
-config OMAP_EHCI_PHY1_RESET_GPIO
-	int "GPIO number to hold PHY #1 in RESET"
-	depends on HAS_OMAP_EHCI_PHY1_RESET_GPIO
-
-config HAS_OMAP_EHCI_PHY2_RESET_GPIO
-	bool "PHY #2 requires a GPIO hold to it in RESET while PHY settles"
-	help
-	  Enable this to be able to configure the GPIO number used to hold the
-	  PHY in RESET for enough time until the PHY is settled and ready.
-
-config OMAP_EHCI_PHY2_RESET_GPIO
-	int "GPIO number to hold PHY #2 in RESET"
-	depends on HAS_OMAP_EHCI_PHY2_RESET_GPIO
-
-config HAS_OMAP_EHCI_PHY3_RESET_GPIO
-	bool "PHY #3 requires a GPIO hold to it in RESET while PHY settles"
-	help
-	  Enable this to be able to configure the GPIO number used to hold the
-	  PHY in RESET for enough time until the PHY is settled and ready.
-
-config OMAP_EHCI_PHY3_RESET_GPIO
-	int "GPIO number to hold PHY #3 in RESET"
-	depends on HAS_OMAP_EHCI_PHY3_RESET_GPIO
-
-endif
-
 config USB_EHCI_VF
 	bool "Support for Vybrid on-chip EHCI USB controller"
 	depends on ARCH_VF610
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index d5facf1..765336a 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -128,62 +128,25 @@
 }
 #endif
 
-#if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
-	defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
-	defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
-/* controls PHY(s) reset signal(s) */
-static inline void omap_ehci_phy_reset(int on, int delay)
-{
-	/*
-	 * Refer ISSUE1:
-	 * Hold the PHY in RESET for enough time till
-	 * PHY is settled and ready
-	 */
-	if (delay && !on)
-		udelay(delay);
-#ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
-	gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
-	gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
-#endif
-#ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
-	gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
-	gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
-#endif
-#ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
-	gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
-	gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
-#endif
-
-	/* Hold the PHY in RESET for enough time till DIR is high */
-	/* Refer: ISSUE1 */
-	if (delay && on)
-		udelay(delay);
-}
-#else
-#define omap_ehci_phy_reset(on, delay)	do {} while (0)
+struct ehci_omap_priv_data {
+	struct ehci_ctrl ctrl;
+	struct omap_ehci *ehci;
+#ifdef CONFIG_DM_REGULATOR
+	struct udevice *vbus_supply;
 #endif
-
-/* Reset is needed otherwise the kernel-driver will throw an error. */
-int omap_ehci_hcd_stop(void)
-{
-	debug("Resetting OMAP EHCI\n");
-	omap_ehci_phy_reset(1, 0);
-
-	if (omap_uhh_reset() < 0)
-		return -1;
-
-	if (omap_ehci_tll_reset() < 0)
-		return -1;
-
-	return 0;
-}
+	enum usb_init_type init_type;
+	int portnr;
+	struct phy phy[OMAP_HS_USB_PORTS];
+	int nports;
+};
 
 /*
  * Initialize the OMAP EHCI controller and PHY.
  * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
  * See there for additional Copyrights.
  */
-int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata)
+static int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
+			      struct udevice *dev)
 {
 	int ret;
 	unsigned int i, reg = 0, rev = 0;
@@ -194,8 +157,9 @@
 	if (ret < 0)
 		return ret;
 
-	/* Put the PHY in RESET */
-	omap_ehci_phy_reset(1, 10);
+	/* Hold the PHY in RESET for enough time till DIR is high */
+	/* Refer: ISSUE1 */
+	udelay(10);
 
 	ret = omap_uhh_reset();
 	if (ret < 0)
@@ -274,7 +238,12 @@
 		if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
 			omap_usbhs_hsic_init(i);
 
-	omap_ehci_phy_reset(0, 10);
+	/*
+	 * Refer ISSUE1:
+	 * Hold the PHY in RESET for enough time till
+	 * PHY is settled and ready
+	 */
+	udelay(10);
 
 	/*
 	 * An undocumented "feature" in the OMAP3 EHCI controller,
@@ -327,7 +296,7 @@
 			omap_usbhs_set_mode(i, mode);
 	}
 
-	return omap_ehci_hcd_init(0, &usbhs_bdata);
+	return 0;
 }
 
 static const struct udevice_id omap_usbhs_dt_ids[] = {
@@ -343,18 +312,6 @@
 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
 };
 
-struct ehci_omap_priv_data {
-	struct ehci_ctrl ctrl;
-	struct omap_ehci *ehci;
-#ifdef CONFIG_DM_REGULATOR
-	struct udevice *vbus_supply;
-#endif
-	enum usb_init_type init_type;
-	int portnr;
-	struct phy phy[OMAP_HS_USB_PORTS];
-	int nports;
-};
-
 static int ehci_usb_of_to_plat(struct udevice *dev)
 {
 	struct usb_plat *plat = dev_get_plat(dev);
@@ -364,12 +321,33 @@
 	return 0;
 }
 
+/*
+ * This driver references phys based on the USB port.  If
+ * the port is unused, the corresponding phy is listed as NULL
+ * which generic_phy_init_bulk treats as an error, so we need
+ * a custom one that tolerates empty phys
+ */
+static int omap_ehci_phy_get(struct udevice *dev)
+{
+	struct ehci_omap_priv_data *priv = dev_get_priv(dev);
+	int i, ret;
+
+	for (i = 0; i < OMAP_HS_USB_PORTS; i++) {
+		ret = generic_phy_get_by_index(dev, i, &priv->phy[i]);
+		if (ret && ret != -ENOENT)
+			return ret;
+	};
+
+	return 0;
+};
+
 static int omap_ehci_probe(struct udevice *dev)
 {
 	struct usb_plat *plat = dev_get_plat(dev);
 	struct ehci_omap_priv_data *priv = dev_get_priv(dev);
 	struct ehci_hccr *hccr;
 	struct ehci_hcor *hcor;
+	int ret;
 
 	priv->ehci = dev_read_addr_ptr(dev);
 	priv->portnr = dev_seq(dev);
@@ -378,6 +356,24 @@
 	hccr = (struct ehci_hccr *)&priv->ehci->hccapbase;
 	hcor = (struct ehci_hcor *)&priv->ehci->usbcmd;
 
+	/* Identify Phys */
+	ret = omap_ehci_phy_get(dev);
+	if (ret) {
+		printf("Failed to get phys\n");
+		return ret;
+	}
+
+	/* Register the EHCI */
+	ret = ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
+	if (ret) {
+		printf("Failed to register EHCI\n");
+		return ret;
+	}
+
+	ret = omap_ehci_hcd_init(0, &usbhs_bdata, dev);
+	if (ret)
+		return ret;
+
 	return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
 }