From patchwork Mon Oct 15 12:07:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Rudholm X-Patchwork-Id: 12227 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 7C4FB1D5116 for ; Mon, 15 Oct 2012 12:09:03 +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 0BF48A19050 for ; Mon, 15 Oct 2012 12:09:02 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so7450608iej.11 for ; Mon, 15 Oct 2012 05:09:02 -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=RWdPYCIQPiFyCzAmAUb5kqXYmHB6XaYyugjMGg6Npk0=; b=GHNdhqrPDCDX2VP2r2zO3A1I2mUE5dP6T/0FsZWIYRyG6IEIdauzKoFhGcYBTbY4HP P6s8+srTUWQoaDFRobPbmPnjMIBg+AwhZj3DQEcVzAoXjTjE72L95hv+3PYcfJohqkX4 EsEkXuMg5cKNUy2erWbQuNPVhCCsatRhK/s123MQn2sOaaIZ077E+fQaU7WaQOrNC0WO W/j7dWqlPiOiFuYIL3eOv1u0CW+IzoihuJg2/7aG66plxI4FtCvc2+/N3UmPPh94yD60 zgaoHF4tYpBZIN8ff+A1g4S58hqDxgrTb2r4YeJ2l5g3FvgxPX8TfX2uk7Ut5nN7Nl5J U17A== Received: by 10.50.236.72 with SMTP id us8mr8291504igc.70.1350302942421; Mon, 15 Oct 2012 05:09:02 -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.67.148 with SMTP id n20csp565307igt; Mon, 15 Oct 2012 05:09:01 -0700 (PDT) Received: by 10.14.199.132 with SMTP id x4mr15443207een.37.1350302940809; Mon, 15 Oct 2012 05:09:00 -0700 (PDT) Received: from eu1sys200aog107.obsmtp.com (eu1sys200aog107.obsmtp.com [207.126.144.123]) by mx.google.com with SMTP id q5si10673686eep.105.2012.10.15.05.08.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 05:09:00 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.123 is neither permitted nor denied by best guess record for domain of johan.rudholm@stericsson.com) client-ip=207.126.144.123; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.123 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 eu1sys200aob107.postini.com ([207.126.147.11]) with SMTP ID DSNKUHv81oLEM636iaJ95w0Y3YqVHYoCobro@postini.com; Mon, 15 Oct 2012 12:09:00 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 CCABFC6; Mon, 15 Oct 2012 12:08:21 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6DDC42B58; Mon, 15 Oct 2012 12:08:21 +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 relay2.stm.gmessaging.net (Postfix) with ESMTPS id 0C8D9A8081; Mon, 15 Oct 2012 14:08: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; Mon, 15 Oct 2012 14:08:20 +0200 From: Johan Rudholm To: , Chris Ball Cc: Per Forlin , Ulf Hansson , Fredrik Soderstedt , Kevin Liu , Philip Rakity , Johan Rudholm Subject: [RFC/PATCH v2] mmc: core: Fixup signal voltage switch Date: Mon, 15 Oct 2012 14:07:06 +0200 Message-ID: <1350302826-28294-1-git-send-email-johan.rudholm@stericsson.com> X-Mailer: git-send-email 1.7.10 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQl4sjzZNkNKMG/XOsCL1ZL9X7B/ZZBe81U7nz0sAz6ycMer4tp9YLteaLu5V4UlLRE1mcOj 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: v1 -> v2 - Removed reset of signal voltage in mmc_sd_get_cid, since "mmc: core: reset signal voltage on power up" previous two patches -> v1: - 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 | 29 ++++++++++++++++++++++++----- drivers/mmc/core/sdio.c | 28 ++++++++++++++++++++++++++-- include/linux/mmc/host.h | 6 ++++++ 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 06c42cf..160760c 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); } @@ -1284,7 +1313,7 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) * 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..0b456de 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,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 2273ce6..7955917 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 7abb0e1..139a0c1 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);