From patchwork Fri Mar 4 12:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ariel D'Alessandro X-Patchwork-Id: 1601027 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=LwhFv98i; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K97vQ2pSSz9sG9 for ; Sat, 5 Mar 2022 00:27:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EAC883D05; Fri, 4 Mar 2022 14:27:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="LwhFv98i"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C788E83D3D; Fri, 4 Mar 2022 13:23:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3353A83CE4 for ; Fri, 4 Mar 2022 13:23:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ariel.dalessandro@collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: adalessandro) with ESMTPSA id A3F091F466C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1646396629; bh=qGssVlPVqYSBKilWfV5Elu0ua0CrG3A6Dz/StQpWBVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwhFv98iKnIb8NBZQIwY7sEpFIAgyk8Ko6Lw5ifHg8o7r1PitshZNnS9lhaiw6qZV DCpPhXyIP8H9t8BSVX4V+yEVLUZaX/eVu8TcI93Lj5nkJmTBOxokGQ+7aY/WMx7gjc N8raCLFbvyauPg+vjOQssE7+ai/U5bTOvYIwpIO3AuibKfoO9yrJ5EMKYvgzSXInMo 2K+m9YJouYwI5VrJ043bovMaO/B+8t+CVP3w7bj3/ChYC//+xe69C5Ns+hRBkxKTHz 8pXOthhPaES3/Nw1/S6/d3nML58Tk99iY8mVohktWAe2AGIpUzt31UBJ0iW2D02FKi BPBf+mkMWp6rA== From: Ariel D'Alessandro 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 v4 3/6] iopoll: Extend read_poll_timeout macro to support variable parameters Date: Fri, 4 Mar 2022 09:22:25 -0300 Message-Id: <20220304122228.71412-4-ariel.dalessandro@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220304122228.71412-1-ariel.dalessandro@collabora.com> References: <20220304122228.71412-1-ariel.dalessandro@collabora.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Mar 2022 14:27:07 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 --- 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 278473899c7..87f14b0ee9c 100644 --- a/drivers/mmc/rockchip_sdhci.c +++ b/drivers/mmc/rockchip_sdhci.c @@ -146,8 +146,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) @@ -235,8 +235,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)