From patchwork Thu Nov 18 02:20:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 334891 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAI2I4lg014101 for ; Thu, 18 Nov 2010 02:20:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754625Ab0KRCUf (ORCPT ); Wed, 17 Nov 2010 21:20:35 -0500 Received: from mail-iw0-f174.google.com ([209.85.214.174]:40235 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754533Ab0KRCUf (ORCPT ); Wed, 17 Nov 2010 21:20:35 -0500 Received: by iwn35 with SMTP id 35so2868582iwn.19 for ; Wed, 17 Nov 2010 18:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=76dsWYAMZ+C3GV1P1MkeWbi+zEmeGXSWMTrRfI8yHdM=; b=dVAZpvV3RfnvfCon64ZfwA+sRmb37kAQP99Mt60pYSyGNc9yp/bK6no8QrtdlIBzPn qvdVkyjqp7m4iQz483QXh+7hP5rChGyfrNC4CS+owv7t5TfRGMXh1VSzDl3IMUXLqbOx PhOlKxJGVCX0TwQQlDN+Ogx0HSyz07ehtRJ4Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=KKifA+MrxMZmuODFvLS2ecf9XdfnCl2iCZS9CDQ1WJjt55pUIREL/cicQsVsTNrV6M eHbFQOVllSwCA3f2ITwjq5yNVUb+mHom9OgiOebYPIOdG+vfyUHpcsYSrroeyogChuBu h6uHlDgfHdHcYeY48NhcF7SYCEFjRjH9Ku/LI= MIME-Version: 1.0 Received: by 10.231.32.197 with SMTP id e5mr5848800ibd.188.1290046831542; Wed, 17 Nov 2010 18:20:31 -0800 (PST) Received: by 10.231.2.209 with HTTP; Wed, 17 Nov 2010 18:20:31 -0800 (PST) In-Reply-To: References: Date: Thu, 18 Nov 2010 10:20:31 +0800 Message-ID: Subject: [PATCH v2 1/1]mmc: check SDIO card wake up during suspending From: Jun Nie To: linux-mmc@vger.kernel.org Cc: Michal Miroslaw , Nicolas Pitre , Chris Ball , Andrew Morton , Bing Zhao , zhangfei gao , Eric Miao , Haojian Zhuang 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.3 (demeter1.kernel.org [140.211.167.41]); Thu, 18 Nov 2010 02:20:36 +0000 (UTC) From 642b2e88fc4b6344290c88ce506fcda1bcc860a3 Mon Sep 17 00:00:00 2001 From: Jun Nie Date: Fri, 12 Nov 2010 19:43:49 +0800 Subject: [PATCH] mmc: check SDIO card wake up during suspending It is possible that SDIO card send card interrupt to wake up system just after SDIO func driver and SDIO card firmware commit suspend state, while system is still in suspending process and mmc interrupt is not release yet. Interrupt storm may happen if func driver does not notify firmware to clear the wake up source. If func driver issue SDIO bus transaction to have firmware clear the source and driver continue to handle the wake up event, system may enter suspend before all transaction done. In this case, SDIO card will not enter lower power mode never. But system can not be wake up for only card insert/remove/interrupt irq are listed in wake up source in SD spec. Data/command done irq can not wake up system. This patch check SDIO card interrupt and stop system suspend if there are card interrupt after func driver suspend. Signed-off-by: Jun Nie --- drivers/mmc/core/sdio.c | 14 ++++++++++++++ drivers/mmc/core/sdio_irq.c | 6 ++++++ drivers/mmc/host/sdhci.c | 18 ++++++++++++++++-- include/linux/mmc/card.h | 2 ++ include/linux/mmc/sdio_func.h | 2 ++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index c3ad105..48a4106 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -584,6 +584,14 @@ static int mmc_sdio_suspend(struct mmc_host *host) for (i = 0; i < host->card->sdio_funcs; i++) { struct sdio_func *func = host->card->sdio_func[i]; + /* cancel suspend once we detect external wake up source */ + if (host->card->pending_interrupt) { + host->card->pending_interrupt = 0; + err = -EBUSY; + printk(KERN_ALERT "%s: wake up event after device suspended\n", + mmc_hostname(host)); + break; + } if (func && sdio_func_present(func) && func->dev.driver) { const struct dev_pm_ops *pmops = func->dev.driver->pm; if (!pmops || !pmops->suspend || !pmops->resume) { @@ -593,10 +601,15 @@ static int mmc_sdio_suspend(struct mmc_host *host) err = pmops->suspend(&func->dev); if (err) break; + else + /* It is prefer that func driver set it in its + suspend function with mmc_claim_host */ + func->suspended = true; } } while (err && --i >= 0) { struct sdio_func *func = host->card->sdio_func[i]; + func->suspended = false; if (func && sdio_func_present(func) && func->dev.driver) { const struct dev_pm_ops *pmops = func->dev.driver->pm; pmops->resume(&func->dev); @@ -639,6 +652,7 @@ static int mmc_sdio_resume(struct mmc_host *host) */ for (i = 0; !err && i < host->card->sdio_funcs; i++) { struct sdio_func *func = host->card->sdio_func[i]; + func->suspended = false; if (func && sdio_func_present(func) && func->dev.driver) { const struct dev_pm_ops *pmops = func->dev.driver->pm; err = pmops->resume(&func->dev); diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c index bb192f9..727a1a3 100644 --- a/drivers/mmc/core/sdio_irq.c +++ b/drivers/mmc/core/sdio_irq.c @@ -49,6 +49,12 @@ static int process_sdio_pending_irqs(struct mmc_card *card) mmc_card_id(card)); ret = -EINVAL; } else if (func->irq_handler) { + if (func->suspended) { + card->pending_interrupt = true; + printk(KERN_WARNING "%s: IRQ that " + "arrives in suspend mode" + " mode\n", sdio_func_id(func)); + } func->irq_handler(func); count++; } else { diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 782c0ee..9c8f1cc 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -24,6 +24,7 @@ #include #include +#include #include "sdhci.h" @@ -1631,7 +1632,7 @@ out: int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state) { - int ret; + int ret = 0; sdhci_disable_card_detection(host); @@ -1641,8 +1642,19 @@ int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state) free_irq(host->irq, host); - if (host->vmmc) + if (host->vmmc) { ret = regulator_disable(host->vmmc); + if (ret) + return ret; + } + + if (host->mmc->card && host->mmc->card->pending_interrupt) { + DBG("%s wake up event after suspend, resuming to handle it\n", + mmc_hostname(host->mmc)); + host->mmc->card->pending_interrupt = 0; + sdhci_resume_host(host); + return -EBUSY; + } return ret; } @@ -1659,6 +1671,8 @@ int sdhci_resume_host(struct sdhci_host *host) return ret; } + if (host->mmc->card && host->mmc->card->pending_interrupt) + host->mmc->card->pending_interrupt = 0; if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { if (host->ops->enable_dma) diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 8ce0827..2252fe2 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -146,6 +146,8 @@ struct mmc_card { struct sdio_func_tuple *tuples; /* unknown common tuples */ struct dentry *debugfs_root; + /* external interrupt arrived after sdio function suspended */ + u32 pending_interrupt; }; #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h index 31baaf8..5c1c462 100644 --- a/include/linux/mmc/sdio_func.h +++ b/include/linux/mmc/sdio_func.h @@ -59,6 +59,8 @@ struct sdio_func { const char **info; /* info strings */ struct sdio_func_tuple *tuples; + + int suspended; /* SDIO function driver state */ }; #define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT) -- 1.7.0.4