From patchwork Fri Dec 7 16:19:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Rudholm X-Patchwork-Id: 13419 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0BD5423E51 for ; Fri, 7 Dec 2012 16:20:53 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 93573A19897 for ; Fri, 7 Dec 2012 16:20:52 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so1590841ieb.11 for ; Fri, 07 Dec 2012 08:20:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:x-gm-message-state; bh=lF5rVoEgChXYG+yFEkQpLByLnvA9Ju6nKYutmAah3Tc=; b=V/0OoBEuYqkNR/YQN4QVKiDRmvMXozSDgcdpeAOfZFSEgRWTckrEpwulBFc+vFYKA+ 4b7WNwEvyILb1e5OyxAU3mCELvu4Z7oTUz6u0T4Vo4YizZCv4tFJPKBxGrxF/F8TerRp ok3GZflXC7th4drTBya/AO76YS5i69ZYwI5M5kGYAbDXOX9YvnAzo1xqDgzY4QQCQCrs 2o5biBekJMMrq17sYxuxFh+BbdUJbkfQCt3LxqOMAjUoN4a+a7w/29SIHSIdrvMxx2nx WRGF66z/Da7RyXT+aLvcpr8Ui2fGy5Tx/ST8N4HAmrK7XUaaEROJpuYo3voXqYhz8jfC B76Q== Received: by 10.43.46.2 with SMTP id um2mr4780828icb.18.1354897251967; Fri, 07 Dec 2012 08:20:51 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp483800igt; Fri, 7 Dec 2012 08:20:50 -0800 (PST) Received: by 10.14.174.198 with SMTP id x46mr18336913eel.23.1354897249823; Fri, 07 Dec 2012 08:20:49 -0800 (PST) Received: from eu1sys200aog111.obsmtp.com (eu1sys200aog111.obsmtp.com [207.126.144.131]) by mx.google.com with SMTP id i42si25259207eem.112.2012.12.07.08.20.36 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 07 Dec 2012 08:20:49 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.131 is neither permitted nor denied by best guess record for domain of johan.rudholm@stericsson.com) client-ip=207.126.144.131; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.131 is neither permitted nor denied by best guess record for domain of johan.rudholm@stericsson.com) smtp.mail=johan.rudholm@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob111.postini.com ([207.126.147.11]) with SMTP ID DSNKUMIXSkN1EoPaghYWdtC9PsW3p0uw2gOv@postini.com; Fri, 07 Dec 2012 16:20:49 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8A1621AE; Fri, 7 Dec 2012 16:20:24 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 168424B79; Fri, 7 Dec 2012 16:20:24 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id A6E5924C300; Fri, 7 Dec 2012 17:20:15 +0100 (CET) Received: from steludxu1610.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 7 Dec 2012 17:20:23 +0100 From: Johan Rudholm To: , Chris Ball Cc: Per Forlin , Ulf Hansson , Fredrik Soderstedt , Kevin Liu , Philip Rakity , Daniel Drake , Aaron , Subhash Jadavani , Johan Rudholm Subject: [PATCH 3/3] mmc: core: Fixup signal voltage switch Date: Fri, 7 Dec 2012 17:19:36 +0100 Message-ID: <1354897176-15307-4-git-send-email-johan.rudholm@stericsson.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1354897176-15307-1-git-send-email-johan.rudholm@stericsson.com> References: <1354897176-15307-1-git-send-email-johan.rudholm@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlBKU8rRZHVIXHXYPJKkQ0Uo6xJqXDoY0tML8f7JU8EoK0YUwxGXec8PeHqFBFDMAuhBsaZ When switching SD and SDIO cards from 3.3V to 1.8V signal levels, the clock should be gated for 5 ms during the step. After enabling the clock, the host should wait for at least 1 ms before checking for failure. Failure by the card to switch is indicated by dat[0:3] being pulled low. The host should check for this condition and power-cycle the card if failure is indicated. Add a retry mechanism for the SDIO case. If the voltage switch fails repeatedly, give up and continue the initialization using the original voltage. This patch places a couple of requirements on the host driver: 1) mmc_set_ios with ios.clock = 0 must gate the clock 2) mmc_power_off must actually cut the power to the card if these requirements are not fulfilled, the 1.8V signal voltage switch may not be successful. Signed-off-by: Johan Rudholm --- drivers/mmc/core/core.c | 35 +++++++++++++++++++++++++++++++++++ drivers/mmc/core/sd.c | 26 +++++++++++++++++++++----- drivers/mmc/core/sdio.c | 25 +++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 285f064..c9a7a8a 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1246,8 +1246,43 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11 host->ios.signal_voltage = signal_voltage; if (host->ops->start_signal_voltage_switch) { + u32 clock; + mmc_host_clk_hold(host); + /* + * During a signal voltage level switch, the clock must be gated + * for a certain period of time according to the SD spec + */ + if (cmd11) { + clock = host->ios.clock; + host->ios.clock = 0; + mmc_set_ios(host); + } + err = host->ops->start_signal_voltage_switch(host, &host->ios); + + if (err && cmd11) { + host->ios.clock = clock; + mmc_set_ios(host); + } else if (cmd11) { + /* Keep clock gated for at least 5 ms */ + mmc_delay(5); + host->ios.clock = clock; + mmc_set_ios(host); + + /* Wait for at least 1 ms according to spec */ + mmc_delay(1); + + /* + * Failure to switch is indicated by the card holding + * dat[0:3] low + */ + if (!host->ops->card_busy) + pr_warning("%s: cannot verify signal voltage switch\n", + mmc_hostname(host)); + else if (host->ops->card_busy(host)) + err = -EAGAIN; + } mmc_host_clk_release(host); } diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 74972c2..eb299bc 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -713,6 +713,14 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) { int err; u32 max_current; + int retries = 10; + +try_again: + if (!retries) { + ocr &= ~SD_OCR_S18R; + pr_warning("%s: Skipping voltage switch\n", + mmc_hostname(host)); + } /* * Since we're changing the OCR value, we seem to @@ -734,9 +742,10 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) /* * If the host supports one of UHS-I modes, request the card - * to switch to 1.8V signaling level. + * to switch to 1.8V signaling level. If the card has failed + * repeatedly to switch however, skip this. */ - if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | + if (retries && host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)) ocr |= SD_OCR_S18R; @@ -748,7 +757,6 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) if (max_current > 150) ocr |= SD_OCR_XPC; -try_again: err = mmc_send_app_op_cond(host, ocr, rocr); if (err) return err; @@ -760,8 +768,16 @@ try_again: if (!mmc_host_is_spi(host) && rocr && ((*rocr & 0x41000000) == 0x41000000)) { err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, true); - if (err) { - ocr &= ~SD_OCR_S18R; + if (err == -EAGAIN) { + /* Power cycle card */ + pr_debug("%s: Signal voltage switch failed, " + "power cycling card (retries = %d)\n", + mmc_hostname(host), retries); + mmc_power_cycle(host); + retries--; + goto try_again; + } else if (err) { + retries = 0; goto try_again; } } diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 2273ce6..573ab06 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -583,10 +583,19 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, { struct mmc_card *card; int err; + int retries = 10; BUG_ON(!host); WARN_ON(!host->claimed); +try_again: + if (!retries) { + pr_warning("%s: Skipping voltage switch\n", + mmc_hostname(host)); + ocr &= ~R4_18V_PRESENT; + host->ocr &= ~R4_18V_PRESENT; + } + /* * Inform the card of the voltage */ @@ -645,14 +654,26 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, * systems that claim 1.8v signalling in fact do not support * it. */ - if ((ocr & R4_18V_PRESENT) && + if (!powered_resume && (ocr & R4_18V_PRESENT) && (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))) { err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, true); - if (err) { + if (err == -EAGAIN) { + /* Power cycle card */ + pr_debug("%s: Signal voltage switch failed, " + "power cycling card (retries = %d)\n", + mmc_hostname(host), retries); + mmc_power_cycle(host); + sdio_reset(host); + mmc_go_idle(host); + mmc_send_if_cond(host, host->ocr_avail); + mmc_remove_card(card); + retries--; + goto try_again; + } else if (err) { ocr &= ~R4_18V_PRESENT; host->ocr &= ~R4_18V_PRESENT; }