public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Scott Branden <sbranden@broadcom.com>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Ray Jui <rjui@broadcom.com>, Lee Jones <lee@kernel.org>,
	linux-mmc@vger.kernel.org,
	open list <linux-kernel@vger.kernel.org>,
	Eric Anholt <eric@anholt.net>,
	"maintainer:BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITE..."
	<bcm-kernel-feedback-list@broadcom.com>,
	linux-rpi-kernel@lists.infradead.org,
	"moderated list:BROADCOM BCM2835 ARM ARCHITECTURE"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 01/13] mmc: bcm2835: add bcm2835_read_wait_sdcmd
Date: Fri, 27 Jan 2017 11:28:32 +0100	[thread overview]
Message-ID: <1485512912.19754.60.camel@redhat.com> (raw)
In-Reply-To: <ff0170ef-2566-1c12-0b27-dccb3bff2e7e@rock-chips.com>

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

  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


[-- Attachment #2: Type: text/x-patch, Size: 2245 bytes --]

From de60d73849d83b0ddf4ee8bd6a7e175c69157a90 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
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 <kraxel@redhat.com>
---
 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 <linux/err.h>
 #include <linux/highmem.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
@@ -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


[-- Attachment #3: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2017-01-27 10:28 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 23:37 [PATCH 00/13] mmc: bcm2835: more cleanups Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 01/13] mmc: bcm2835: add bcm2835_read_wait_sdcmd Gerd Hoffmann
2017-01-26 23:51   ` Florian Fainelli
2017-01-27  8:04     ` Gerd Hoffmann
2017-01-27 18:23       ` Florian Fainelli
2017-02-15 10:59         ` Jeremy McNicoll
2017-01-27  2:03   ` Shawn Lin
2017-01-27 10:28     ` Gerd Hoffmann [this message]
2017-01-26 23:37 ` [PATCH 02/13] mmc: bcm2835: use bcm2835_read_wait_sdcmd in bcm2835_send_command Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 03/13] mmc: bcm2835: add bcm2835_threaded_irq Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 04/13] mmc: bcm2835: add bcm2835_check_data_error Gerd Hoffmann
2017-01-27  2:05   ` Shawn Lin
2017-01-27 10:31     ` Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 05/13] mmc: bcm2835: call bcm2835_block_irq from irqthread Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 06/13] mmc: bcm2835: add bcm2835_check_cmd_error Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 07/13] mmc: bcm2835: call bcm2835_busy_irq from irqthread Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 08/13] mmc: bcm2835: split bcm2835_data_irq Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 09/13] mmc: bcm2835: switch locking to mutex Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 10/13] mmc: bcm2835: work queue is dead code now, zap Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 11/13] mmc: bcm2835: kill tasklet Gerd Hoffmann
2017-01-26 23:37 ` [PATCH 12/13] mmc: bcm2835: move timeout to thread context Gerd Hoffmann
2017-01-27  2:08   ` Shawn Lin
2017-01-26 23:37 ` [PATCH 13/13] mmc: bcm2835: use bcm2835_read_wait_sdcmd in bcm2835_finish_command Gerd Hoffmann
     [not found] ` <1485473846-24537-1-git-send-email-kraxel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-01-27  8:25   ` [PATCH 00/13] mmc: bcm2835: more cleanups Ulf Hansson
     [not found]     ` <CAPDyKFoOShjQC8MbaxEuPG9m5FiSEfEd55qph3UDRHXH7C6VWA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-27 17:52       ` Eric Anholt

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=1485512912.19754.60.camel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=shawn.lin@rock-chips.com \
    --cc=stefan.wahren@i2se.com \
    --cc=swarren@wwwdotorg.org \
    --cc=ulf.hansson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox