Skip to contentSkip to conversation

usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn

PATCH Superseded Adam Ford 2 participants 4 messages Dec 22, 2021

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Adam Ford

author
#0 lore raw

PATCH 1/1 usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn

The imx8mm and imx8mn appear compatible with imx7d-usb flags in the OTG driver. If the dr_mode is defined as host or peripheral, the device appears to operate correctly, however the auto host/peripheral detection results in an error.

Simply adding checks in ehci_usb_phy_mode for 8mm and 8mn in ehci_usb_phy_mode is not enough, because ehci_usb_of_to_plat is run before the clock is enabled which results in a hang.

Enable the USB clock in ehci_usb_of_to_plat and add checks in ehci_usb_phy_mode for 8mm and 8mn to enable auto detection of the OTG mode on i.MX8M Mini and Nano.

drivers/usb/host/ehci-mx6.c +20 -1
index 1bd6147c76..fa0798171b 100644
@@ -543,7 +543,7 @@ static int ehci_usb_phy_mode(struct udevice *dev)
 			plat->init_type = USB_INIT_DEVICE;
 		else
 			plat->init_type = USB_INIT_HOST;
-	} else if (is_mx7()) {
+	} else if (is_mx7() || is_imx8mm() || is_imx8mn()) {
 		phy_status = (void __iomem *)(addr +
 					      USBNC_PHY_STATUS_OFFSET);
 		val = readl(phy_status);
@@ -561,11 +561,30 @@ static int ehci_usb_phy_mode(struct udevice *dev)
 
 static int ehci_usb_of_to_plat(struct udevice *dev)
 {
+#if CONFIG_IS_ENABLED(CLK)
+	int ret = 0;
+	struct ehci_mx6_priv_data *priv = dev_get_priv(dev);
+
+	ret = clk_get_by_index(dev, 0, &priv->clk);
+	if (ret < 0)
+		return ret;
+
+	ret = clk_enable(&priv->clk);
+	if (ret)
+		return ret;
+#endif
+
 	struct usb_plat *plat = dev_get_plat(dev);
 	enum usb_dr_mode dr_mode;
 
 	dr_mode = usb_get_dr_mode(dev_ofnode(dev));
 
+#if CONFIG_IS_ENABLED(CLK)
+	ret = clk_disable(&priv->clk);
+	if (ret)
+		return ret;
+#endif
+
 	switch (dr_mode) {
 	case USB_DR_MODE_HOST:
 		plat->init_type = USB_INIT_HOST;
Signature · 1 line
2.32.0
#1 lore raw
Quoted 5 lines · Adam Ford

The imx8mm and imx8mn appear compatible with imx7d-usb flags in the OTG driver. If the dr_mode is defined as host or peripheral, the device appears to operate correctly, however the auto host/peripheral detection results in an error.

Quoted 7 lines

Simply adding checks in ehci_usb_phy_mode for 8mm and 8mn in ehci_usb_phy_mode is not enough, because ehci_usb_of_to_plat is run before the clock is enabled which results in a hang.

Enable the USB clock in ehci_usb_of_to_plat and add checks in ehci_usb_phy_mode for 8mm and 8mn to enable auto detection of the OTG mode on i.MX8M Mini and Nano.

I was under the impression that of_to_plat() was meant to parse DT into driver local data, so frobbing with clock there could be a problem, right ? +CC Simon.

Quoted 44 lines
drivers/usb/host/ehci-mx6.c +20 -1
index 1bd6147c76..fa0798171b 100644
@@ -543,7 +543,7 @@ static int ehci_usb_phy_mode(struct udevice *dev)
  			plat->init_type = USB_INIT_DEVICE;
  		else
  			plat->init_type = USB_INIT_HOST;
-	} else if (is_mx7()) {
+	} else if (is_mx7() || is_imx8mm() || is_imx8mn()) {
  		phy_status = (void __iomem *)(addr +
  					      USBNC_PHY_STATUS_OFFSET);
  		val = readl(phy_status);
@@ -561,11 +561,30 @@ static int ehci_usb_phy_mode(struct udevice *dev)
 
  static int ehci_usb_of_to_plat(struct udevice *dev)
  {
+#if CONFIG_IS_ENABLED(CLK)
+	int ret = 0;
+	struct ehci_mx6_priv_data *priv = dev_get_priv(dev);
+
+	ret = clk_get_by_index(dev, 0, &priv->clk);
+	if (ret < 0)
+		return ret;
+
+	ret = clk_enable(&priv->clk);
+	if (ret)
+		return ret;
+#endif
+
  	struct usb_plat *plat = dev_get_plat(dev);
  	enum usb_dr_mode dr_mode;
 
  	dr_mode = usb_get_dr_mode(dev_ofnode(dev));
 
+#if CONFIG_IS_ENABLED(CLK)
+	ret = clk_disable(&priv->clk);
+	if (ret)
+		return ret;
+#endif
+
  	switch (dr_mode) {
  	case USB_DR_MODE_HOST:
  		plat->init_type = USB_INIT_HOST;
author
#2 lore raw
Quoted 10 lines · Marek Vasut
Quoted 9 lines · Adam Ford

The imx8mm and imx8mn appear compatible with imx7d-usb flags in the OTG driver. If the dr_mode is defined as host or peripheral, the device appears to operate correctly, however the auto host/peripheral detection results in an error.

Simply adding checks in ehci_usb_phy_mode for 8mm and 8mn in ehci_usb_phy_mode is not enough, because ehci_usb_of_to_plat is run before the clock is enabled which results in a hang.

Quoted 8 lines
Quoted 3 lines

Enable the USB clock in ehci_usb_of_to_plat and add checks in ehci_usb_phy_mode for 8mm and 8mn to enable auto detection of the OTG mode on i.MX8M Mini and Nano.

I was under the impression that of_to_plat() was meant to parse DT into driver local data, so frobbing with clock there could be a problem, right ? +CC Simon.

If that's true, we'll likely need to move the functions from ehci_usb_of_to_plat to the probe function to run after the clocks are enabled, because the call to usb_get_dr_mode hangs without the clocks running. usb_get_dr_mode tells the driver if it's a host or device mode.

We could make a temporary clock instead of passing the clock to the priv structure. I intentionally shut the clock off as soon as we're finished reading the register so it didn't collide with the existing functions.

adam

Quoted 46 lines
Quoted 45 lines
drivers/usb/host/ehci-mx6.c +20 -1
index 1bd6147c76..fa0798171b 100644
@@ -543,7 +543,7 @@ static int ehci_usb_phy_mode(struct udevice *dev)
                      plat->init_type = USB_INIT_DEVICE;
              else
                      plat->init_type = USB_INIT_HOST;
-     } else if (is_mx7()) {
+     } else if (is_mx7() || is_imx8mm() || is_imx8mn()) {
              phy_status = (void __iomem *)(addr +
                                            USBNC_PHY_STATUS_OFFSET);
              val = readl(phy_status);
@@ -561,11 +561,30 @@ static int ehci_usb_phy_mode(struct udevice *dev)
 
  static int ehci_usb_of_to_plat(struct udevice *dev)
  {
+#if CONFIG_IS_ENABLED(CLK)
+     int ret = 0;
+     struct ehci_mx6_priv_data *priv = dev_get_priv(dev);
+
+     ret = clk_get_by_index(dev, 0, &priv->clk);
+     if (ret < 0)
+             return ret;
+
+     ret = clk_enable(&priv->clk);
+     if (ret)
+             return ret;
+#endif
+
      struct usb_plat *plat = dev_get_plat(dev);
      enum usb_dr_mode dr_mode;
 
      dr_mode = usb_get_dr_mode(dev_ofnode(dev));
 
+#if CONFIG_IS_ENABLED(CLK)
+     ret = clk_disable(&priv->clk);
+     if (ret)
+             return ret;
+#endif
+
      switch (dr_mode) {
      case USB_DR_MODE_HOST:
              plat->init_type = USB_INIT_HOST;
#3 lore raw
Quoted 21 lines · Adam Ford
Quoted 10 lines · Marek Vasut
Quoted 9 lines · Adam Ford

The imx8mm and imx8mn appear compatible with imx7d-usb flags in the OTG driver. If the dr_mode is defined as host or peripheral, the device appears to operate correctly, however the auto host/peripheral detection results in an error.

Simply adding checks in ehci_usb_phy_mode for 8mm and 8mn in ehci_usb_phy_mode is not enough, because ehci_usb_of_to_plat is run before the clock is enabled which results in a hang.

Quoted 8 lines
Quoted 3 lines

Enable the USB clock in ehci_usb_of_to_plat and add checks in ehci_usb_phy_mode for 8mm and 8mn to enable auto detection of the OTG mode on i.MX8M Mini and Nano.

I was under the impression that of_to_plat() was meant to parse DT into driver local data, so frobbing with clock there could be a problem, right ? +CC Simon.

Quoted 4 lines

If that's true, we'll likely need to move the functions from ehci_usb_of_to_plat to the probe function to run after the clocks are enabled, because the call to usb_get_dr_mode hangs without the clocks running. usb_get_dr_mode tells the driver if it's a host or device mode.

Yes and this does not work, because you need to know whether the IP is in host and gadget mode before probe happens I think. Indeed, that's why OTG is unsupported thus far. But please do dig in and try to find a proper solution.

Quoted 3 lines

We could make a temporary clock instead of passing the clock to the priv structure. I intentionally shut the clock off as soon as we're finished reading the register so it didn't collide with the existing functions.

[...]