From patchwork Wed Feb 25 18:11:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 5882281 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0AF47BF440 for ; Wed, 25 Feb 2015 18:15:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0BF302034F for ; Wed, 25 Feb 2015 18:15:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 106C22028D for ; Wed, 25 Feb 2015 18:15:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YQgRm-00035E-Nd; Wed, 25 Feb 2015 18:12:34 +0000 Received: from mail-ig0-x234.google.com ([2607:f8b0:4001:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YQgRg-0002yw-Vv for linux-arm-kernel@lists.infradead.org; Wed, 25 Feb 2015 18:12:29 +0000 Received: by mail-ig0-f180.google.com with SMTP id b16so8050484igk.1 for ; Wed, 25 Feb 2015 10:12:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=oabDDy4WYRFP/UzpLoSwnSMdnAyFXo4oaWRUJAswSEg=; b=esTSsrQpSDFE5nHwlccMgars6XXPnrZ2JbVlSMI07IGlR4sJn955eCpCrsL04+FPJ1 QGJ56mL8/418095wZQ1qKRV0NY05qjuM56UVnRw/0MfGWRvfmj4hmlHmthU/oMmfETAB ZcB2Y+VhH1WwJ3RkHpZTaOUkG0pa3YEZfYXuc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oabDDy4WYRFP/UzpLoSwnSMdnAyFXo4oaWRUJAswSEg=; b=GQhd/Rn8vjzEVYi/YFqSi0cy5vo4VN9TLY7EpIxag+5Z8OUXHrMYiSb7yaTYvKlDzU IqGdxX3I7zRXjwSLWMu/CHJ4v2jS9ful4cHdFDF8WvpQrsM51woovcL/1TEJBi5S3BqE bywCyX24b2xobMOSPtsdhAL0rWx3uUS7x7VMeOZls8RqVTZkLFd1HAcPUBDA1f3RvH3E 93umRdKN7C6LBw+ljW2a2IZ0ROkeZgZDZokAWxA17Y+7HpzDEUr5cb2DinvjIAVZZwWz VRYUY/M1GAFTpxswCMdXpwHgKGA5Tnx+B/ctQMJyb3arHYlcPDcGQVgztc/3Y7Cgv1da 26kw== X-Gm-Message-State: ALoCoQkGLQ7LmoGOl7ziTG4DtQHOBRZ8C+zoT23F7zxO8pPIq2H4xZsgE/+/uDpnJr0cIy0Ls8wQ X-Received: by 10.50.143.106 with SMTP id sd10mr6303832igb.17.1424887925969; Wed, 25 Feb 2015 10:12:05 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by mx.google.com with ESMTPSA id i16sm11972202ioe.17.2015.02.25.10.12.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 10:12:05 -0800 (PST) From: Doug Anderson To: Jaehoon Chung , Seungwon Jeon , Ulf Hansson Subject: [PATCH 1/2] mmc: dw_mmc: Only enable CD after setup and only if needed Date: Wed, 25 Feb 2015 10:11:51 -0800 Message-Id: <1424887912-20015-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150225_101229_077176_458538D5 X-CRM114-Status: GOOD ( 17.50 ) X-Spam-Score: -0.8 (/) Cc: Addy Ke , Heiko Stuebner , Andrew Bresticker , linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, Doug Anderson , chris@printf.net, linux-rockchip@lists.infradead.org, Alim Akhtar , Sonny Rao , javier.martinez@collabora.co.uk, linux-arm-kernel@lists.infradead.org, Alexandru Stan X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We really don't want to get a card detect interrupt during probe time since it can confuse things. Let's disable the card detect interrupt until we're in a really good place: the end of probe. Let's also simply avoid enabling the card detect interrupt if it's not used. It appears that (at least on rk3288) when vqmmc is turned on it can cause a bogus "card detect" interrupt. That meant that we were getting a predictable card detect interrupt while we were in mmc_add_host(). On the version of the kernel I'm working with at least (3.14), this is not a great time to get a card detect interrupt since I think that we don't grab all the needed locks in mmc_add_host() and children. I put stack dumps in dw_mci_setup_bus() and found that I could see two distinct stack crawls that looked like: Caller one: * dw_mci_setup_bus * dw_mci_set_ios * mmc_power_up * mmc_start_host * mmc_add_host Caller two: * dw_mci_setup_bus * dw_mci_set_ios * mmc_set_chip_select * mmc_go_idle * mmc_rescan * process_one_work * worker_thread * kthread Signed-off-by: Doug Anderson Tested-by: Javier Martinez Canillas --- drivers/mmc/host/dw_mmc.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 4d2e3c2..8df2a92 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -2574,6 +2574,34 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) } #endif /* CONFIG_OF */ +static void dw_mci_enable_cd(struct dw_mci *host) +{ + struct dw_mci_board *brd = host->pdata; + unsigned long irqflags; + u32 temp; + int i; + + /* No need for CD if broken card detection */ + if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) + return; + + /* No need for CD if all slots have a non-error GPIO */ + for (i = 0; i < host->num_slots; i++) { + struct dw_mci_slot *slot = host->slot[i]; + + if (IS_ERR_VALUE(mmc_gpio_get_cd(slot->mmc))) + break; + } + if (i == host->num_slots) + return; + + spin_lock_irqsave(&host->irq_lock, irqflags); + temp = mci_readl(host, INTMASK); + temp |= SDMMC_INT_CD; + mci_writel(host, INTMASK, temp); + spin_unlock_irqrestore(&host->irq_lock, irqflags); +} + int dw_mci_probe(struct dw_mci *host) { const struct dw_mci_drv_data *drv_data = host->drv_data; @@ -2747,13 +2775,13 @@ int dw_mci_probe(struct dw_mci *host) host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1; /* - * Enable interrupts for command done, data over, data empty, card det, + * Enable interrupts for command done, data over, data empty, * receive ready and error such as transmit, receive timeout, crc error */ mci_writel(host, RINTSTS, 0xFFFFFFFF); mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | SDMMC_INT_TXDR | SDMMC_INT_RXDR | - DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); + DW_MCI_ERROR_FLAGS); mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */ dev_info(host->dev, "DW MMC controller at irq %d, " @@ -2770,6 +2798,9 @@ int dw_mci_probe(struct dw_mci *host) init_slots++; } + /* Now that slots are all setup, we can enable card detect */ + dw_mci_enable_cd(host); + if (init_slots) { dev_info(host->dev, "%d slots initialized\n", init_slots); } else { @@ -2864,7 +2895,7 @@ int dw_mci_resume(struct dw_mci *host) mci_writel(host, RINTSTS, 0xFFFFFFFF); mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | SDMMC_INT_TXDR | SDMMC_INT_RXDR | - DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); + DW_MCI_ERROR_FLAGS); mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); for (i = 0; i < host->num_slots; i++) { @@ -2876,6 +2907,10 @@ int dw_mci_resume(struct dw_mci *host) dw_mci_setup_bus(slot, true); } } + + /* Now that slots are all setup, we can enable card detect */ + dw_mci_enable_cd(host); + return 0; } EXPORT_SYMBOL(dw_mci_resume);