From patchwork Fri Jan 13 15:09:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Antipov X-Patchwork-Id: 6185 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 32BDF23E01 for ; Fri, 13 Jan 2012 15:08:51 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 21CB1A18812 for ; Fri, 13 Jan 2012 15:08:51 +0000 (UTC) Received: by bkbzu5 with SMTP id zu5so2929353bkb.11 for ; Fri, 13 Jan 2012 07:08:50 -0800 (PST) Received: by 10.204.152.20 with SMTP id e20mr569755bkw.117.1326467330796; Fri, 13 Jan 2012 07:08:50 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs31889bkc; Fri, 13 Jan 2012 07:08:50 -0800 (PST) Received: by 10.180.99.232 with SMTP id et8mr585708wib.8.1326467330276; Fri, 13 Jan 2012 07:08:50 -0800 (PST) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id p55si5951327eeh.39.2012.01.13.07.08.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Jan 2012 07:08:50 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) smtp.mail=dmitry.antipov@linaro.org Received: by bkcjk14 with SMTP id jk14so2891537bkc.37 for ; Fri, 13 Jan 2012 07:08:49 -0800 (PST) Received: by 10.204.128.130 with SMTP id k2mr621529bks.7.1326467329102; Fri, 13 Jan 2012 07:08:49 -0800 (PST) Received: from localhost.localdomain ([78.153.153.8]) by mx.google.com with ESMTPS id fg16sm18600077bkb.16.2012.01.13.07.08.47 (version=SSLv3 cipher=OTHER); Fri, 13 Jan 2012 07:08:48 -0800 (PST) From: Dmitry Antipov To: Chris Ball Cc: patches@linaro.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH] mmc: change mmc_delay() to use usleep_range() Date: Fri, 13 Jan 2012 19:09:30 +0400 Message-Id: <1326467370-21026-1-git-send-email-dmitry.antipov@linaro.org> X-Mailer: git-send-email 1.7.7.5 Use the usleep_range() to simplify mmc_delay() and give some more accuracy to it - but with an exception of mmc_card_sleepawake(): since sleep/awake timeout varies in a wide range, different delay methods should be used. Signed-off-by: Dmitry Antipov --- drivers/mmc/core/core.h | 8 ++------ drivers/mmc/core/mmc_ops.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 14664f1..a77851e 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -47,12 +47,8 @@ void mmc_power_off(struct mmc_host *host); static inline void mmc_delay(unsigned int ms) { - if (ms < 1000 / HZ) { - cond_resched(); - mdelay(ms); - } else { - msleep(ms); - } + unsigned long us = ms * USEC_PER_MSEC; + usleep_range(us, us + 1000); } void mmc_rescan(struct work_struct *work); diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 4d41fa9..38d53ac 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -82,9 +82,15 @@ int mmc_card_sleepawake(struct mmc_host *host, int sleep) * SEND_STATUS command to poll the status because that command (and most * others) is invalid while the card sleeps. */ - if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) - mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); - + if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) { + /* JEDEC MMCA 4.41 specifies the timeout value is in 200ns..838.86ms + range. Round it up to 1us and use an appropriate delay method. */ + unsigned long us = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10); + if (us < 10) + udelay(us); + else + usleep_range(us, us + 100); + } if (!sleep) err = mmc_select_card(card);