public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] imx: usb: ehci-mx6: wait_for_bit to check reg status
@ 2015-08-06 20:46 Adrian Alonso
  2015-08-06 22:36 ` Marek Vasut
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Alonso @ 2015-08-06 20:46 UTC (permalink / raw)
  To: u-boot

Add wait_for_bit to check reg bit status and replace unbounded
loops to check usb command status

Signed-off-by: Adrian Alonso <aalonso@freescale.com>
---
Patch depends on the following patch set:
imx: usb: ehci-mx6: add usb support for imx7d soc
imx: usb: ehci-mx6: document board specific functions
imx: usb: ehci-mx6: reg accessor cleanups

 drivers/usb/host/ehci-mx6.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 54f8684..2666351 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -117,12 +117,39 @@ static void usb_power_config(int index)
 		     pll_480_ctrl_set);
 }
 
+static int wait_for_bit(u32 *reg, const u32 mask, bool set)
+{
+	u32 val;
+	const unsigned int timeout = 10000;
+	unsigned long start = get_timer(0);
+
+	while(1) {
+		val = readl(reg);
+		if (!set)
+			val = ~val;
+
+		if ((val & mask) == mask)
+			return 0;
+
+		if (get_timer(start) > timeout)
+			break;
+
+		udelay(1);
+	}
+
+	debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
+			__func__, reg, mask, set);
+
+	return -ETIMEDOUT;
+}
+
 /* Return 0 : host node, <>0 : device mode */
 static int usb_phy_enable(int index, struct usb_ehci *ehci)
 {
 	void __iomem *phy_reg;
 	void __iomem *phy_ctrl;
 	void __iomem *usb_cmd;
+	int ret;
 
 	if (index >= ARRAY_SIZE(phy_bases))
 		return 0;
@@ -133,12 +160,14 @@ static int usb_phy_enable(int index, struct usb_ehci *ehci)
 
 	/* Stop then Reset */
 	clrbits_le32(usb_cmd, UCMD_RUN_STOP);
-	while (readl(usb_cmd) & UCMD_RUN_STOP)
-		;
+	ret = wait_for_bit(usb_cmd, UCMD_RUN_STOP, 0);
+	if (ret)
+		return ret;
 
 	setbits_le32(usb_cmd, UCMD_RESET);
-	while (readl(usb_cmd) & UCMD_RESET)
-		;
+	ret = wait_for_bit(usb_cmd, UCMD_RESET, 0);
+	if (ret)
+		return ret;
 
 	/* Reset USBPHY module */
 	setbits_le32(phy_ctrl, USBPHY_CTRL_SFTRST);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] imx: usb: ehci-mx6: wait_for_bit to check reg status
  2015-08-06 20:46 [U-Boot] [PATCH] imx: usb: ehci-mx6: wait_for_bit to check reg status Adrian Alonso
@ 2015-08-06 22:36 ` Marek Vasut
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2015-08-06 22:36 UTC (permalink / raw)
  To: u-boot

On Thursday, August 06, 2015 at 10:46:03 PM, Adrian Alonso wrote:
> Add wait_for_bit to check reg bit status and replace unbounded
> loops to check usb command status
> 
> Signed-off-by: Adrian Alonso <aalonso@freescale.com>

Applied to u-boot-usb/master, thanks!

Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-06 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-06 20:46 [U-Boot] [PATCH] imx: usb: ehci-mx6: wait_for_bit to check reg status Adrian Alonso
2015-08-06 22:36 ` Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox