[4/8] usb: ehci-mx6: move mode set/detect to probe

Message ID 20220520082623.1788887-5-tommaso.merciai@amarulasolutions.com
State New
Headers show
Series
  • imx8mm: Add serial download support
Related show

Commit Message

Tommaso Merciai May 20, 2022, 8:26 a.m. UTC
There is no need to set and/or detect mode in of_to_plat and
accessing phy registers at that point before device power domain and
clock are enabled will cause hangs on platforms such as IMX8M Mini.

Move the mode set/detect from of_to_plat into the probe and remove
the unnecessary of_to_plat.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: Tommaso Merciai <tommaso.merciai@amarulasolutions.com>
---
 drivers/usb/host/ehci-mx6.c | 49 ++++++++++---------------------------
 1 file changed, 13 insertions(+), 36 deletions(-)

Patch

diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 060b02accc..1b6dc19a01 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -559,27 +559,6 @@  static int ehci_usb_phy_mode(struct udevice *dev)
 	return 0;
 }
 
-static int ehci_usb_of_to_plat(struct udevice *dev)
-{
-	struct usb_plat *plat = dev_get_plat(dev);
-	enum usb_dr_mode dr_mode;
-
-	dr_mode = usb_get_dr_mode(dev_ofnode(dev));
-
-	switch (dr_mode) {
-	case USB_DR_MODE_HOST:
-		plat->init_type = USB_INIT_HOST;
-		break;
-	case USB_DR_MODE_PERIPHERAL:
-		plat->init_type = USB_INIT_DEVICE;
-		break;
-	default:
-		plat->init_type = USB_INIT_UNKNOWN;
-	};
-
-	return 0;
-}
-
 static int mx6_parse_dt_addrs(struct udevice *dev)
 {
 #if !defined(CONFIG_PHY)
@@ -641,7 +620,6 @@  static int ehci_usb_probe(struct udevice *dev)
 	struct usb_plat *plat = dev_get_plat(dev);
 	struct usb_ehci *ehci = dev_read_addr_ptr(dev);
 	struct ehci_mx6_priv_data *priv = dev_get_priv(dev);
-	enum usb_init_type type = plat->init_type;
 	struct ehci_hccr *hccr;
 	struct ehci_hcor *hcor;
 	int ret;
@@ -659,7 +637,6 @@  static int ehci_usb_probe(struct udevice *dev)
 		return ret;
 
 	priv->ehci = ehci;
-	priv->init_type = type;
 	priv->phy_type = usb_get_phy_mode(dev_ofnode(dev));
 
 #if CONFIG_IS_ENABLED(CLK)
@@ -676,19 +653,20 @@  static int ehci_usb_probe(struct udevice *dev)
 	mdelay(1);
 #endif
 
-	/*
-	 * If the device tree didn't specify host or device,
-	 * the default is USB_INIT_UNKNOWN, so we need to check
-	 * the register. For imx8mm and imx8mn, the clocks need to be
-	 * running first, so we defer the check until they are.
-	 */
-	if (priv->init_type == USB_INIT_UNKNOWN) {
+		switch (usb_get_dr_mode(dev_ofnode(dev))) {
+		case USB_DR_MODE_HOST:
+			plat->init_type = USB_INIT_HOST;
+			break;
+		case USB_DR_MODE_PERIPHERAL:
+			plat->init_type = USB_INIT_DEVICE;
+			break;
+		case USB_DR_MODE_OTG:
+		case USB_DR_MODE_UNKNOWN:
 		ret = ehci_usb_phy_mode(dev);
 		if (ret)
-			goto err_clk;
-		else
-			priv->init_type = plat->init_type;
-	}
+			return ret;
+	};
+	priv->init_type = plat->init_type;
 
 #if CONFIG_IS_ENABLED(DM_REGULATOR)
 	ret = device_get_supply_regulator(dev, "vbus-supply",
@@ -713,7 +691,7 @@  static int ehci_usb_probe(struct udevice *dev)
 #if CONFIG_IS_ENABLED(DM_REGULATOR)
 	if (priv->vbus_supply) {
 		ret = regulator_set_enable(priv->vbus_supply,
-					   (type == USB_INIT_DEVICE) ?
+					   (priv->init_type == USB_INIT_DEVICE) ?
 					   false : true);
 		if (ret && ret != -ENOSYS) {
 			printf("Error enabling VBUS supply (ret=%i)\n", ret);
@@ -798,7 +776,6 @@  U_BOOT_DRIVER(usb_mx6) = {
 	.name	= "ehci_mx6",
 	.id	= UCLASS_USB,
 	.of_match = mx6_usb_ids,
-	.of_to_plat = ehci_usb_of_to_plat,
 	.probe	= ehci_usb_probe,
 	.remove = ehci_usb_remove,
 	.ops	= &ehci_usb_ops,