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: 9540989 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 9465B601D7 for ; Fri, 27 Jan 2017 10:41:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AD9E28324 for ; Fri, 27 Jan 2017 10:41:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F82328329; Fri, 27 Jan 2017 10:41:17 +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=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36D112807B for ; Fri, 27 Jan 2017 10:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932590AbdA0KjB (ORCPT ); Fri, 27 Jan 2017 05:39:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42440 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932444AbdA0KiT (ORCPT ); Fri, 27 Jan 2017 05:38:19 -0500 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 Cc: linux-rpi-kernel@lists.infradead.org, Stefan Wahren , Eric Anholt , Ulf Hansson , linux-mmc@vger.kernel.org, Florian Fainelli , Ray Jui , Scott Branden , "maintainer:BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITE..." , Stephen Warren , Lee Jones , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" , open list 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) Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.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