From patchwork Mon Oct 29 07:51:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaehoon Chung X-Patchwork-Id: 1661691 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3B4FF3FCF7 for ; Mon, 29 Oct 2012 07:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755469Ab2J2HvX (ORCPT ); Mon, 29 Oct 2012 03:51:23 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:31262 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755432Ab2J2HvX (ORCPT ); Mon, 29 Oct 2012 03:51:23 -0400 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MCN004729TF2VU0@mailout4.samsung.com> for linux-mmc@vger.kernel.org; Mon, 29 Oct 2012 16:51:21 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-60-508e3579be32 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 34.76.01231.9753E805; Mon, 29 Oct 2012 16:51:21 +0900 (KST) Received: from [10.90.51.55] by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MCN009IO9TLIZ30@mmp1.samsung.com> for linux-mmc@vger.kernel.org; Mon, 29 Oct 2012 16:51:21 +0900 (KST) Message-id: <508E3578.9050007@samsung.com> Date: Mon, 29 Oct 2012 16:51:20 +0900 From: Jaehoon Chung User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-version: 1.0 To: linux-mmc Cc: Chris Ball , Will Newton , James Hogan , Kyungmin Park , Seungwon Jeon Subject: [PATCH] mmc: dw-mmc: check whether card is busy or not, before disabling clock Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprILMWRmVeSWpSXmKPExsVy+t9jAd1K074Ag7dN+hZH/vczOjB6fN4k F8AYxWWTkpqTWZZapG+XwJUxa88MpoIFUhUXT51hbGCcKdrFyMkhIWAicfzpcTYIW0ziwr31 YLaQwCJGid6D+V2MXEB2O5PEqQv72UESvAJaEt9nvAOzWQRUJZ6c28EMYrMJ6Ehs/3acqYuR g0NUIExi5+Z0iHJBiR+T77GA2CICmhKd21eygcxkFjjAKLFn1zQmkISwQKTElZYzYHOYgebs b53GBmHLS2xe85Z5AiPfLCSzZiEpm4WkbAEj8ypG0dSC5ILipPRcQ73ixNzi0rx0veT83E2M 4IB6JrWDcWWDxSFGAQ5GJR7exje9AUKsiWXFlbmHGCU4mJVEeJdyA4V4UxIrq1KL8uOLSnNS iw8xSnOwKInzNnukBAgJpCeWpGanphakFsFkmTg4pRoYz+yPe1EVOy87Wafw9Eb7jek6WT/6 L1lfkDjSHGPM+tw5+fSTTXEH2999eHCLQTGl5V/u7nhX36O6YsaPwxI+tzlF9LSZrTr3eznb yh9Vd/09VFecqLmcIbHZcktP7qXIa1wHrtqZdDn6TpomEMLN65FqH14U3+3Fv8+mtfIhR5/h odY7bEpKLMUZiYZazEXFiQAxsmePJAIAAA== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Before disabling clock, need to check whether card is busy on not. Signed-off-by: Jaehoon Chung Signed-off-by: Kyungmin Park --- drivers/mmc/host/dw_mmc.c | 53 +++++++++++++++++++++++++++----------------- drivers/mmc/host/dw_mmc.h | 1 + 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 4b2bedc..5707bb6 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -228,6 +228,27 @@ static void dw_mci_set_timeout(struct dw_mci *host) mci_writel(host, TMOUT, 0xffffffff); } +static bool mci_wait_reset(struct device *dev, struct dw_mci *host) +{ + unsigned long timeout = jiffies + msecs_to_jiffies(500); + unsigned int ctrl; + + mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | + SDMMC_CTRL_DMA_RESET)); + + /* wait till resets clear */ + do { + ctrl = mci_readl(host, CTRL); + if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | + SDMMC_CTRL_DMA_RESET))) + return true; + } while (time_before(jiffies, timeout)); + + dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl); + + return false; +} + static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) { struct mmc_data *data; @@ -621,6 +642,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot) struct dw_mci *host = slot->host; u32 div; u32 clk_en_a; + int timeout = 1000; if (slot->clock != host->current_speed) { div = host->bus_hz / slot->clock; @@ -637,6 +659,16 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot) "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" " div = %d)\n", slot->id, host->bus_hz, slot->clock, div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div); + do { + if (!(mci_readl(host, STATUS) & SDMMC_DATA_BUSY)) + break; + if (timeout-- < 0) { + dev_err(host->dev, "Can't disable clock" + "because Card is busy!!\n"); + return; + } + mci_wait_reset(host->dev, host); + } while (1); /* disable clock */ mci_writel(host, CLKENA, 0); @@ -1995,27 +2027,6 @@ no_dma: return; } -static bool mci_wait_reset(struct device *dev, struct dw_mci *host) -{ - unsigned long timeout = jiffies + msecs_to_jiffies(500); - unsigned int ctrl; - - mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | - SDMMC_CTRL_DMA_RESET)); - - /* wait till resets clear */ - do { - ctrl = mci_readl(host, CTRL); - if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | - SDMMC_CTRL_DMA_RESET))) - return true; - } while (time_before(jiffies, timeout)); - - dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl); - - return false; -} - #ifdef CONFIG_OF static struct dw_mci_of_quirks { char *quirk; diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 53b8fd9..4f27357 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -127,6 +127,7 @@ #define SDMMC_CMD_INDX(n) ((n) & 0x1F) /* Status register defines */ #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF) +#define SDMMC_DATA_BUSY BIT(9) /* Internal DMAC interrupt defines */ #define SDMMC_IDMAC_INT_AI BIT(9) #define SDMMC_IDMAC_INT_NI BIT(8)