From patchwork Sat Feb 13 09:56:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovic Desroches X-Patchwork-Id: 8299821 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4EA029F6E4 for ; Sat, 13 Feb 2016 09:57:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54D72203ED for ; Sat, 13 Feb 2016 09:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 109C4203B5 for ; Sat, 13 Feb 2016 09:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750858AbcBMJ4t (ORCPT ); Sat, 13 Feb 2016 04:56:49 -0500 Received: from eusmtp01.atmel.com ([212.144.249.243]:34007 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbcBMJ4r (ORCPT ); Sat, 13 Feb 2016 04:56:47 -0500 Received: from ibiza.corp.atmel.com (10.161.101.13) by eusmtp01.atmel.com (10.161.101.31) with Microsoft SMTP Server id 14.3.235.1; Sat, 13 Feb 2016 10:56:36 +0100 From: Ludovic Desroches To: CC: , , , , Ludovic Desroches Subject: [PATCH] mmc: sdhci-of-at91: fix wakeup issue when using runtime pm Date: Sat, 13 Feb 2016 10:56:40 +0100 Message-ID: <1455357400-32145-1-git-send-email-ludovic.desroches@atmel.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <20160212120415.GJ14937@odux.rfo.atmel.com> References: <20160212120415.GJ14937@odux.rfo.atmel.com> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 When suspending the sdhci host, the only hardware event that could wake up the host is a sdio irq if they are enabled. If we want to wakeup on card detect events, a gpio as to be used. If we don't want to use a gpio but the card detect pio of the controller then we need to keep enabled the clock of the controller interface to get the interrupt and to not set the host in a suspended state to have the interrupt handled. Signed-off-by: Ludovic Desroches --- drivers/mmc/host/sdhci-of-at91.c | 46 ++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c index efec736..2159c6e 100644 --- a/drivers/mmc/host/sdhci-of-at91.c +++ b/drivers/mmc/host/sdhci-of-at91.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,6 @@ static const struct sdhci_ops sdhci_at91_sama5d2_ops = { static const struct sdhci_pltfm_data soc_data_sama5d2 = { .ops = &sdhci_at91_sama5d2_ops, - .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION, .quirks2 = SDHCI_QUIRK2_NEED_DELAY_AFTER_INT_CLK_RST, }; @@ -55,17 +55,37 @@ static const struct of_device_id sdhci_at91_dt_match[] = { }; #ifdef CONFIG_PM +static bool sdhci_at91_use_sdhci_runtime(struct sdhci_host *host) +{ + u32 caps = host->mmc->caps; + + return (caps & MMC_CAP_NONREMOVABLE) || + (!IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc))); +} + static int sdhci_at91_runtime_suspend(struct device *dev) { struct sdhci_host *host = dev_get_drvdata(dev); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_at91_priv *priv = pltfm_host->priv; - int ret; + int ret = 0; - ret = sdhci_runtime_suspend_host(host); + /* + * If we call sdhci_runtime_suspend(), we could wakeup only if sdio + * irqs are enabled. If we want to wakeup on a card detect event there + * are two options: + * - do not call sdhci_runtime_suspend() but save power by disabling + * all clocks excepting the one for the controller interface. + * - call sdhci_runtime_suspend(), save maximum power by disabling + * all clocks but use a gpio for the card detect signal to have a way + * to wakeup. + */ + if (sdhci_at91_use_sdhci_runtime(host)) { + ret = sdhci_runtime_suspend_host(host); + clk_disable_unprepare(priv->hclock); + } clk_disable_unprepare(priv->gck); - clk_disable_unprepare(priv->hclock); clk_disable_unprepare(priv->mainck); return ret; @@ -84,19 +104,23 @@ static int sdhci_at91_runtime_resume(struct device *dev) return ret; } - ret = clk_prepare_enable(priv->hclock); - if (ret) { - dev_err(dev, "can't enable hclock\n"); - return ret; - } - ret = clk_prepare_enable(priv->gck); if (ret) { dev_err(dev, "can't enable gck\n"); return ret; } - return sdhci_runtime_resume_host(host); + if (sdhci_at91_use_sdhci_runtime(host)) { + ret = clk_prepare_enable(priv->hclock); + if (ret) { + dev_err(dev, "can't enable hclock\n"); + return ret; + } + + ret = sdhci_runtime_resume_host(host); + } + + return ret; } #endif /* CONFIG_PM */