Skip to contentSkip to conversation

usb: dwc2: reset dwc2 core before dwc2_get_hwparams()

PATCH In review Yunzhi Li 2 participants 2 messages Aug 19, 2015 – Aug 21, 2015

Subsystems (2)
lore
Share & tools
lore

Yunzhi Li

author
#0 lore raw

PATCH v3 1/1 usb: dwc2: reset dwc2 core before dwc2_get_hwparams()

We initiate dwc2 usb controller in BIOS, dwc2_core_reset() should be called before dwc2_get_hwparams() to reset core registers to default value. Without this the FIFO setting might be incorrect because calculating FIFO size need power-on value of GRXFSIZ/GNPTXFSIZ/HPTXFSIZ registers.

This patch could avoid warnning massage like in rk3288 platform:

[    2.074764] dwc2 ff580000.usb: 256 invalid for

host_perio_tx_fifo_size. Check HW configuration.

---

 drivers/usb/dwc2/core.c     |  2 +-
 drivers/usb/dwc2/core.h     |  1 +
 drivers/usb/dwc2/platform.c | 21 ++++++++++++++++++++-
 3 files changed, 22 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.c +1 -1
index c3cc1a7..86d1d65 100644
@@ -474,7 +474,7 @@ static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg)
  * Do core a soft reset of the core.  Be careful with this because it
  * resets all the internal state machines of the core.
  */
-static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
+int dwc2_core_reset(struct dwc2_hsotg *hsotg)
 {
 	u32 greset;
 	int count = 0;
drivers/usb/dwc2/core.h +1 -0
index 0ed87620..5d95aec 100644
@@ -846,6 +846,7 @@ enum dwc2_halt_status {
  * The following functions support initialization of the core driver component
  * and the DWC_otg controller
  */
+extern int dwc2_core_reset(struct dwc2_hsotg *hsotg);
 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
 extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
 extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
drivers/usb/dwc2/platform.c +20 -1
index 9093530..55d378a 100644
@@ -166,7 +166,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	struct phy *phy;
 	struct usb_phy *uphy;
 	int retval;
-	int irq;
+	int irq, count = 0;
+	u32 greset;
 
 	match = of_match_device(dwc2_of_match_table, &dev->dev);
 	if (match && match->data) {
@@ -243,6 +244,24 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	spin_lock_init(&hsotg->lock);
 	mutex_init(&hsotg->init_mutex);
 
+	/*
+	 * Reset before dwc2_get_hwparams() then it could get power-on real
+	 * reset value form registers.
+	 */
+	count = 0;
+	greset |= GRSTCTL_CSFTRST;
+	writel(greset, hsotg->regs + GRSTCTL);
+	do {
+		usleep_range(20000, 40000);
+		greset = readl(hsotg->regs + GRSTCTL);
+		if (++count > 50) {
+			dev_warn(hsotg->dev,
+				 "%s() HANG! Soft Reset GRSTCTL=%0x\n",
+				 __func__, greset);
+			return -EBUSY;
+		}
+	} while (greset & GRSTCTL_CSFTRST);
+
 	/* Detect config values from hardware */
 	retval = dwc2_get_hwparams(hsotg);
 	if (retval)
Signature · 1 line
2.0.0
#1 lore raw
Quoted 70 lines · Yunzhi Li

We initiate dwc2 usb controller in BIOS, dwc2_core_reset() should be called before dwc2_get_hwparams() to reset core registers to default value. Without this the FIFO setting might be incorrect because calculating FIFO size need power-on value of GRXFSIZ/GNPTXFSIZ/HPTXFSIZ registers.

This patch could avoid warnning massage like in rk3288 platform:

[    2.074764] dwc2 ff580000.usb: 256 invalid for

host_perio_tx_fifo_size. Check HW configuration.

---

 drivers/usb/dwc2/core.c     |  2 +-
 drivers/usb/dwc2/core.h     |  1 +
 drivers/usb/dwc2/platform.c | 21 ++++++++++++++++++++-
 3 files changed, 22 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.c +1 -1
index c3cc1a7..86d1d65 100644
@@ -474,7 +474,7 @@ static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg)
  * Do core a soft reset of the core.  Be careful with this because it
  * resets all the internal state machines of the core.
  */
-static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
+int dwc2_core_reset(struct dwc2_hsotg *hsotg)
 {
 	u32 greset;
 	int count = 0;
drivers/usb/dwc2/core.h +1 -0
index 0ed87620..5d95aec 100644
@@ -846,6 +846,7 @@ enum dwc2_halt_status {
  * The following functions support initialization of the core driver component
  * and the DWC_otg controller
  */
+extern int dwc2_core_reset(struct dwc2_hsotg *hsotg);
 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
 extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
 extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
drivers/usb/dwc2/platform.c +10 -1
index 9093530..55d378a 100644
@@ -166,7 +166,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	struct phy *phy;
 	struct usb_phy *uphy;
 	int retval;
-	int irq;
+	int irq, count = 0;
+	u32 greset;
 
 	match = of_match_device(dwc2_of_match_table, &dev->dev);
 	if (match && match->data) {
@@ -243,6 +244,24 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	spin_lock_init(&hsotg->lock);
 	mutex_init(&hsotg->init_mutex);
 
+	/*
+	 * Reset before dwc2_get_hwparams() then it could get power-on real
+	 * reset value form registers.
+	 */
+	count = 0;
+	greset |= GRSTCTL_CSFTRST;
+	writel(greset, hsotg->regs + GRSTCTL);
+	do {

drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 264

Quoted 10 lines
drivers/usb/dwc2/platform.c +10 -0
+		usleep_range(20000, 40000);
+		greset = readl(hsotg->regs + GRSTCTL);
+		if (++count > 50) {
+			dev_warn(hsotg->dev,
+				 "%s() HANG! Soft Reset GRSTCTL=%0x\n",
+				 __func__, greset);
+			return -EBUSY;
+		}
+	} while (greset & GRSTCTL_CSFTRST);
+

Could you move this out to a separate function so
that we don't have duplicate code?

Thanks,
John