From patchwork Thu May 5 06:49:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arindam Nath X-Patchwork-Id: 756052 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p456q135022457 for ; Thu, 5 May 2011 06:52:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751752Ab1EEGwT (ORCPT ); Thu, 5 May 2011 02:52:19 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:53880 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751466Ab1EEGwS (ORCPT ); Thu, 5 May 2011 02:52:18 -0400 Received: by pvg12 with SMTP id 12so837420pvg.19 for ; Wed, 04 May 2011 23:52:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=xA3j0qDLQLRsb25C7dz/V6rlpIX5jvxxfwGMM+QwAp4=; b=g5zfCUoJ7vnI4aqLp5SOPKs3JDkAy+P/mH3vdj7pSgCw94OA9ZR2rArhrlfYC9a2Sj Rh+bA4MUkF1PG/pTD5qLa71dZlubg7XVdkZcDfKHisxarvkWptfXiOe3K6MsnHBWl9p2 rfQv7nI4JFEmnpY/PvAHKeKXBaD0SW81lp2nQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=uR3fs7Mauv3xlyOqRUfeKr5DrjmtXBI7Seqqq164cAmdiNHPP2AEDLRu4bes7yegSm mWnBhqPqnZl/kag8IHFekxF3RFpLblSAs4PU+4SC/h4HLXVJTEz0OKTtLyA8ZNh8vgfT sfXZqzBAIn2DUp0U9ASSdcwDcIP9i0gjreyFo= Received: by 10.142.144.7 with SMTP id r7mr1105502wfd.412.1304578338143; Wed, 04 May 2011 23:52:18 -0700 (PDT) Received: from localhost ([122.166.82.113]) by mx.google.com with ESMTPS id k6sm2423907wfa.17.2011.05.04.23.52.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 May 2011 23:52:17 -0700 (PDT) From: Arindam Nath To: cjb@laptop.org Cc: prakity@marvell.com, zhangfei.gao@gmail.com, subhashj@codeaurora.org, linux-mmc@vger.kernel.org, henry.su@amd.com, aaron.lu@amd.com, anath.amd@gmail.com, Arindam Nath Subject: [PATCH v4 09/15] mmc: sdhci: enable preset value after uhs initialization Date: Thu, 5 May 2011 12:19:05 +0530 Message-Id: <1304578151-1775-10-git-send-email-arindam.nath@amd.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1304578151-1775-1-git-send-email-arindam.nath@amd.com> References: <1304578151-1775-1-git-send-email-arindam.nath@amd.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 05 May 2011 06:52:19 +0000 (UTC) According to the Host Controller spec v3.00, setting Preset Value Enable in the Host Control2 register lets SDCLK Frequency Select, Clock Generator Select and Driver Strength Select to be set automatically by the Host Controller based on the UHS-I mode set. This patch enables this feature. Since Preset Value Enable makes sense only for UHS-I cards, we enable this feature after successfull UHS-I initialization. We also reset Preset Value Enable next time before initialization. Signed-off-by: Arindam Nath Reviewed-by: Philip Rakity Tested-by: Philip Rakity --- drivers/mmc/core/sd.c | 11 +++++++++++ drivers/mmc/host/sdhci.c | 32 ++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 1 + 3 files changed, 44 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 84cb8c3..851c8fc 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -931,6 +931,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, /* Card is an ultra-high-speed card */ mmc_sd_card_set_uhs(card); + + /* + * Since initialization is now complete, enable preset + * value registers for UHS-I cards. + */ + if (host->ops->enable_preset_value) + host->ops->enable_preset_value(host, 1); } else { /* * Attempt to change to high-speed (if supported) @@ -1101,6 +1108,10 @@ int mmc_attach_sd(struct mmc_host *host) if (err) return err; + /* Disable preset value enable if already set since last time */ + if (host->ops->enable_preset_value) + host->ops->enable_preset_value(host, 0); + err = mmc_send_app_op_cond(host, 0, &ocr); if (err) return err; diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 85775cf..cb767a0 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1655,6 +1655,37 @@ out: return err; } +static void sdhci_enable_preset_value(struct mmc_host *mmc, int enable) +{ + struct sdhci_host *host; + u16 ctrl; + unsigned long flags; + + host = mmc_priv(mmc); + + /* Host Controller v3.00 defines preset value registers */ + if (host->version < SDHCI_SPEC_300) + return; + + spin_lock_irqsave(&host->lock, flags); + + ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); + + /* + * We only enable or disable Preset Value if they are not already + * enabled or disabled respectively. Otherwise, we bail out. + */ + if (enable && !(ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) { + ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE; + sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); + } else if (!enable && (ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) { + ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE; + sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); + } + + spin_unlock_irqrestore(&host->lock, flags); +} + static const struct mmc_host_ops sdhci_ops = { .request = sdhci_request, .set_ios = sdhci_set_ios, @@ -1662,6 +1693,7 @@ static const struct mmc_host_ops sdhci_ops = { .enable_sdio_irq = sdhci_enable_sdio_irq, .start_signal_voltage_switch = sdhci_start_signal_voltage_switch, .execute_tuning = sdhci_execute_tuning, + .enable_preset_value = sdhci_enable_preset_value, }; /*****************************************************************************\ diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index ca7007f..2209e01 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -137,6 +137,7 @@ struct mmc_host_ops { int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios); int (*execute_tuning)(struct mmc_host *host); + void (*enable_preset_value)(struct mmc_host *host, int enable); }; struct mmc_card;