From patchwork Thu Jan 26 23:37:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 9540351 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 8392860429 for ; Thu, 26 Jan 2017 23:39:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A02528305 for ; Thu, 26 Jan 2017 23:39:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ED612830A; Thu, 26 Jan 2017 23:39:11 +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 autolearn=ham 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 2B5DF28305 for ; Thu, 26 Jan 2017 23:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753001AbdAZXhq (ORCPT ); Thu, 26 Jan 2017 18:37:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60060 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752513AbdAZXhn (ORCPT ); Thu, 26 Jan 2017 18:37:43 -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 33C607F342; Thu, 26 Jan 2017 23:37:32 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-57.ams2.redhat.com [10.36.116.57]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0QNbU6C014496; Thu, 26 Jan 2017 18:37:31 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id B110D80F6D; Fri, 27 Jan 2017 00:37:28 +0100 (CET) From: Gerd Hoffmann To: linux-rpi-kernel@lists.infradead.org Cc: Stefan Wahren , Eric Anholt , Ulf Hansson , linux-mmc@vger.kernel.org, Gerd Hoffmann , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com (maintainer:BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITE...), Stephen Warren , Lee Jones , linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 01/13] mmc: bcm2835: add bcm2835_read_wait_sdcmd Date: Fri, 27 Jan 2017 00:37:14 +0100 Message-Id: <1485473846-24537-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1485473846-24537-1-git-send-email-kraxel@redhat.com> References: <1485473846-24537-1-git-send-email-kraxel@redhat.com> 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.26]); Thu, 26 Jan 2017 23:37:32 +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 Signed-off-by: Gerd Hoffmann --- drivers/mmc/host/bcm2835.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c index 9744517..ceee4cf 100644 --- a/drivers/mmc/host/bcm2835.c +++ b/drivers/mmc/host/bcm2835.c @@ -609,6 +609,36 @@ 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, + 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; + + 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(); + } + return value; +} + bool bcm2835_send_command(struct bcm2835_host *host, struct mmc_command *cmd) {