From patchwork Fri Jan 27 10:28:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 9540955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 32E7660415 for ; Fri, 27 Jan 2017 10:29:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 254F527D4D for ; Fri, 27 Jan 2017 10:29:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A37827FC0; Fri, 27 Jan 2017 10:29:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9CA2827D4D for ; Fri, 27 Jan 2017 10:29:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cX3mh-0002ki-F6; Fri, 27 Jan 2017 10:29:35 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cX3m4-00022l-RN; Fri, 27 Jan 2017 10:29:00 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80CE58051A; Fri, 27 Jan 2017 10:28:36 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0RASYdL021151; Fri, 27 Jan 2017 05:28:34 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 3C5E680E6D; Fri, 27 Jan 2017 11:28:32 +0100 (CET) Message-ID: <1485512912.19754.60.camel@redhat.com> Subject: Re: [PATCH 01/13] mmc: bcm2835: add bcm2835_read_wait_sdcmd From: Gerd Hoffmann To: Shawn Lin Date: Fri, 27 Jan 2017 11:28:32 +0100 In-Reply-To: References: <1485473846-24537-1-git-send-email-kraxel@redhat.com> <1485473846-24537-2-git-send-email-kraxel@redhat.com> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 27 Jan 2017 10:28:36 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170127_022857_200835_3F5310F0 X-CRM114-Status: GOOD ( 18.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Ulf Hansson , Florian Fainelli , Scott Branden , Stephen Warren , Ray Jui , Lee Jones , linux-mmc@vger.kernel.org, open list , Eric Anholt , "maintainer:BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITE..." , linux-rpi-kernel@lists.infradead.org, "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, > > + for (;;) { > > + value = readl(host->ioaddr + SDCMD); > > + if (!(value & SDCMD_NEW_FLAG)) > > + break; > > + if (check_fail && (value & SDCMD_FAIL_FLAG)) > > + break; > > + if (time_after(jiffies, end)) { > > + dev_err(dev, "%s: timeout (%d us)\n", > > + __func__, timeout); > > + break; > > + } > > + > > + /* if it takes longer reduce poll interval */ > > + if (time_after(jiffies, fastpoll)) > > + udelay(10); > > + else > > + cpu_relax(); > > + } > > Use readl_poll_timeout intead of open-coding them.. Cool. Didn't know this exists. Incremental fixup attached. thanks, Gerd From de60d73849d83b0ddf4ee8bd6a7e175c69157a90 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 27 Jan 2017 11:25:54 +0100 Subject: [PATCH] mmc: bcm2835: use readl_poll_timeout in bcm2835_read_wait_sdcmd Signed-off-by: Gerd Hoffmann --- drivers/mmc/host/bcm2835.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c index 64a2334..e8a3f6e 100644 --- a/drivers/mmc/host/bcm2835.c +++ b/drivers/mmc/host/bcm2835.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -609,33 +610,27 @@ static void bcm2835_prepare_data(struct bcm2835_host *host, writel(data->blocks, host->ioaddr + SDHBLC); } -static u32 bcm2835_read_wait_sdcmd(struct bcm2835_host *host, u32 timeout, +static u32 bcm2835_read_wait_sdcmd(struct bcm2835_host *host, u32 max_ms, bool check_fail) { struct device *dev = &host->pdev->dev; - unsigned long start = jiffies; - unsigned long fastpoll = start + usecs_to_jiffies(10); - unsigned long end = start + msecs_to_jiffies(timeout); u32 value; + int ret; - for (;;) { - value = readl(host->ioaddr + SDCMD); - if (!(value & SDCMD_NEW_FLAG)) - break; - if (check_fail && (value & SDCMD_FAIL_FLAG)) - break; - if (time_after(jiffies, end)) { - dev_err(dev, "%s: timeout (%d us)\n", - __func__, timeout); - break; - } + ret = readl_poll_timeout(host->ioaddr + SDCMD, value, + (!(value & SDCMD_NEW_FLAG)) || + (check_fail && (value & SDCMD_FAIL_FLAG)), + 1, 10); + if (ret == -ETIMEDOUT) + /* if it takes a while make poll interval bigger */ + ret = readl_poll_timeout(host->ioaddr + SDCMD, value, + (!(value & SDCMD_NEW_FLAG)) || + (check_fail && (value & SDCMD_FAIL_FLAG)), + 10, max_ms * 1000); + if (ret == -ETIMEDOUT) + dev_err(dev, "%s: timeout (%d ms)\n", + __func__, max_ms); - /* if it takes longer reduce poll interval */ - if (time_after(jiffies, fastpoll)) - udelay(10); - else - cpu_relax(); - } return value; } -- 1.8.3.1