All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ariel D'Alessandro <ariel.dalessandro@collabora.com>
To: u-boot@lists.denx.de
Cc: Peter.Hoyes@arm.com, aford173@gmail.com, alice.guo@nxp.com,
	andre.przywara@arm.com, andrey.zhizhikin@leica-geosystems.com,
	ariel.dalessandro@collabora.com, bmeng.cn@gmail.com,
	christian.gmeiner@gmail.com, christianshewitt@gmail.com,
	festevam@gmail.com, iliev@ronetix.at, jagan@amarulasolutions.com,
	jh80.chung@samsung.com, joe.hershberger@ni.com,
	kettenis@openbsd.org, kever.yang@rock-chips.com,
	kuldeep.singh@nxp.com, marcel.ziswiler@toradex.com,
	marex@denx.de, michael@amarulasolutions.com,
	michal.simek@xilinx.com, oliver.graute@kococonnector.com,
	pali@kernel.org, paul.liu@linaro.org, pbrobinson@gmail.com,
	peng.fan@nxp.com, philipp.tomsich@vrull.eu,
	priyanka.jain@nxp.com, radu-nicolae.pirea@oss.nxp.com,
	rath@ibv-augsburg.net, rfried.dev@gmail.com, samuel@sholland.org,
	sbabic@denx.de, simon.k.r.goldschmidt@gmail.com,
	sjg@chromium.org, stephan@gerhold.net, tharvey@gateworks.com,
	tien.fong.chee@intel.com, uboot-imx@nxp.com,
	vladimir.oltean@nxp.com, wd@denx.de, xypron.glpk@gmx.de,
	ye.li@nxp.com
Subject: [PATCH v5 4/7] iopoll: Extend read_poll_timeout macro to support variable parameters
Date: Tue, 12 Apr 2022 10:31:35 -0300	[thread overview]
Message-ID: <20220412133138.110815-5-ariel.dalessandro@collabora.com> (raw)
In-Reply-To: <20220412133138.110815-1-ariel.dalessandro@collabora.com>

This macro currently supports only one parameter. Based on Linux iopoll,
let's extend read_poll_timeout common API to allow multiple variable
parameters.

Signed-off-by: Ariel D'Alessandro <ariel.dalessandro@collabora.com>
---
 arch/arm/mach-socfpga/reset_manager_s10.c | 20 +++++++++++---------
 drivers/mmc/rockchip_sdhci.c              |  9 +++++----
 include/linux/iopoll.h                    | 12 ++++++------
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-socfpga/reset_manager_s10.c b/arch/arm/mach-socfpga/reset_manager_s10.c
index d2337bd4d62..f47fec10a0c 100644
--- a/arch/arm/mach-socfpga/reset_manager_s10.c
+++ b/arch/arm/mach-socfpga/reset_manager_s10.c
@@ -80,9 +80,9 @@ void socfpga_bridges_reset(int enable)
 			     ~0);
 
 		/* Poll until all idleack to 0 */
-		read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
-				  SYSMGR_SOC64_NOC_IDLEACK, reg, !reg, 1000,
-				  300000);
+		read_poll_timeout(readl, reg, !reg, 1000, 300000,
+				  socfpga_get_sysmgr_addr() +
+				  SYSMGR_SOC64_NOC_IDLEACK);
 	} else {
 		/* set idle request to all bridges */
 		writel(~0,
@@ -93,18 +93,20 @@ void socfpga_bridges_reset(int enable)
 		writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
 
 		/* Poll until all idleack to 1 */
-		read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
-				  SYSMGR_SOC64_NOC_IDLEACK, reg,
+		read_poll_timeout(readl, reg,
 				  reg == (SYSMGR_NOC_H2F_MSK |
 					  SYSMGR_NOC_LWH2F_MSK),
-				  1000, 300000);
+				  1000, 300000,
+				  socfpga_get_sysmgr_addr() +
+				  SYSMGR_SOC64_NOC_IDLEACK);
 
 		/* Poll until all idlestatus to 1 */
-		read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
-				  SYSMGR_SOC64_NOC_IDLESTATUS, reg,
+		read_poll_timeout(readl, reg,
 				  reg == (SYSMGR_NOC_H2F_MSK |
 					  SYSMGR_NOC_LWH2F_MSK),
-				  1000, 300000);
+				  1000, 300000,
+				  socfpga_get_sysmgr_addr() +
+				  SYSMGR_SOC64_NOC_IDLESTATUS);
 
 		/* Reset all bridges (except NOR DDR scheduler & F2S) */
 		setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c
index f3f9d83ba36..1fdc8415178 100644
--- a/drivers/mmc/rockchip_sdhci.c
+++ b/drivers/mmc/rockchip_sdhci.c
@@ -202,8 +202,8 @@ static void rk3399_emmc_phy_power_on(struct rockchip_emmc_phy *phy, u32 clock)
 	/* REN Enable on STRB Line for HS400 */
 	writel(RK_CLRSETBITS(0, 1 << 9), &phy->emmcphy_con[2]);
 
-	read_poll_timeout(readl, &phy->emmcphy_status, dllrdy,
-			  PHYCTRL_DLL_LOCK_WO_TMOUT(dllrdy), 1, 5000);
+	read_poll_timeout(readl, dllrdy, PHYCTRL_DLL_LOCK_WO_TMOUT(dllrdy), 1,
+			  5000, &phy->emmcphy_status);
 }
 
 static void rk3399_emmc_phy_power_off(struct rockchip_emmc_phy *phy)
@@ -328,8 +328,9 @@ static int rk3568_sdhci_emmc_set_clock(struct sdhci_host *host, unsigned int clo
 			DWCMSHC_EMMC_DLL_START;
 		sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_CTRL);
 
-		ret = read_poll_timeout(readl, host->ioaddr + DWCMSHC_EMMC_DLL_STATUS0,
-					val, DLL_LOCK_WO_TMOUT(val), 1, 500);
+		ret = read_poll_timeout(readl, val, DLL_LOCK_WO_TMOUT(val), 1,
+					500,
+					host->ioaddr + DWCMSHC_EMMC_DLL_STATUS0);
 		if (ret)
 			return ret;
 
diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index 30cdea0cdc1..0ee2bddaa83 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -14,11 +14,11 @@
 /**
  * read_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
  * @op: accessor function (takes @addr as its only argument)
- * @addr: Address to poll
  * @val: Variable to read the value into
  * @cond: Break condition (usually involving @val)
  * @sleep_us: Maximum time to sleep in us
  * @timeout_us: Timeout in us, 0 means never timeout
+ * @args: arguments for @op poll
  *
  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
  * case, the last read value at @addr is stored in @val.
@@ -26,15 +26,15 @@
  * When available, you'll probably want to use one of the specialized
  * macros defined below rather than this macro directly.
  */
-#define read_poll_timeout(op, addr, val, cond, sleep_us, timeout_us)	\
+#define read_poll_timeout(op, val, cond, sleep_us, timeout_us, args...)	\
 ({ \
 	unsigned long timeout = timer_get_us() + timeout_us; \
 	for (;;) { \
-		(val) = op(addr); \
+		(val) = op(args); \
 		if (cond) \
 			break; \
 		if (timeout_us && time_after(timer_get_us(), timeout)) { \
-			(val) = op(addr); \
+			(val) = op(args); \
 			break; \
 		} \
 		if (sleep_us) \
@@ -44,13 +44,13 @@
 })
 
 #define readx_poll_sleep_timeout(op, addr, val, cond, sleep_us, timeout_us) \
-	read_poll_timeout(op, addr, val, cond, sleep_us, timeout_us)
+	read_poll_timeout(op, val, cond, sleep_us, timeout_us, addr)
 
 #define readl_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \
 	readx_poll_sleep_timeout(readl, addr, val, cond, sleep_us, timeout_us)
 
 #define readx_poll_timeout(op, addr, val, cond, timeout_us) \
-	read_poll_timeout(op, addr, val, cond, false, timeout_us)
+	read_poll_timeout(op, val, cond, false, timeout_us, addr)
 
 #define readb_poll_timeout(addr, val, cond, timeout_us) \
 	readx_poll_timeout(readb, addr, val, cond, timeout_us)
-- 
2.34.1


  parent reply	other threads:[~2022-04-12 13:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 13:31 [PATCH v5 0/7] imx8mn-smm-s2/pro: Add iMX8MN BSH SMM S2 boards Ariel D'Alessandro
2022-04-12 13:31 ` [PATCH v5 1/7] imx8m: add regs used by GPMI Ariel D'Alessandro
2022-04-12 18:47   ` sbabic
2022-04-12 13:31 ` [PATCH v5 2/7] imx8m: add init_nand_clk Ariel D'Alessandro
2022-04-12 18:46   ` sbabic
2022-04-12 13:31 ` [PATCH v5 3/7] phy: nxp-c45-tja11xx: Rename functions to be c45 tja11xx specific Ariel D'Alessandro
2022-04-12 18:46   ` sbabic
2022-04-12 13:31 ` Ariel D'Alessandro [this message]
2022-04-12 18:45   ` [PATCH v5 4/7] iopoll: Extend read_poll_timeout macro to support variable parameters sbabic
2022-04-12 13:31 ` [PATCH v5 5/7] net: phy: Add phy_modify() accessor Ariel D'Alessandro
2022-04-12 18:43   ` sbabic
2022-04-12 13:31 ` [PATCH v5 6/7] net: phy: nxp-tja11xx: Add NXP TJA11xx PHY driver Ariel D'Alessandro
2022-04-12 18:45   ` sbabic
2022-04-12 13:31 ` [PATCH v5 7/7] bsh: imx8mn-smm-s2/pro: Add iMX8MN BSH SMM S2 boards Ariel D'Alessandro
2022-04-12 18:46   ` sbabic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220412133138.110815-5-ariel.dalessandro@collabora.com \
    --to=ariel.dalessandro@collabora.com \
    --cc=Peter.Hoyes@arm.com \
    --cc=aford173@gmail.com \
    --cc=alice.guo@nxp.com \
    --cc=andre.przywara@arm.com \
    --cc=andrey.zhizhikin@leica-geosystems.com \
    --cc=bmeng.cn@gmail.com \
    --cc=christian.gmeiner@gmail.com \
    --cc=christianshewitt@gmail.com \
    --cc=festevam@gmail.com \
    --cc=iliev@ronetix.at \
    --cc=jagan@amarulasolutions.com \
    --cc=jh80.chung@samsung.com \
    --cc=joe.hershberger@ni.com \
    --cc=kettenis@openbsd.org \
    --cc=kever.yang@rock-chips.com \
    --cc=kuldeep.singh@nxp.com \
    --cc=marcel.ziswiler@toradex.com \
    --cc=marex@denx.de \
    --cc=michael@amarulasolutions.com \
    --cc=michal.simek@xilinx.com \
    --cc=oliver.graute@kococonnector.com \
    --cc=pali@kernel.org \
    --cc=paul.liu@linaro.org \
    --cc=pbrobinson@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=priyanka.jain@nxp.com \
    --cc=radu-nicolae.pirea@oss.nxp.com \
    --cc=rath@ibv-augsburg.net \
    --cc=rfried.dev@gmail.com \
    --cc=samuel@sholland.org \
    --cc=sbabic@denx.de \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=sjg@chromium.org \
    --cc=stephan@gerhold.net \
    --cc=tharvey@gateworks.com \
    --cc=tien.fong.chee@intel.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=wd@denx.de \
    --cc=xypron.glpk@gmx.de \
    --cc=ye.li@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.