Skip to contentSkip to conversation

usb: dwc2: Add reset ctrl to driver

PATCH New Ley Foon Tan 3 participants 4 messages Aug 28, 2018 – Aug 29, 2018 USB

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 usb: dwc2: Add reset ctrl to driver

Add code to reset all reset signals as in usb DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present.

If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset.

---
v3:
- Add error handling when return non-zero from reset_get_bulk().

v2:
- Add reset_release_bulk() in _remove function.

---
 drivers/usb/host/dwc2.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/usb/host/dwc2.c +37 -0
index cbe065b..b6f008a 100644
@@ -15,6 +15,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <power/regulator.h>
+#include <reset.h>
 
 #include "dwc2.h"
 
@@ -49,6 +50,8 @@ struct dwc2_priv {
 	 */
 	bool hnp_srp_disable;
 	bool oc_disable;
+
+	struct reset_ctl_bulk	resets;
 };
 
 #ifndef CONFIG_DM_USB
@@ -1124,11 +1127,43 @@ int _submit_int_msg(struct dwc2_priv *priv, struct usb_device *dev,
 	}
 }
 
+static int dwc2_reset(struct udevice *dev)
+{
+	int ret;
+	struct dwc2_priv *priv = dev_get_priv(dev);
+
+	ret = reset_get_bulk(dev, &priv->resets);
+	if (ret) {
+		dev_warn(dev, "Can't get reset: %d\n", ret);
+		/* Return 0 if error due to !CONFIG_DM_RESET and reset
+		 * DT property is not present.
+		 */
+		if (ret == -ENOENT || ret == -ENOTSUPP)
+			return 0;
+		else
+			return ret;
+	}
+
+	ret = reset_deassert_bulk(&priv->resets);
+	if (ret) {
+		reset_release_bulk(&priv->resets);
+		dev_err(dev, "Failed to reset: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 {
 	struct dwc2_core_regs *regs = priv->regs;
 	uint32_t snpsid;
 	int i, j;
+	int ret;
+
+	ret = dwc2_reset(dev);
+	if (ret)
+		return ret;
 
 	snpsid = readl(&regs->gsnpsid);
 	dev_info(dev, "Core Release: %x.%03x\n",
@@ -1303,6 +1338,8 @@ static int dwc2_usb_remove(struct udevice *dev)
 
 	dwc2_uninit_common(priv->regs);
 
+	reset_release_bulk(&priv->resets);
+
 	return 0;
 }
 
Signature · 1 line
1.7.1
#1 lore raw

PATCH v3 1/1 usb: dwc2: Add reset ctrl to driver

Quoted 85 lines · Ley Foon Tan

Add code to reset all reset signals as in usb DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present.

If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset.

---
v3:
- Add error handling when return non-zero from reset_get_bulk().

v2:
- Add reset_release_bulk() in _remove function.

---
 drivers/usb/host/dwc2.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/usb/host/dwc2.c +35 -0
index cbe065b..b6f008a 100644
@@ -15,6 +15,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <power/regulator.h>
+#include <reset.h>
 
 #include "dwc2.h"
 
@@ -49,6 +50,8 @@ struct dwc2_priv {
 	 */
 	bool hnp_srp_disable;
 	bool oc_disable;
+
+	struct reset_ctl_bulk	resets;
 };
 
 #ifndef CONFIG_DM_USB
@@ -1124,11 +1127,43 @@ int _submit_int_msg(struct dwc2_priv *priv, struct usb_device *dev,
 	}
 }
 
+static int dwc2_reset(struct udevice *dev)
+{
+	int ret;
+	struct dwc2_priv *priv = dev_get_priv(dev);
+
+	ret = reset_get_bulk(dev, &priv->resets);
+	if (ret) {
+		dev_warn(dev, "Can't get reset: %d\n", ret);
+		/* Return 0 if error due to !CONFIG_DM_RESET and reset
+		 * DT property is not present.
+		 */
+		if (ret == -ENOENT || ret == -ENOTSUPP)
+			return 0;
+		else
+			return ret;
+	}
+
+	ret = reset_deassert_bulk(&priv->resets);
+	if (ret) {
+		reset_release_bulk(&priv->resets);
+		dev_err(dev, "Failed to reset: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 {
 	struct dwc2_core_regs *regs = priv->regs;
 	uint32_t snpsid;
 	int i, j;
+	int ret;
+
+	ret = dwc2_reset(dev);
+	if (ret)
+		return ret;
 
 	snpsid = readl(&regs->gsnpsid);
 	dev_info(dev, "Core Release: %x.%03x\n",

drivers/usb/host/dwc2.c static int dwc2_usb_remove(struct udevice *dev) · line 1340

Quoted 3 lines
drivers/usb/host/dwc2.c +0 -0
@@ -1303,6 +1338,8 @@ static int dwc2_usb_remove(struct udevice *dev)
 
 	dwc2_uninit_common(priv->regs);
 

Don't you need to assert the reset here ?

Quoted 6 lines
drivers/usb/host/dwc2.c +2 -0
+	reset_release_bulk(&priv->resets);
+
 	return 0;
 }
 
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH v3 1/1 usb: dwc2: Add reset ctrl to driver

Quoted 84 lines · Marek Vasut
Quoted 82 lines · Ley Foon Tan

Add code to reset all reset signals as in usb DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present.

If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset.

---
v3:
- Add error handling when return non-zero from reset_get_bulk().

v2:
- Add reset_release_bulk() in _remove function.

---
 drivers/usb/host/dwc2.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/usb/host/dwc2.c +35 -0
index cbe065b..b6f008a 100644
@@ -15,6 +15,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <power/regulator.h>
+#include <reset.h>
 
 #include "dwc2.h"
 
@@ -49,6 +50,8 @@ struct dwc2_priv {
       */
      bool hnp_srp_disable;
      bool oc_disable;
+
+     struct reset_ctl_bulk   resets;
 };
 
 #ifndef CONFIG_DM_USB
@@ -1124,11 +1127,43 @@ int _submit_int_msg(struct dwc2_priv *priv, struct usb_device *dev,
      }
 }
 
+static int dwc2_reset(struct udevice *dev)
+{
+     int ret;
+     struct dwc2_priv *priv = dev_get_priv(dev);
+
+     ret = reset_get_bulk(dev, &priv->resets);
+     if (ret) {
+             dev_warn(dev, "Can't get reset: %d\n", ret);
+             /* Return 0 if error due to !CONFIG_DM_RESET and reset
+              * DT property is not present.
+              */
+             if (ret == -ENOENT || ret == -ENOTSUPP)
+                     return 0;
+             else
+                     return ret;
+     }
+
+     ret = reset_deassert_bulk(&priv->resets);
+     if (ret) {
+             reset_release_bulk(&priv->resets);
+             dev_err(dev, "Failed to reset: %d\n", ret);
+             return ret;
+     }
+
+     return 0;
+}
+
 static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 {
      struct dwc2_core_regs *regs = priv->regs;
      uint32_t snpsid;
      int i, j;
+     int ret;
+
+     ret = dwc2_reset(dev);
+     if (ret)
+             return ret;
 
Quoted 8 lines

drivers/usb/host/dwc2.c static int dwc2_usb_remove(struct udevice *dev) · line 1340

Quoted 6 lines
drivers/usb/host/dwc2.c +0 -0
      snpsid = readl(&regs->gsnpsid);
      dev_info(dev, "Core Release: %x.%03x\n",
@@ -1303,6 +1338,8 @@ static int dwc2_usb_remove(struct udevice *dev)
 
      dwc2_uninit_common(priv->regs);
 

Don't you need to assert the reset here ?

reset_release_bulk() function will assert the reset and free reset struct.

Quoted 8 lines

drivers/usb/host/dwc2.c static int dwc2_usb_remove(struct udevice *dev) · line 1345

Quoted 7 lines
drivers/usb/host/dwc2.c +2 -0
+     reset_release_bulk(&priv->resets);
+
      return 0;
 }
 

Regards
Ley Foon

#3 lore raw

PATCH v3 1/1 usb: dwc2: Add reset ctrl to driver

Quoted 89 lines · Ley Foon Tan
Quoted 88 lines · Marek Vasut
Quoted 86 lines · Ley Foon Tan

Add code to reset all reset signals as in usb DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present.

If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset.

---
v3:
- Add error handling when return non-zero from reset_get_bulk().

v2:
- Add reset_release_bulk() in _remove function.

---
 drivers/usb/host/dwc2.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/usb/host/dwc2.c +35 -0
index cbe065b..b6f008a 100644
@@ -15,6 +15,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <power/regulator.h>
+#include <reset.h>
 
 #include "dwc2.h"
 
@@ -49,6 +50,8 @@ struct dwc2_priv {
       */
      bool hnp_srp_disable;
      bool oc_disable;
+
+     struct reset_ctl_bulk   resets;
 };
 
 #ifndef CONFIG_DM_USB
@@ -1124,11 +1127,43 @@ int _submit_int_msg(struct dwc2_priv *priv, struct usb_device *dev,
      }
 }
 
+static int dwc2_reset(struct udevice *dev)
+{
+     int ret;
+     struct dwc2_priv *priv = dev_get_priv(dev);
+
+     ret = reset_get_bulk(dev, &priv->resets);
+     if (ret) {
+             dev_warn(dev, "Can't get reset: %d\n", ret);
+             /* Return 0 if error due to !CONFIG_DM_RESET and reset
+              * DT property is not present.
+              */
+             if (ret == -ENOENT || ret == -ENOTSUPP)
+                     return 0;
+             else
+                     return ret;
+     }
+
+     ret = reset_deassert_bulk(&priv->resets);
+     if (ret) {
+             reset_release_bulk(&priv->resets);
+             dev_err(dev, "Failed to reset: %d\n", ret);
+             return ret;
+     }
+
+     return 0;
+}
+
 static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 {
      struct dwc2_core_regs *regs = priv->regs;
      uint32_t snpsid;
      int i, j;
+     int ret;
+
+     ret = dwc2_reset(dev);
+     if (ret)
+             return ret;
 
      snpsid = readl(&regs->gsnpsid);
      dev_info(dev, "Core Release: %x.%03x\n",
@@ -1303,6 +1338,8 @@ static int dwc2_usb_remove(struct udevice *dev)
 
Quoted 5 lines
Quoted 4 lines

drivers/usb/host/dwc2.c static int dwc2_usb_remove(struct udevice *dev) · line 1340

Quoted 2 lines
drivers/usb/host/dwc2.c +0 -0
      dwc2_uninit_common(priv->regs);
 

Don't you need to assert the reset here ?

reset_release_bulk() function will assert the reset and free reset struct.

Ah, OK, applied, thanks.

Signature · 2 lines
Best regards,
Marek Vasut