From patchwork Thu Sep 27 14:57:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Rudholm X-Patchwork-Id: 11763 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 85FB023E41 for ; Thu, 27 Sep 2012 14:59:13 +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 140A2A1882F for ; Thu, 27 Sep 2012 14:59:12 +0000 (UTC) Received: by ieje10 with SMTP id e10so4411701iej.11 for ; Thu, 27 Sep 2012 07:59:12 -0700 (PDT) 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:mime-version:content-type :x-gm-message-state; bh=8wXZTxdD40RB+pz3PEuQd9H3EjhIhYOJ/QdtCvWBY+4=; b=A2Km/+6nIzX/ogOUXGqEECUPv8rZjiV7gm2RHzKYnkMKJc3wj0dPVe4JfK0+1f6Jar xrN1IzuvjAaMI/YqJQ1MSn+7pDeluLoam+85o1UuOB1S4exf8sAUlWVYzUW5F3k5XxwV oabHhnDjxgdG3U8MaK1oUiW9atk1XstCc4qU2vqqM/M9yfqcVhMiM7C1ZUmMTDDIkXm7 qWv8e4Lzd2F4kequylxAYyp6VmU2rfzTyRQ1HyXXaIlhaX+dzPyfzdOSuwjQm54lKclv +OqfJEFCFEuO4j6sgnh5OvHXbQ5WGC188dmhcgkqHvKtg8UulD/BKd73VDjnKN/4frZ8 UA+g== Received: by 10.50.7.212 with SMTP id l20mr3795474iga.43.1348757952469; Thu, 27 Sep 2012 07:59:12 -0700 (PDT) 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.184.232 with SMTP id ex8csp420034igc; Thu, 27 Sep 2012 07:59:10 -0700 (PDT) Received: by 10.14.213.197 with SMTP id a45mr6356656eep.3.1348757949910; Thu, 27 Sep 2012 07:59:09 -0700 (PDT) Received: from eu1sys200aog110.obsmtp.com (eu1sys200aog110.obsmtp.com [207.126.144.129]) by mx.google.com with SMTP id o42si5370414eep.143.2012.09.27.07.59.03 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 07:59:09 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.129 is neither permitted nor denied by best guess record for domain of johan.rudholm@stericsson.com) client-ip=207.126.144.129; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.129 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 eu1sys200aob110.postini.com ([207.126.147.11]) with SMTP ID DSNKUGRpruEvLSJ2JkuwedKIHf+/v+RCzZWE@postini.com; Thu, 27 Sep 2012 14:59:08 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 5A16AFD; Thu, 27 Sep 2012 14:58:25 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0CB5446EE; Thu, 27 Sep 2012 14:58:25 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id D05ED24C07C; Thu, 27 Sep 2012 16:58:16 +0200 (CEST) Received: from steludxu1610.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Thu, 27 Sep 2012 16:58:24 +0200 From: Johan Rudholm To: , Chris Ball Cc: Per Forlin , Ulf Hansson , Fredrik Soderstedt , Kevin Liu , Philip Rakity , Johan Rudholm Subject: [RFC/PATCH] mmc: core: Fixup signal voltage switch Date: Thu, 27 Sep 2012 16:57:48 +0200 Message-ID: <1348757868-21502-1-git-send-email-johan.rudholm@stericsson.com> X-Mailer: git-send-email 1.7.10 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlmhKxegJpiUS6Ye0JAFSx98+NPMr9SmwRzgu/PqFsTiOUMNE0VNCubMY5KjGde4oZUGaoN 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. Signed-off-by: Johan Rudholm --- This rfc/patch is based on the following two patches: [PATCH v2 1/2] mmc: core: Proper signal voltage switch [PATCH v2 2/2] mmc: core: Power cycle card on voltage switch fail This patch has been tested with a couple of UHS micro-SD cards, one of which sometimes requires up to five power cycles before it accepts the signal voltage switch. The patch has also been tested with various other micro-SD cards, as well as one SDIO WLAN chip (cw1200) to check for regressions. The patch has been tested with CONFIG_MMC_CLKGATE. I'd be very grateful if someone could help me test this patch with a SDIO card that supports 1.8V and perhaps also a combo card (which does seem to be rare these days?)? Changelog from v1 of previous two patches: - Keep calls to mmc_host_clk_hold / mmc_host_clk_release - Add retry-loop / power cycle in sdio.c - Fall back to 3.3 V if the switch repeatedly fails - Add an extra argument to the card_busy host_ops function, which can be used to signal polling use of the function --- drivers/mmc/core/core.c | 31 ++++++++++++++++++++++++++++++- drivers/mmc/core/core.h | 1 + drivers/mmc/core/sd.c | 33 ++++++++++++++++++++++++++++----- drivers/mmc/core/sdio.c | 28 ++++++++++++++++++++++++++-- include/linux/mmc/host.h | 6 ++++++ 5 files changed, 91 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 6612163..7e24360 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1243,8 +1243,37 @@ 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); + clock = host->ios.clock; + if (cmd11) { + 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) { + /* Stop clock for at least 5 ms according to spec */ + 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 && + host->ops->card_busy(host, 0)) + err = -EAGAIN; + } mmc_host_clk_release(host); } @@ -1326,7 +1355,7 @@ static void mmc_poweroff_notify(struct mmc_host *host) * If a host does all the power sequencing itself, ignore the * initial MMC_POWER_UP stage. */ -static void mmc_power_up(struct mmc_host *host) +void mmc_power_up(struct mmc_host *host) { int bit; diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 3bdafbc..5a5170d 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -45,6 +45,7 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, void mmc_set_timing(struct mmc_host *host, unsigned int timing); void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); void mmc_power_off(struct mmc_host *host); +void mmc_power_up(struct mmc_host *host); static inline void mmc_delay(unsigned int ms) { diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 74972c2..1d23c70 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -713,6 +713,18 @@ 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)); + } + + /* The initialization should be done at 3.3 V I/O voltage. */ + if (rocr) + mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); /* * Since we're changing the OCR value, we seem to @@ -734,9 +746,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 +761,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 +772,19 @@ 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_warning("%s: Signal voltage switch failed, " + "power cycling card (retries = %d)\n", + mmc_hostname(host), retries); + mmc_power_off(host); + /* Wait at least 1 ms according to spec */ + mmc_delay(1); + mmc_power_up(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 d4619e2..337e3d9 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,29 @@ 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_warning("%s: Signal voltage switch failed, " + "power cycling card (retries = %d)\n", + mmc_hostname(host), retries); + mmc_power_off(host); + /* Wait at least 1 ms according to spec */ + mmc_delay(1); + mmc_power_up(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; } diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index d5d9bd4..2795a0b 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -131,6 +131,12 @@ struct mmc_host_ops { int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios); + /* + * Check if the card is pulling dat0 low. keep_busy can be used to + * indicate that the function will be called in a polling manner. + */ + int (*card_busy)(struct mmc_host *host, int keep_busy); + /* The tuning command opcode value is different for SD and eMMC cards */ int (*execute_tuning)(struct mmc_host *host, u32 opcode); void (*enable_preset_value)(struct mmc_host *host, bool enable);