From patchwork Mon Sep 16 14:17:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 20344 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f197.google.com (mail-ye0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 22E8324694 for ; Mon, 16 Sep 2013 14:18:19 +0000 (UTC) Received: by mail-ye0-f197.google.com with SMTP id q5sf4108378yen.0 for ; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=4HtYAaThF5HQLVV7Y6eDjKkeFNYQPhAYFuA2/grlW6w=; b=jJSEuIzASuxkHjpenubfdDd2kG42QfLVbGU2fxbs6oclAIhuYQZvQzIn7XfnJrymZP CjSsPJSTSuUg9WUFVOpG0obzSCX8nEb8SHlJ5vDmaX+VDIiKwbib1x9A1KTH4i0Uoas+ vtARAHG7YqbmnTzRLv/TK5+cVN0KLpkfkuJZV35NPZe4UjjtrXeB6xpyRq8DEGqNyLHk CjvZrpcthU9OwCUzwIMj1LajaXPZNx0vaFmNtTalenHcR5CbeZ50AJOuKEIiYP6hq1Vh dxB4/Ji9bowDbJdQyJkvTUakGbryMLbIChMn5VBWBjk/Hd0eanpKzg1cm2Vtjm7e/IJs vBCQ== X-Gm-Message-State: ALoCoQm+WNe+JEZTIWVin214GV5YmeGr7NohwYzkzMFIluRyoyzErb8PHvsEU9ARzwhJi9U6Ubkj X-Received: by 10.58.201.66 with SMTP id jy2mr1636964vec.5.1379341098945; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.28.10 with SMTP id x10ls2384678qeg.20.gmail; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) X-Received: by 10.52.170.136 with SMTP id am8mr548442vdc.33.1379341098870; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) Received: from mail-vb0-f47.google.com (mail-vb0-f47.google.com [209.85.212.47]) by mx.google.com with ESMTPS id ur9si7142769veb.117.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 07:18:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.47 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.47; Received: by mail-vb0-f47.google.com with SMTP id h10so2907049vbh.34 for ; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) X-Received: by 10.58.108.74 with SMTP id hi10mr27802725veb.14.1379341098778; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp99358vcz; Mon, 16 Sep 2013 07:18:18 -0700 (PDT) X-Received: by 10.112.143.3 with SMTP id sa3mr25289739lbb.12.1379341097503; Mon, 16 Sep 2013 07:18:17 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com [209.85.215.42]) by mx.google.com with ESMTPS id ze5si11992715lbb.163.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 07:18:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.42 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id ep20so3152236lab.15 for ; Mon, 16 Sep 2013 07:18:16 -0700 (PDT) X-Received: by 10.112.17.35 with SMTP id l3mr1401928lbd.41.1379341096914; Mon, 16 Sep 2013 07:18:16 -0700 (PDT) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id ur6sm13161703lbc.5.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 07:18:16 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Chris Ball Cc: Prasanna NAVARATNA , Ulf Hansson Subject: [PATCH 6/7] mmc: core: Prevent violation of specs while initializing cards Date: Mon, 16 Sep 2013 16:17:47 +0200 Message-Id: <1379341068-27097-7-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1379341068-27097-1-git-send-email-ulf.hansson@linaro.org> References: <1379341068-27097-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.47 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , According to eMMC/SD/SDIO specs, the VDD (VCC) voltage level must be maintained during the initialization sequence. If we want/need to tune the voltage level, a complete power cycle of the card must be executed. Most host drivers conforms to the specifications by only allowing to change VDD voltage level at the MMC_POWER_UP state, but some also cares about MMC_POWER_ON state, which they should'nt. This patch will not break those drivers, but they could clean up code to better reflect what is expected from the protocol layer. A big re-work of the mmc_select_voltage function is done to only change VDD voltage level if the host supports MMC_CAP2_FULL_PWR_CYCLE. Otherwise only validation of the host and card ocr mask will be done. A very nice side-effect of this patch is that we now don't need to reset the negotiated ocr mask at the mmc_power_off function, since now it will actually reflect the present voltage level, which safely can be used at the next power up and re-initialization. Moreover, we then only need to execute mmc_select_voltage from the attach sequence. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 31 +++++++++++-------------------- drivers/mmc/core/mmc.c | 1 - drivers/mmc/core/sd.c | 1 - drivers/mmc/core/sdio.c | 17 ++--------------- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 4a1e3ca..0d89ccc 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1383,21 +1383,20 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) int bit; ocr &= host->ocr_avail; + if (!ocr) { + dev_warn(mmc_dev(host), "no support for card's volts\n"); + return 0; + } - bit = ffs(ocr); - if (bit) { - bit -= 1; - + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { + bit = ffs(ocr) - 1; ocr &= 3 << bit; - - mmc_host_clk_hold(host); - host->ios.vdd = bit; - mmc_set_ios(host); - mmc_host_clk_release(host); + mmc_power_cycle(host, ocr); } else { - pr_warning("%s: host doesn't support card's voltages\n", - mmc_hostname(host)); - ocr = 0; + bit = fls(ocr) - 1; + ocr &= 3 << bit; + if (bit != host->ios.vdd) + dev_warn(mmc_dev(host), "exceeding card's volts\n"); } return ocr; @@ -1596,14 +1595,6 @@ void mmc_power_off(struct mmc_host *host) host->ios.clock = 0; host->ios.vdd = 0; - - /* - * Reset ocr mask to be the highest possible voltage supported for - * this card. This value will be used at next power up. - */ - if (host->card) - host->card->ocr = 1 << (fls(host->ocr_avail) - 1); - if (!mmc_host_is_spi(host)) { host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; host->ios.chip_select = MMC_CS_DONTCARE; diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index efc9f6f..9149eab 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1535,7 +1535,6 @@ static int mmc_resume(struct mmc_host *host) mmc_claim_host(host); mmc_power_up(host, host->card->ocr); - mmc_select_voltage(host, host->card->ocr); err = mmc_init_card(host, host->card->ocr, host->card); mmc_release_host(host); diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 398065c..53db60a 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1103,7 +1103,6 @@ static int mmc_sd_resume(struct mmc_host *host) mmc_claim_host(host); mmc_power_up(host, host->card->ocr); - mmc_select_voltage(host, host->card->ocr); err = mmc_sd_init_card(host, host->card->ocr, host->card); mmc_release_host(host); diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index e0a135a..b7c19e8 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -987,7 +987,6 @@ static int mmc_sdio_resume(struct mmc_host *host) /* Restore power if needed */ if (!mmc_card_keep_power(host)) { mmc_power_up(host, host->card->ocr); - mmc_select_voltage(host, host->card->ocr); /* * Tell runtime PM core we just powered up the card, * since it still believes the card is powered off. @@ -1045,7 +1044,6 @@ static int mmc_sdio_resume(struct mmc_host *host) static int mmc_sdio_power_restore(struct mmc_host *host) { int ret; - u32 ocr, rocr; BUG_ON(!host); BUG_ON(!host->card); @@ -1067,28 +1065,17 @@ static int mmc_sdio_power_restore(struct mmc_host *host) * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and * harmless in other situations. * - * With these steps taken, mmc_select_voltage() is also required to - * restore the correct voltage setting of the card. */ sdio_reset(host); mmc_go_idle(host); mmc_send_if_cond(host, host->ocr_avail); - ret = mmc_send_io_op_cond(host, 0, &ocr); + ret = mmc_send_io_op_cond(host, 0, NULL); if (ret) goto out; - if (host->ocr_avail_sdio) - host->ocr_avail = host->ocr_avail_sdio; - - rocr = mmc_select_voltage(host, ocr & ~0x7F); - if (!rocr) { - ret = -EINVAL; - goto out; - } - - ret = mmc_sdio_init_card(host, rocr, host->card, + ret = mmc_sdio_init_card(host, host->card->ocr, host->card, mmc_card_keep_power(host)); if (!ret && host->sdio_irqs) mmc_signal_sdio_irq(host);