Skip to contentSkip to conversation

Add wait_for_bit()

PATCH Superseded Mateusz Kulikowski 3 participants 13 messages Dec 15, 2015

Subsystems (8)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Add wait_for_bit()

This series add generic function to poll register waiting for one or more bits to change.

Very similar function was used in several drivers:
- dwc2
- ohci-lp32xx
- ehci-mx6
- zynq_gem

First patch adds function, following patches update drivers and board config files / defconfigs.

This series was compile-tested with buildman for ~50 boards (most or even all boards affected by change)

Code was also run-tested on ehci-msm driver (not yet in mainline)

There is single difference in behavior: ohci-lp32xx driver will not print "Timeout..." message with debug disabled.
I think it's not a big issue as this driver seems unused, but if it's an issue - please drop that patch.

Mateusz Kulikowski (5):
lib: Add wait_for_bit
usb: dwc2: Use shared wait_for_bit
usb: ohci-lpc32xx: Use shared wait_for_bit
usb: ehci-mx6: Use shared wait_for_bit
net: zynq_gem: Use shared wait_for_bit

 drivers/net/Kconfig                   |  1 +
 drivers/net/zynq_gem.c                | 35 ++--------------------------
 drivers/usb/host/dwc2.c               | 43 +++++++++++++---------------------
 drivers/usb/host/ehci-mx6.c           | 37 +++++++----------------------
 drivers/usb/host/ohci-lpc32xx.c       | 36 ++++++++--------------------
 include/configs/aristainetos-common.h |  1 +
 include/configs/cgtqmx6eval.h         |  1 +
 include/configs/embestmx6boards.h     |  1 +
 include/configs/gw_ventana.h          |  1 +
 include/configs/hikey.h               |  1 +
 include/configs/mx6cuboxi.h           |  1 +
 include/configs/mx6qarm2.h            |  1 +
 include/configs/mx6qsabreauto.h       |  1 +
 include/configs/mx6sabresd.h          |  1 +
 include/configs/mx6slevk.h            |  1 +
 include/configs/mx6sxsabresd.h        |  1 +
 include/configs/mx6ul_14x14_evk.h     |  1 +
 include/configs/nitrogen6x.h          |  1 +
 include/configs/novena.h              |  1 +
 include/configs/ot1200.h              |  1 +
 include/configs/platinum.h            |  1 +
 include/configs/rpi-common.h          |  1 +
 include/configs/socfpga_common.h      |  1 +
 include/configs/tbs2910.h             |  1 +
 include/configs/titanium.h            |  1 +
 include/configs/tqma6.h               |  1 +
 include/configs/wandboard.h           |  1 +
 include/configs/warp.h                |  1 +
 include/wait_bit.h                    | 34 +++++++++++++++++++++++++++
 lib/Kconfig                           |  4 ++++
 lib/Makefile                          |  1 +
 lib/wait_bit.c                        | 44 +++++++++++++++++++++++++++++++++++
 32 files changed, 144 insertions(+), 114 deletions(-)
 create mode 100644 include/wait_bit.h
 create mode 100644 lib/wait_bit.c
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/5 lib: Add wait_for_bit

Add function to poll register waiting for specific bit(s). Similar functions are implemented in few drivers - they are almost identical and can be generalized.

---

 include/wait_bit.h | 34 ++++++++++++++++++++++++++++++++++
 lib/Kconfig        |  4 ++++
 lib/Makefile       |  1 +
 lib/wait_bit.c     | 44 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+)
 create mode 100644 include/wait_bit.h
 create mode 100644 lib/wait_bit.c
include/wait_bit.h new file +34 -0
new file mode 100644
index 0000000..7dbfa1a
@@ -0,0 +1,34 @@
+/*
+ * Wait for bit with timeout and ctrlc
+ *
+ * (C) Copyright 2015 Mateusz Kulikowski <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __WAIT_BIT_H
+#define __WAIT_BIT_H
+
+/**
+ * wait_for_bit()	waits for bit set/cleared in register
+ *
+ * Function polls register waiting for specific bit(s) change
+ * (either 0->1 or 1->0). It can fail under two conditions:
+ * - Timeout
+ * - User interaction (CTRL-C)
+ * Function succeeds only if all bits of masked register are set/cleared
+ * (depending on set option).
+ *
+ * @param prefix	Prefix added to timeout messagge (message visible only
+ *			with debug enabled)
+ * @param reg		Register that will be read (using readl())
+ * @param mask		Bit(s) of register that must be active
+ * @param set		Selects wait condition (bit set or clear)
+ * @param timeout	Timeout (in miliseconds)
+ * @param breakable	Enables CTRL-C interruption
+ * @return		0 on success, -ETIMEDOUT or -EINTR on failure
+ */
+int wait_for_bit(const char *prefix, u32 *reg, const u32 mask, bool set,
+		 unsigned int timeout, bool breakable);
+
+#endif
lib/Kconfig +4 -0
index 9d580e4..5977fc6 100644
@@ -137,6 +137,10 @@ config ERRNO_STR
 	  - if errno is null or positive number - a pointer to "Success" message
 	  - if errno is negative - a pointer to errno related message
 
+config LIB_WAIT_BIT
+	bool
+	default n
+
 source lib/efi/Kconfig
 
 endmenu
lib/Makefile +1 -0
index 1f1ff6f..437f937 100644
@@ -81,6 +81,7 @@ obj-y += time.o
 obj-$(CONFIG_TRACE) += trace.o
 obj-$(CONFIG_LIB_UUID) += uuid.o
 obj-$(CONFIG_LIB_RAND) += rand.o
+obj-$(CONFIG_LIB_WAIT_BIT) += wait_bit.o
 
 ifdef CONFIG_SPL_BUILD
 # SPL U-Boot may use full-printf, tiny-printf or none at all
lib/wait_bit.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.5.0
#3 lore raw

PATCH 2/5 usb: dwc2: Use shared wait_for_bit

In reply to Mateusz Kulikowski

Use existing library function to poll bit(s).
Update configs using dwc2.

---

 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(-)
drivers/usb/host/dwc2.c +16 -27
index 541c0f9..d1c9c45 100644
@@ -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;
 
include/configs/hikey.h +1 -0
index 796861e..4e3bfec 100644
@@ -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*/
include/configs/rpi-common.h +1 -0
index 1b83eb3..70d6123 100644
@@ -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
include/configs/socfpga_common.h +1 -0
index b3f65b6..47062cd 100644
@@ -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
 /*
Signature · 1 line
2.5.0
#7 lore raw

PATCH 3/5 usb: ohci-lpc32xx: Use shared wait_for_bit

In reply to Mateusz Kulikowski

Use existing library function to poll bit(s).
No config files are updated, as there is no board using this driver.

---

 drivers/usb/host/ohci-lpc32xx.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)
drivers/usb/host/ohci-lpc32xx.c +10 -26
index 48d338e..1101f6f 100644
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <errno.h>
+#include <wait_bit.h>
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/clk.h>
@@ -80,29 +81,9 @@ struct otg_regs {
 static struct otg_regs *otg = (struct otg_regs *)USB_BASE;
 static struct clk_pm_regs *clk_pwr = (struct clk_pm_regs *)CLK_PM_BASE;
 
-static int wait_for_bit(void *reg, const u32 mask, bool set)
-{
-	u32 val;
-	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) > CONFIG_SYS_HZ)
-			break;
-
-		udelay(1);
-	}
-
-	error("Timeout (reg=%p mask=%08x wait_set=%i)\n", reg, mask, set);
-
-	return -ETIMEDOUT;
-}
+#ifndef CONFIG_LIB_WAIT_BIT
+#error CONFIG_LIB_WAIT_BIT is required for ohci-lpc32xx driver
+#endif
 
 static int isp1301_set_value(int reg, u8 value)
 {
@@ -158,7 +139,8 @@ static int usbpll_setup(void)
 	setbits_le32(&clk_pwr->usb_ctrl, CLK_USBCTRL_POSTDIV_2POW(0x01));
 	setbits_le32(&clk_pwr->usb_ctrl, CLK_USBCTRL_PLL_PWRUP);
 
-	ret = wait_for_bit(&clk_pwr->usb_ctrl, CLK_USBCTRL_PLL_STS, 1);
+	ret = wait_for_bit(__func__, &clk_pwr->usb_ctrl, CLK_USBCTRL_PLL_STS,
+			   true, CONFIG_SYS_HZ, false);
 	if (ret)
 		return ret;
 
@@ -183,7 +165,8 @@ int usb_cpu_init(void)
 
 	/* enable I2C clock */
 	writel(OTG_CLK_I2C_EN, &otg->otg_clk_ctrl);
-	ret = wait_for_bit(&otg->otg_clk_sts, OTG_CLK_I2C_EN, 1);
+	ret = wait_for_bit(__func__, &otg->otg_clk_sts, OTG_CLK_I2C_EN, true,
+			   CONFIG_SYS_HZ, false);
 	if (ret)
 		return ret;
 
@@ -203,7 +186,8 @@ int usb_cpu_init(void)
 			 OTG_CLK_I2C_EN | OTG_CLK_HOST_EN;
 	writel(mask, &otg->otg_clk_ctrl);
 
-	ret = wait_for_bit(&otg->otg_clk_sts, mask, 1);
+	ret = wait_for_bit(__func__, &otg->otg_clk_sts, mask, true,
+			   CONFIG_SYS_HZ, false);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.5.0
#10 lore raw

PATCH 4/5 usb: ehci-mx6: Use shared wait_for_bit

In reply to Mateusz Kulikowski

Use existing library function to poll bit(s).
Update configs using ehci-mx6.

---

 drivers/usb/host/ehci-mx6.c           | 37 +++++++++--------------------------
 include/configs/aristainetos-common.h |  1 +
 include/configs/cgtqmx6eval.h         |  1 +
 include/configs/embestmx6boards.h     |  1 +
 include/configs/gw_ventana.h          |  1 +
 include/configs/mx6cuboxi.h           |  1 +
 include/configs/mx6qarm2.h            |  1 +
 include/configs/mx6qsabreauto.h       |  1 +
 include/configs/mx6sabresd.h          |  1 +
 include/configs/mx6slevk.h            |  1 +
 include/configs/mx6sxsabresd.h        |  1 +
 include/configs/mx6ul_14x14_evk.h     |  1 +
 include/configs/nitrogen6x.h          |  1 +
 include/configs/novena.h              |  1 +
 include/configs/ot1200.h              |  1 +
 include/configs/platinum.h            |  1 +
 include/configs/tbs2910.h             |  1 +
 include/configs/titanium.h            |  1 +
 include/configs/tqma6.h               |  1 +
 include/configs/wandboard.h           |  1 +
 include/configs/warp.h                |  1 +
 21 files changed, 29 insertions(+), 28 deletions(-)
drivers/usb/host/ehci-mx6.c +9 -28
index 2666351..ed269be 100644
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <usb.h>
 #include <errno.h>
+#include <wait_bit.h>
 #include <linux/compiler.h>
 #include <usb/ehci-fsl.h>
 #include <asm/io.h>
@@ -57,6 +58,11 @@
 #define UCMD_RESET		(1 << 1) /* controller reset */
 
 #if defined(CONFIG_MX6)
+
+#ifndef CONFIG_LIB_WAIT_BIT
+#error CONFIG_LIB_WAIT_BIT is required for ehci-mx6 driver
+#endif
+
 static const unsigned phy_bases[] = {
 	USB_PHY0_BASE_ADDR,
 	USB_PHY1_BASE_ADDR,
@@ -117,32 +123,6 @@ 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)
 {
@@ -160,12 +140,13 @@ static int usb_phy_enable(int index, struct usb_ehci *ehci)
 
 	/* Stop then Reset */
 	clrbits_le32(usb_cmd, UCMD_RUN_STOP);
-	ret = wait_for_bit(usb_cmd, UCMD_RUN_STOP, 0);
+	ret = wait_for_bit(__func__, usb_cmd, UCMD_RUN_STOP, false, 10000,
+			   false);
 	if (ret)
 		return ret;
 
 	setbits_le32(usb_cmd, UCMD_RESET);
-	ret = wait_for_bit(usb_cmd, UCMD_RESET, 0);
+	ret = wait_for_bit(__func__, usb_cmd, UCMD_RESET, false, 10000, false);
 	if (ret)
 		return ret;
 
include/configs/aristainetos-common.h +1 -0
index 0b97ccc..c97c352 100644
@@ -218,6 +218,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_MAX_CONTROLLER_COUNT 2
include/configs/cgtqmx6eval.h +1 -0
index 487c011..380e1c8 100644
@@ -75,6 +75,7 @@
 #define CONFIG_CMD_USB
 #define CONFIG_CMD_FAT
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/embestmx6boards.h +1 -0
index 90cd959..feaa78e 100644
@@ -41,6 +41,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_HOST_ETHER
include/configs/gw_ventana.h +1 -0
index b7b9c78..b672aab 100644
@@ -178,6 +178,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_HOST_ETHER
include/configs/mx6cuboxi.h +1 -0
index 4feb121..8363b27 100644
@@ -58,6 +58,7 @@
 /* USB */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/mx6qarm2.h +1 -0
index 86a0316..588eb76 100644
@@ -135,6 +135,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/mx6qsabreauto.h +1 -0
index 1c99805..641a5bc 100644
@@ -18,6 +18,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_HOST_ETHER
include/configs/mx6sabresd.h +1 -0
index bfc4f61..66b9405 100644
@@ -58,6 +58,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/mx6slevk.h +1 -0
index 6937924..23938ac 100644
@@ -182,6 +182,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/mx6sxsabresd.h +1 -0
index 0aec296..8f967d5 100644
@@ -158,6 +158,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/mx6ul_14x14_evk.h +1 -0
index 2712b27..1afefd4 100644
@@ -211,6 +211,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/nitrogen6x.h +1 -0
index 3416ce3..0d72e0b 100644
@@ -84,6 +84,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_HOST_ETHER
include/configs/novena.h +1 -0
index 4b4f2d7..3371ced 100644
@@ -153,6 +153,7 @@
 /* USB Configs */
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_KEYBOARD
include/configs/ot1200.h +1 -0
index 879ad58..5b5ec9f 100644
@@ -61,6 +61,7 @@
 #define CONFIG_CMD_USB
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_MXC_USB_PORTSC   (PORT_PTS_UTMI | PORT_PTS_PTW)
 #define CONFIG_USB_MAX_CONTROLLER_COUNT 2
include/configs/platinum.h +1 -0
index bb7e845..94ab45d 100644
@@ -63,6 +63,7 @@
 
 /* USB config */
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_MXC_USB_PORT			1
include/configs/tbs2910.h +1 -0
index 17b0213..f3b2f60 100644
@@ -122,6 +122,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_MAX_CONTROLLER_COUNT 2
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
include/configs/titanium.h +1 -0
index acfa84a..1d4b143 100644
@@ -57,6 +57,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_MXC_USB_PORT	1
include/configs/tqma6.h +1 -0
index 31d7757..7ac6032 100644
@@ -93,6 +93,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_HOST_ETHER
include/configs/wandboard.h +1 -0
index 4c8e9e9..8ecf8df 100644
@@ -50,6 +50,7 @@
 /* USB Configs */
 #define CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_USB_MAX_CONTROLLER_COUNT	2
include/configs/warp.h +1 -0
index 3e9a5a3..e2ebc86 100644
@@ -66,6 +66,7 @@
 #define CONFIG_CMD_USB
 #ifdef CONFIG_CMD_USB
 #define CONFIG_USB_EHCI
+#define CONFIG_LIB_WAIT_BIT
 #define CONFIG_USB_EHCI_MX6
 #define CONFIG_USB_STORAGE
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
Signature · 1 line
2.5.0
#11 lore raw

PATCH 5/5 net: zynq_gem: Use shared wait_for_bit

In reply to Mateusz Kulikowski

Use existing library function to poll bit(s).

---

 drivers/net/Kconfig    |  1 +
 drivers/net/zynq_gem.c | 35 ++---------------------------------
 2 files changed, 3 insertions(+), 33 deletions(-)
drivers/net/Kconfig +1 -0
index 6905cc0..890e6c1 100644
@@ -103,6 +103,7 @@ config PCH_GBE
 
 config ZYNQ_GEM
 	depends on DM_ETH && (ARCH_ZYNQ || ARCH_ZYNQMP)
+	select LIB_WAIT_BIT
 	bool "Xilinx Ethernet GEM"
 	help
 	  This MAC is presetn in Xilinx Zynq and ZynqMP SoCs.
drivers/net/zynq_gem.c +2 -33
index 0a41281..430c2a4 100644
@@ -19,6 +19,7 @@
 #include <asm/io.h>
 #include <phy.h>
 #include <miiphy.h>
+#include <wait_bit.h>
 #include <watchdog.h>
 #include <asm/system.h>
 #include <asm/arch/hardware.h>
@@ -452,38 +453,6 @@ static int zynq_gem_init(struct udevice *dev)
 	return 0;
 }
 
-static int wait_for_bit(const char *func, u32 *reg, const u32 mask,
-			bool set, unsigned int timeout)
-{
-	u32 val;
-	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;
-
-		if (ctrlc()) {
-			puts("Abort\n");
-			return -EINTR;
-		}
-
-		udelay(1);
-	}
-
-	debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
-	      func, reg, mask, set);
-
-	return -ETIMEDOUT;
-}
-
 static int zynq_gem_send(struct udevice *dev, void *ptr, int len)
 {
 	u32 addr, size;
@@ -525,7 +494,7 @@ static int zynq_gem_send(struct udevice *dev, void *ptr, int len)
 		printf("TX buffers exhausted in mid frame\n");
 
 	return wait_for_bit(__func__, &regs->txsr, ZYNQ_GEM_TSR_DONE,
-			    true, 20000);
+			    true, 20000, true);
 }
 
 /* Do not check frame_recd flag in rx_status register 0x20 - just poll BD */
Signature · 1 line
2.5.0
#2 lore raw

PATCH 1/5 lib: Add wait_for_bit

In reply to Mateusz Kulikowski
Quoted 5 lines · Mateusz Kulikowski

Add function to poll register waiting for specific bit(s). Similar functions are implemented in few drivers - they are almost identical and can be generalized.

---

Excellent !

Quoted 7 lines
 include/wait_bit.h | 34 ++++++++++++++++++++++++++++++++++
 lib/Kconfig        |  4 ++++
 lib/Makefile       |  1 +
 lib/wait_bit.c     | 44 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+)
 create mode 100644 include/wait_bit.h
 create mode 100644 lib/wait_bit.c

[...]

Quoted 1 line

+int wait_for_bit(const char *prefix,

const u32 *

Quoted 1 line

u32 *reg, const u32 mask,

const bool, const unsigned int , const bool ;-)

Quoted 22 lines

bool set,

lib/wait_bit.c new file +20 -0
+		 unsigned int timeout, bool breakable)
 
+{
+	u32 val;
+	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;
+
+		if (breakable && ctrlc()) {
+			puts("Abort\n");
+			return -EINTR;

lib/wait_bit.c line 44

Quoted 10 lines
lib/wait_bit.c new file +10 -0
+		}
+
+		udelay(1);
+	}
+
+	debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", prefix, reg, mask,
+	      set);
+
+	return -ETIMEDOUT;
+}

Best regards,
Marek Vasut

#4 lore raw

PATCH 2/5 usb: dwc2: Use shared wait_for_bit

In reply to Mateusz Kulikowski
Quoted 5 lines · Mateusz Kulikowski

Use existing library function to poll bit(s).
Update configs using dwc2.

---

[...]

include/configs/hikey.h line 69

Quoted 9 lines
include/configs/hikey.h +1 -0
index 796861e..4e3bfec 100644
@@ -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.

include/configs/hikey.h line 72

Quoted 3 lines
include/configs/hikey.h +0 -0
 #define CONFIG_USB_DWC2
 #define CONFIG_USB_DWC2_REG_ADDR 0xF72C0000
 /*#define CONFIG_DWC2_DFLT_SPEED_FULL*/

[...]

Best regards,
Marek Vasut

#12 lore raw

cover Add wait_for_bit()

In reply to Mateusz Kulikowski
Quoted 22 lines

From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Mateusz Kulikowski
Sent: 14-Dec-15 7:09 PM
To: u-boot at lists.denx.de; Marek Vasut; Joe Hershberger
Subject: [U-Boot] [PATCH 0/5] Add wait_for_bit()

This series add generic function to poll register waiting for one or more bits to change.

Very similar function was used in several drivers:
- dwc2
- ohci-lp32xx
- ehci-mx6
- zynq_gem

First patch adds function, following patches update drivers and board config files / defconfigs.

This series was compile-tested with buildman for ~50 boards (most or even all boards affected by change)

Quoted 6 lines

Code was also run-tested on ehci-msm driver (not yet in mainline)

There is single difference in behavior: ohci-lp32xx driver will not print "Timeout..." message with debug disabled.
I think it's not a big issue as this driver seems unused, but if it's an issue - please drop that patch.

This is not an issue; the lpc32xx driver is used in our custom board based on u-boot 2015.10.

Quoted 2 lines

...

Quoted 7 lines

--
2.5.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de

________________________________

This e-mail contains privileged and confidential information intended for the use of the addressees named above. If you are not the intended recipient of this e-mail, you are hereby notified that you must not disseminate, copy or take any action in respect of any information contained in it. If you have received this e-mail in error, please notify the sender immediately by e-mail and immediately destroy this e-mail and its attachments.

#8 lore raw

PATCH 3/5 usb: ohci-lpc32xx: Use shared wait_for_bit

In reply to Mateusz Kulikowski
Quoted 8 lines

From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Mateusz Kulikowski
Sent: 14-Dec-15 7:09 PM
To: u-boot at lists.denx.de; Marek Vasut; Joe Hershberger
Subject: [U-Boot] [PATCH 3/5] usb: ohci-lpc32xx: Use shared wait_for_bit

Use existing library function to poll bit(s).
No config files are updated, as there is no board using this driver.

I tested the change using our custom lpc32xx board.

Quoted 7 lines

---

 drivers/usb/host/ohci-lpc32xx.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

...

________________________________

This e-mail contains privileged and confidential information intended for the use of the addressees named above. If you are not the intended recipient of this e-mail, you are hereby notified that you must not disseminate, copy or take any action in respect of any information contained in it. If you have received this e-mail in error, please notify the sender immediately by e-mail and immediately destroy this e-mail and its attachments.

#9 lore raw

PATCH 3/5 usb: ohci-lpc32xx: Use shared wait_for_bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Quoted 10 lines · SYLVAIN
Quoted 8 lines

From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Mateusz Kulikowski
Sent: 14-Dec-15 7:09 PM
To: u-boot at lists.denx.de; Marek Vasut; Joe Hershberger
Subject: [U-Boot] [PATCH 3/5] usb: ohci-lpc32xx: Use shared wait_for_bit

Use existing library function to poll bit(s).
No config files are updated, as there is no board using this driver.

I tested the change using our custom lpc32xx board.

Thanks!

Quoted 9 lines
Quoted 8 lines

---

 drivers/usb/host/ohci-lpc32xx.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)
Quoted 7 lines

...

________________________________

This e-mail contains privileged and confidential information intended for the use of the addressees named above. If you are not the intended recipient of this e-mail, you are hereby notified that you must not disseminate, copy or take any action in respect of any information contained in it. If you have received this e-mail in error, please notify the sender immediately by e-mail and immediately destroy this e-mail and its attachments.

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

iQEcBAEBCAAGBQJWcIP+AAoJELvtohmVtQzB6A0H/2bB0WFXSiaxoM1z52wRZQNM gqHEZs0Dj299h/wtwzOTUnnKxV1G2PA2WX6+SwiF9tf1JlNBlGJ6OwN6UJS0FIeA 2adqDzq7GJ0H9MrBjrMJJz1wASfG/2ryn+yFUjTBEwIb8Kjo1MBh3IiJv/HpHMif 1mLSLsvc3ukMKiJln/sXBZJEXIUT5uzP9OUt2ZPi2Yz7ujvD1Axhyntfx3xVpHZq tG6PIPB0cuT8mwxSBjZGOC+z9ppcCKuEEpLU5isXdTYVPkneOq7UaX+Ryebr2x2R so59vc1iXaBQoapglTi7asS8BEXPciBjSEzjodlgzlNVO+KVPCqItbaTq+GvTbo= =Znto
-----END PGP SIGNATURE-----

#5 lore raw

PATCH 2/5 usb: dwc2: Use shared wait_for_bit

In reply to Marek Vasut

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Quoted 1 line · Marek Vasut

On Tuesday, December 15, 2015 at 01:09:24 AM, Mateusz Kulikowski wrote:

[...]

Quoted 4 lines

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-----

#6 lore raw

PATCH 2/5 usb: dwc2: Use shared wait_for_bit

Quoted 10 lines · Mateusz Kulikowski
Quoted 1 line · Marek Vasut

On Tuesday, December 15, 2015 at 01:09:24 AM, Mateusz Kulikowski wrote:

[...]

Quoted 3 lines

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