diff mbox

[U-Boot,2/5] usb: dwc2: Use shared wait_for_bit

Message ID 1450138168-25102-3-git-send-email-mateusz.kulikowski@gmail.com
State Changes Requested
Delegated to: Marek Vasut
Headers show

Commit Message

Mateusz Kulikowski Dec. 15, 2015, 12:09 a.m. UTC
Use existing library function to poll bit(s).
Update configs using dwc2.

Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
---

 drivers/usb/host/dwc2.c          | 43 +++++++++++++++-------------------------
 include/configs/hikey.h          |  1 +
 include/configs/rpi-common.h     |  1 +
 include/configs/socfpga_common.h |  1 +
 4 files changed, 19 insertions(+), 27 deletions(-)

Comments

Marek Vasut Dec. 15, 2015, 12:21 a.m. UTC | #1
On Tuesday, December 15, 2015 at 01:09:24 AM, Mateusz Kulikowski wrote:
> Use existing library function to poll bit(s).
> Update configs using dwc2.
> 
> Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
> ---

[...]

> diff --git a/include/configs/hikey.h b/include/configs/hikey.h
> index 796861e..4e3bfec 100644
> --- a/include/configs/hikey.h
> +++ b/include/configs/hikey.h
> @@ -66,6 +66,7 @@
> 
>  #define CONFIG_CMD_USB
>  #ifdef CONFIG_CMD_USB
> +#define CONFIG_LIB_WAIT_BIT

Just enable this stuff by default (ie. dont introduce new config option,
just use obj-y in lib/Makefile). The compiler will throw the function away
if it's not used.

>  #define CONFIG_USB_DWC2
>  #define CONFIG_USB_DWC2_REG_ADDR 0xF72C0000
>  /*#define CONFIG_DWC2_DFLT_SPEED_FULL*/

[...]

Best regards,
Marek Vasut
Mateusz Kulikowski Dec. 15, 2015, 9:22 p.m. UTC | #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 15.12.2015 01:21, Marek Vasut wrote:
> On Tuesday, December 15, 2015 at 01:09:24 AM, Mateusz Kulikowski wrote:
[...]
> 
> Just enable this stuff by default (ie. dont introduce new config option,
> just use obj-y in lib/Makefile). The compiler will throw the function away
> if it's not used.
I had some concerns about that in the morning but now everything is clear, 
will do it that way (and learned something today).


Thanks for the review,
Mateusz

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJWcISEAAoJELvtohmVtQzBWOYIAIbDorhGaxDNpGAgMNqqJqka
wwA5Lkv0DLy+CbQeA+MYvmy1gfPTNlJ/AimmKz1HwSkqVthoFq3nHQwvR6hhkbEF
fJE6+jkebW8+5dXffNd6DA4ok40EP3uAipG2YEMjJ9hSvgZP0GPz4JhSVMcX4GRF
WGUuuNAJNXLrd3hglm4l4N+ltMhLH9G+7/qcVFnpIJeQs4jxWAezoIq0hSdfYE0F
9WHRWqgBS+ZyfcHQaKwqo2RL8jDKaKicgE00JpXtd5txwql8MrbSegBnkKq/BdeE
6haxAgbgsqRWnOhKfEQerTmzfewiJ4AFwixb1MyvvsWfUFPtQr14DtQlRZwYBLo=
=nWpX
-----END PGP SIGNATURE-----
Marek Vasut Dec. 15, 2015, 10:43 p.m. UTC | #3
On Tuesday, December 15, 2015 at 10:22:22 PM, Mateusz Kulikowski wrote:
> On 15.12.2015 01:21, Marek Vasut wrote:
> > On Tuesday, December 15, 2015 at 01:09:24 AM, Mateusz Kulikowski wrote:
> [...]
> 
> > Just enable this stuff by default (ie. dont introduce new config option,
> > just use obj-y in lib/Makefile). The compiler will throw the function
> > away if it's not used.
> 
> I had some concerns about that in the morning but now everything is clear,
> will do it that way (and learned something today).

Good , thanks!

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 541c0f9..d1c9c45 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -13,6 +13,7 @@ 
 #include <memalign.h>
 #include <phys2bus.h>
 #include <usbroothubdes.h>
+#include <wait_bit.h>
 #include <asm/io.h>
 
 #include "dwc2.h"
@@ -52,27 +53,10 @@  static struct dwc2_priv local;
 /*
  * DWC2 IP interface
  */
-static int wait_for_bit(void *reg, const uint32_t mask, bool set)
-{
-	unsigned int timeout = 1000000;
-	uint32_t val;
-
-	while (--timeout) {
-		val = readl(reg);
-		if (!set)
-			val = ~val;
-
-		if ((val & mask) == mask)
-			return 0;
-
-		udelay(1);
-	}
-
-	debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
-	      __func__, reg, mask, set);
 
-	return -ETIMEDOUT;
-}
+#ifndef CONFIG_LIB_WAIT_BIT
+#error CONFIG_LIB_WAIT_BIT is required for dwc2 driver
+#endif
 
 /*
  * Initializes the FSLSPClkSel field of the HCFG register
@@ -117,7 +101,8 @@  static void dwc_otg_flush_tx_fifo(struct dwc2_core_regs *regs, const int num)
 
 	writel(DWC2_GRSTCTL_TXFFLSH | (num << DWC2_GRSTCTL_TXFNUM_OFFSET),
 	       &regs->grstctl);
-	ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_TXFFLSH, 0);
+	ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_TXFFLSH,
+			   false, 1000, false);
 	if (ret)
 		printf("%s: Timeout!\n", __func__);
 
@@ -135,7 +120,8 @@  static void dwc_otg_flush_rx_fifo(struct dwc2_core_regs *regs)
 	int ret;
 
 	writel(DWC2_GRSTCTL_RXFFLSH, &regs->grstctl);
-	ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_RXFFLSH, 0);
+	ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_RXFFLSH,
+			   false, 1000, false);
 	if (ret)
 		printf("%s: Timeout!\n", __func__);
 
@@ -152,13 +138,15 @@  static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
 	int ret;
 
 	/* Wait for AHB master IDLE state. */
-	ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_AHBIDLE, 1);
+	ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_AHBIDLE,
+			   true, 1000, false);
 	if (ret)
 		printf("%s: Timeout!\n", __func__);
 
 	/* Core Soft Reset */
 	writel(DWC2_GRSTCTL_CSFTRST, &regs->grstctl);
-	ret = wait_for_bit(&regs->grstctl, DWC2_GRSTCTL_CSFTRST, 0);
+	ret = wait_for_bit(__func__, &regs->grstctl, DWC2_GRSTCTL_CSFTRST,
+			   false, 1000, false);
 	if (ret)
 		printf("%s: Timeout!\n", __func__);
 
@@ -243,8 +231,8 @@  static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
 		clrsetbits_le32(&regs->hc_regs[i].hcchar,
 				DWC2_HCCHAR_EPDIR,
 				DWC2_HCCHAR_CHEN | DWC2_HCCHAR_CHDIS);
-		ret = wait_for_bit(&regs->hc_regs[i].hcchar,
-				   DWC2_HCCHAR_CHEN, 0);
+		ret = wait_for_bit(__func__, &regs->hc_regs[i].hcchar,
+				   DWC2_HCCHAR_CHEN, false, 1000, false);
 		if (ret)
 			printf("%s: Timeout!\n", __func__);
 	}
@@ -737,7 +725,8 @@  int wait_for_chhltd(struct dwc2_core_regs *regs, uint32_t *sub, int *toggle,
 	int ret;
 	uint32_t hcint, hctsiz;
 
-	ret = wait_for_bit(&hc_regs->hcint, DWC2_HCINT_CHHLTD, true);
+	ret = wait_for_bit(__func__, &hc_regs->hcint, DWC2_HCINT_CHHLTD, true,
+			   1000, false);
 	if (ret)
 		return ret;
 
diff --git a/include/configs/hikey.h b/include/configs/hikey.h
index 796861e..4e3bfec 100644
--- a/include/configs/hikey.h
+++ b/include/configs/hikey.h
@@ -66,6 +66,7 @@ 
 
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_DWC2
 #define CONFIG_USB_DWC2_REG_ADDR 0xF72C0000
 /*#define CONFIG_DWC2_DFLT_SPEED_FULL*/
diff --git a/include/configs/rpi-common.h b/include/configs/rpi-common.h
index 1b83eb3..70d6123 100644
--- a/include/configs/rpi-common.h
+++ b/include/configs/rpi-common.h
@@ -78,6 +78,7 @@ 
 
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_DWC2
 #ifdef CONFIG_BCM2836
 #define CONFIG_USB_DWC2_REG_ADDR 0x3f980000
diff --git a/include/configs/socfpga_common.h b/include/configs/socfpga_common.h
index b3f65b6..47062cd 100644
--- a/include/configs/socfpga_common.h
+++ b/include/configs/socfpga_common.h
@@ -227,6 +227,7 @@  unsigned int cm_get_qspi_controller_clk_hz(void);
  * USB
  */
 #ifdef CONFIG_CMD_USB
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_DWC2
 #define CONFIG_USB_STORAGE
 /*