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: 720571 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v8w5F4vpvz9t8j for ; Fri, 27 Jan 2017 21:29:37 +1100 (AEDT) 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-J3; 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-Spam-Score: -10.1 (----------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-10.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [209.132.183.28 listed in list.dnswl.org] -3.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list 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+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org 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