From patchwork Tue May 13 01:38:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Rao X-Patchwork-Id: 4162101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3091E9F1C0 for ; Tue, 13 May 2014 01:41:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 46F002035C for ; Tue, 13 May 2014 01:41:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B3BB20357 for ; Tue, 13 May 2014 01:41:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wk1gh-00028k-Cu; Tue, 13 May 2014 01:39:23 +0000 Received: from mail-pb0-f74.google.com ([209.85.160.74]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wk1ge-000250-Bp for linux-arm-kernel@lists.infradead.org; Tue, 13 May 2014 01:39:21 +0000 Received: by mail-pb0-f74.google.com with SMTP id rp16so92930pbb.3 for ; Mon, 12 May 2014 18:38:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eCHiRKkEGFnUFhDZCwT9AyGHneZpvx/05whE93t60mc=; b=BhfDkoY2RdgwYWd+ES22aQYu04OjFRFK8xeGlD6uSLCbeJWT8n11kV5cMQPJMDeIU/ uewg0x61WSFGdlINBdzxWCx+LHkhaJoY1/m1sZ3k4hpiSepdQF7fOHCOqdat7z273iQf rsMW8Ue6dx1y0PDwUZkWw4COz0BrsN7W7Ffj0+V9v5KSF+1eUqjm3Us2gH+hynstsEND qJmQ52A4PBBB2cl04BimqxrI/Bc7781k86VymnMo3cmv8wFw5I2clo5CdqJVsfGFRxHi 8OgHm7LthazuuBrGldMJGJSk0yUjdit+qQfMyl7L74KdPHmQoKNLqlW9XQr1acszC6PY Y5AQ== X-Gm-Message-State: ALoCoQmtg/blX8IEtOBkb63OBz4vQw2lQdH6LJYnQYj2FnLLwuKEaDpZstEwrh+lBXpQyu/o6hTS X-Received: by 10.66.163.33 with SMTP id yf1mr13716163pab.19.1399945139508; Mon, 12 May 2014 18:38:59 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id l7si707005yho.1.2014.05.12.18.38.59 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 May 2014 18:38:59 -0700 (PDT) Received: from sonnyrao.mtv.corp.google.com (sonnyrao.mtv.corp.google.com [172.22.72.76]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 12D4531C1BD; Mon, 12 May 2014 18:38:59 -0700 (PDT) Received: by sonnyrao.mtv.corp.google.com (Postfix, from userid 129445) id B0781A0920; Mon, 12 May 2014 18:38:58 -0700 (PDT) From: Sonny Rao To: linux-mmc@vger.kernel.org Subject: [PATCHv2] mmc: dw_mmc: change to use recommended reset procedure Date: Mon, 12 May 2014 18:38:41 -0700 Message-Id: <1399945121-7387-1-git-send-email-sonnyrao@chromium.org> X-Mailer: git-send-email 1.9.1.423.g4596e3a X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140512_183920_428163_146EBBE9 X-CRM114-Status: GOOD ( 17.67 ) X-Spam-Score: -1.4 (-) Cc: Yuvaraj Kumar C D , linux-samsung-soc@vger.kernel.org, grundler@chromium.org, t.figa@samsung.com, joshi@samsung.com, dianders@chromium.org, jh80.chung@samsung.com, tgih.jun@samsung.com, kgene.kim@samsung.com, cjb@laptop.org, Sonny Rao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch changes the fifo reset code to follow the reset procedure outlined in the documentation of Synopsys Mobile storage host databook 7.2.13. v2: Add Generic DMA support per the documentation, move interrupt clear before wait make the test for DMA host->use_dma rather than host->using_dma add proper return values (although it appears no caller checks) Signed-off-by: Sonny Rao Signed-off-by: Yuvaraj Kumar C D --- drivers/mmc/host/dw_mmc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++- drivers/mmc/host/dw_mmc.h | 1 + 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 55cd110..aff57e1 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -2325,6 +2325,7 @@ static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset) static inline bool dw_mci_fifo_reset(struct dw_mci *host) { + u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET; /* * Reseting generates a block interrupt, hence setting * the scatter-gather pointer to NULL. @@ -2334,7 +2335,59 @@ static inline bool dw_mci_fifo_reset(struct dw_mci *host) host->sg = NULL; } - return dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET); + /* + * The recommended method for resetting is to always reset the + * controller and the fifo, but differs slightly depending on the mode. + * The Generic DMA mode (non IDMAC) also needs to reset DMA where IDMAC + * mode resets IDMAC at the end. + * + */ +#ifndef CONFIG_MMC_DW_IDMAC + if (host->use_dma) + flags |= SDMMC_CTRL_DMA_RESET; +#endif + if (dw_mci_ctrl_reset(host, flags)) { + /* + * In all cases we clear the RAWINTS register to clear any + * interrupts. + */ + mci_writel(host, RINTSTS, 0xFFFFFFFF); + + /* if using dma we wait for dma_req to clear */ + if (host->use_dma) { + unsigned long timeout = jiffies + msecs_to_jiffies(500); + u32 status; + do { + status = mci_readl(host, STATUS); + if (!(status & SDMMC_STATUS_DMA_REQ)) + break; + cpu_relax(); + } while (time_before(jiffies, timeout)); + + if (status & SDMMC_STATUS_DMA_REQ) { + dev_err(host->dev, + "%s: Timeout waiting for dma_req to " + "clear during reset", __func__); + return false; + } + + /* when using DMA next we reset the fifo again */ + dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET); + } + } else { + dev_err(host->dev, "%s: Reset bits didn't clear", __func__); + return false; + } + +#ifdef CONFIG_MMC_DW_IDMAC + /* It is also recommended that we reset and reprogram idmac */ + dw_mci_idmac_reset(host); +#endif + + /* After a CTRL reset we need to have CIU set clock registers */ + mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0); + + return true; } static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host) diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 6bf24ab..2505804 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -129,6 +129,7 @@ #define SDMMC_CMD_INDX(n) ((n) & 0x1F) /* Status register defines */ #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF) +#define SDMMC_STATUS_DMA_REQ BIT(31) /* FIFOTH register defines */ #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \ ((r) & 0xFFF) << 16 | \