From patchwork Mon Dec 16 17:01:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinh Nguyen X-Patchwork-Id: 3355861 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 93696C0D4A for ; Mon, 16 Dec 2013 17:03:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 45643201FD for ; Mon, 16 Dec 2013 17:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63DF120203 for ; Mon, 16 Dec 2013 17:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754681Ab3LPRDL (ORCPT ); Mon, 16 Dec 2013 12:03:11 -0500 Received: from mail-db9lp0248.outbound.messaging.microsoft.com ([213.199.154.248]:37619 "EHLO db9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754680Ab3LPRDK (ORCPT ); Mon, 16 Dec 2013 12:03:10 -0500 Received: from mail112-db9-R.bigfish.com (10.174.16.253) by DB9EHSOBE030.bigfish.com (10.174.14.93) with Microsoft SMTP Server id 14.1.225.22; Mon, 16 Dec 2013 17:03:09 +0000 Received: from mail112-db9 (localhost [127.0.0.1]) by mail112-db9-R.bigfish.com (Postfix) with ESMTP id F0D33180D64; Mon, 16 Dec 2013 17:03:08 +0000 (UTC) X-Forefront-Antispam-Report: CIP:66.35.236.231; KIP:(null); UIP:(null); IPV:NLI; H:sj-itexedge01.altera.priv.altera.com; RD:none; EFVD:NLI X-SpamScore: 11 X-BigFish: VS11(zzzz1f42h208ch1ee6h1de0h1fdah2073h2146h1202h1e76h2189h1d1ah1d2ah1fc6hz70kz1de098h8275bh1de097hz2fh2a8h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h14ddh1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah224fh1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e1dh1e23h1fe8h1ff5h2218h2216h226dh22d0h2327h2336h286p1155h) Received-SPF: pass (mail112-db9: domain of altera.com designates 66.35.236.231 as permitted sender) client-ip=66.35.236.231; envelope-from=dinguyen@altera.com; helo=sj-itexedge01.altera.priv.altera.com ; v.altera.com ; Received: from mail112-db9 (localhost.localdomain [127.0.0.1]) by mail112-db9 (MessageSwitch) id 1387213386868636_26931; Mon, 16 Dec 2013 17:03:06 +0000 (UTC) Received: from DB9EHSMHS016.bigfish.com (unknown [10.174.16.226]) by mail112-db9.bigfish.com (Postfix) with ESMTP id BEDC8420092; Mon, 16 Dec 2013 17:03:06 +0000 (UTC) Received: from sj-itexedge01.altera.priv.altera.com (66.35.236.231) by DB9EHSMHS016.bigfish.com (10.174.14.26) with Microsoft SMTP Server (TLS) id 14.16.227.3; Mon, 16 Dec 2013 17:03:05 +0000 Received: from sj-mail01.altera.com (137.57.1.6) by sj-itexedge01.altera.priv.altera.com (66.35.236.231) with Microsoft SMTP Server id 8.3.298.1; Mon, 16 Dec 2013 08:54:32 -0800 Received: from linux-builds1.altera.com (linux-builds1.altera.com [137.57.188.114]) by sj-mail01.altera.com (8.13.7+Sun/8.13.7) with ESMTP id e09NDJAc011450; Sun, 9 Jan 2000 15:13:20 -0800 (PST) From: To: , , , , , , , , , CC: , Dinh Nguyen Subject: [PATCHv4] mmc: dw_mmc: Enable the hold reg for certain speed modes Date: Mon, 16 Dec 2013 11:01:19 -0600 Message-ID: <1387213279-22020-1-git-send-email-dinguyen@altera.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-OriginatorOrg: altera.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 From: Dinh Nguyen This patch will enable the SDMMC_CMD_USE_HOLD_REG bit when the slot is operating all timing modes, except for SDR50, DDR50, SDR104, and MMC_HS200. According to the Synopsys databook :"To meet the relatively high Input Hold Time requirement for SDR12, SDR25, and other MMC speed modes, you should program bit[29]use_hold_Reg of the CMD register to 1'b1;"..."However, for the higher speed modes of SDR104, SDR50 and DDR50, you can meet the much smaller Input Hold Time requirement of 0.8ns by bypassing the Hold Register (Path A in Figure 10-8, programming CMD.use_hold_reg = 1'b0) and then adding delay elements on the output path as indicated. Also, "Never set CMD.use_hold_reg = 1 and cclk_in_drv phase shift to 0 at the same time. This would add an extra one-cycle delay on the output path, resulting in incorrect behavior." This patch also checks the IHR(Implement Hold Register) in the HCON register. This information is taking from the v2.50a of the Synopsys Designware Cores Mobile Storage Host Databook. Signed-off-by: Dinh Nguyen Acked-by: Arnd Bergmann Acked-by: Heiko Stuebner Tested-by: Heiko Stuebner --- v4: use_hold_reg should be set for all modes when cclk_in_drv is non-zero. v3: Read the IHR(Implement Hold Register) in the HCON v2: Add check for cclk_in_drv phase shift in conjunction with use_hold_reg. --- drivers/mmc/host/dw_mmc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc.h | 4 ++++ include/linux/mmc/dw_mmc.h | 3 +++ 3 files changed, 59 insertions(+) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 4bce0de..080ebb6 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -279,6 +279,9 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) cmdr |= SDMMC_CMD_DAT_WR; } + if (slot->host->use_hold_reg) + cmdr |= SDMMC_CMD_USE_HOLD_REG; + if (drv_data && drv_data->prepare_command) drv_data->prepare_command(slot->host, &cmdr); @@ -969,6 +972,25 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) mci_writel(slot->host, UHS_REG, regs); slot->host->timing = ios->timing; + /* Per Synopsys spec, use_hold_reg should be set for all modes except for + * high-speed SDR50, DDR50, SDR104, and MMC_HS200. However, use_hold_reg + * should be cleared if the cclk_in_drv is 0. use_hold_reg should be set + * for all modes if cclk_in_drv is set. + */ + slot->host->use_hold_reg = 1; + switch (slot->host->timing) { + case MMC_TIMING_UHS_SDR50: + case MMC_TIMING_UHS_SDR104: + case MMC_TIMING_UHS_DDR50: + case MMC_TIMING_MMC_HS200: + if (slot->host->pdata->cclk_in_drv == 0) + slot->host->use_hold_reg = 0; + break; + } + + if (slot->host->can_use_hold_reg == 0) + slot->host->use_hold_reg = 0; + /* * Use mirror of ios->clock to prevent race with mmc * core ios update when finding the minimum. @@ -2339,6 +2361,8 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) const struct dw_mci_drv_data *drv_data = host->drv_data; int idx, ret; u32 clock_frequency; + int sdr_timing[2]; + int ddr_timing[2]; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { @@ -2389,6 +2413,25 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) if (of_find_property(np, "caps2-mmc-hs200-1_2v", NULL)) pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR; + /* Check for the "samsung,dw-mshc-sdr-timing" and the + * "samsung,dw-mshc-ddr-timing" bindings as this will tell us if we + * can safely set the SDMMC_CMD_USE_HOLD_REG bit. The second paramater + * in these 2 bindings is the value of the cclk_in_drv. If cclk_in_drv + * is 0, we cannot set the SDMMC_CMD_USE_HOLD_REG bit. The default + * behavior will be to set cclk_in_drv, as some platforms do not have + * to set the sdr or ddr timing parameters. + */ + sdr_timing[1] = ddr_timing[1] = 1; + of_property_read_u32_array(np, + "samsung,dw-mshc-sdr-timing", sdr_timing, 2); + + of_property_read_u32_array(np, + "samsung,dw-mshc-ddr-timing", ddr_timing, 2); + + pdata->cclk_in_drv = 1; + if ((sdr_timing[1] == 0) || (ddr_timing[1] == 0)) + pdata->cclk_in_drv = 0; + return pdata; } @@ -2495,6 +2538,15 @@ int dw_mci_probe(struct dw_mci *host) goto err_regulator; } + /* Check to see if the HOLD REG is implemented. */ + host->can_use_hold_reg = (mci_readl(host, HCON) & SDMMC_HCON_IHR) >> 22; + + /* Can only use the HOLD REG is both conditions are true: + * Hardware has implemented HOLD_REG and + * cclk_in_drv is non-zero. + */ + host->can_use_hold_reg &= host->pdata->cclk_in_drv; + host->quirks = host->pdata->quirks; spin_lock_init(&host->lock); diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 6bf24ab..dfd05c9 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -145,6 +145,10 @@ #define SDMMC_IDMAC_ENABLE BIT(7) #define SDMMC_IDMAC_FB BIT(1) #define SDMMC_IDMAC_SWRESET BIT(0) + +/* Hardware Configuration(HCON) register */ +#define SDMMC_HCON_IHR BIT(22) + /* Version ID register define */ #define SDMMC_GET_VERID(x) ((x) & 0xFFFF) /* Card read threshold */ diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h index 6ce7d2c..2b5b8bf 100644 --- a/include/linux/mmc/dw_mmc.h +++ b/include/linux/mmc/dw_mmc.h @@ -191,6 +191,8 @@ struct dw_mci { struct regulator *vmmc; /* Power regulator */ unsigned long irq_flags; /* IRQ flags */ int irq; + u32 can_use_hold_reg; + bool use_hold_reg; }; /* DMA ops for Internal/External DMAC interface */ @@ -238,6 +240,7 @@ struct dw_mci_board { u32 caps; /* Capabilities */ u32 caps2; /* More capabilities */ u32 pm_caps; /* PM capabilities */ + u32 cclk_in_drv; /*cclk_in_drv phase shift */ /* * Override fifo depth. If 0, autodetect it from the FIFOTH register, * but note that this may not be reliable after a bootloader has used