From patchwork Mon Jun 20 10:38:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 2070 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 AA77D23E02 for ; Mon, 20 Jun 2011 10:29:06 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id 73E4FA18477 for ; Mon, 20 Jun 2011 10:29:06 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 7so2224413vxd.11 for ; Mon, 20 Jun 2011 03:29:06 -0700 (PDT) Received: by 10.52.112.106 with SMTP id ip10mr3587735vdb.127.1308565745815; Mon, 20 Jun 2011 03:29:05 -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.52.183.130 with SMTP id em2cs23172vdc; Mon, 20 Jun 2011 03:29:05 -0700 (PDT) Received: by 10.42.8.204 with SMTP id j12mr1330124icj.363.1308565745068; Mon, 20 Jun 2011 03:29:05 -0700 (PDT) Received: from mail-iy0-f178.google.com (mail-iy0-f178.google.com [209.85.210.178]) by mx.google.com with ESMTPS id m3si32371247icx.4.2011.06.20.03.29.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Jun 2011 03:29:05 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.178 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) client-ip=209.85.210.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.178 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) smtp.mail=shawn.guo@linaro.org Received: by iyb26 with SMTP id 26so3617996iyb.37 for ; Mon, 20 Jun 2011 03:29:04 -0700 (PDT) Received: by 10.231.66.135 with SMTP id n7mr4887558ibi.189.1308565744637; Mon, 20 Jun 2011 03:29:04 -0700 (PDT) Received: from localhost.localdomain ([58.208.97.176]) by mx.google.com with ESMTPS id d10sm3113114ibb.32.2011.06.20.03.28.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Jun 2011 03:29:04 -0700 (PDT) From: Shawn Guo To: linux-mmc@vger.kernel.org Cc: Chris Ball , Wolfram Sang , Arnaud Patard , Eric Benard , linux-arm-kernel@lists.infradead.org, patches@linaro.org, Shawn Guo Subject: [PATCH v3 1/4] mmc: sdhci: fix interrupt storm from card detection Date: Mon, 20 Jun 2011 18:38:42 +0800 Message-Id: <1308566325-11600-2-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1308566325-11600-1-git-send-email-shawn.guo@linaro.org> References: <1308566325-11600-1-git-send-email-shawn.guo@linaro.org> The issue was initially found by Eric Benard as below. http://permalink.gmane.org/gmane.linux.ports.arm.kernel/108031 Not sure about other SDHCI based controller, but on Freescale eSDHC, the SDHCI_INT_CARD_INSERT bits will be immediately set again when it gets cleared, if a card is inserted. The driver need to mask the irq to prevent interrupt storm which will freeze the system. And the SDHCI_INT_CARD_REMOVE gets the same situation. The patch fixes the problem based on the initial idea from Eric Benard. Signed-off-by: Shawn Guo Cc: Eric Benard --- drivers/mmc/host/sdhci.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 91d9892..d94e2b4 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -127,7 +127,9 @@ static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs) static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) { - u32 irqs = SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT; + u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & + SDHCI_CARD_PRESENT; + u32 irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT; if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) return; @@ -2154,13 +2156,30 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) mmc_hostname(host->mmc), intmask); if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) { + u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & + SDHCI_CARD_PRESENT; + + /* + * There is a observation on i.mx esdhc. INSERT bit will be + * immediately set again when it gets cleared, if a card is + * inserted. We have to mask the irq to prevent interrupt + * storm which will freeze the system. And the REMOVE gets + * the same situation. + * + * More testing are needed here to ensure it works for other + * platforms though. + */ + sdhci_mask_irqs(host, present ? SDHCI_INT_CARD_INSERT : + SDHCI_INT_CARD_REMOVE); + sdhci_unmask_irqs(host, present ? SDHCI_INT_CARD_REMOVE : + SDHCI_INT_CARD_INSERT); + sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT | - SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS); + SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS); + intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE); tasklet_schedule(&host->card_tasklet); } - intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE); - if (intmask & SDHCI_INT_CMD_MASK) { sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK, SDHCI_INT_STATUS);