From patchwork Fri Mar 25 16:05:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovic Desroches X-Patchwork-Id: 8672401 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 CF73C9F36E for ; Fri, 25 Mar 2016 16:06:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D7D4A202A1 for ; Fri, 25 Mar 2016 16:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEEA82028D for ; Fri, 25 Mar 2016 16:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753882AbcCYQFq (ORCPT ); Fri, 25 Mar 2016 12:05:46 -0400 Received: from eusmtp01.atmel.com ([212.144.249.243]:5033 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753564AbcCYQFo (ORCPT ); Fri, 25 Mar 2016 12:05:44 -0400 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; Fri, 25 Mar 2016 17:05:34 +0100 From: Ludovic Desroches To: , CC: , , , , Ludovic Desroches Subject: [PATCH] mmc: sdhci-of-at91: allow the use of controller card detect as wake up Date: Fri, 25 Mar 2016 17:05:03 +0100 Message-ID: <1458921903-11133-3-git-send-email-ludovic.desroches@atmel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458921903-11133-1-git-send-email-ludovic.desroches@atmel.com> References: <1458921903-11133-1-git-send-email-ludovic.desroches@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=-7.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 At the moment, there are only two ways to wake up from runtime suspend state: - using a gpio for the card detection which is not a good solution since you still need the card detect pin of the controller. - using polling which is also not a good solution since it will resume/suspend the controller between each attempt. The sdhci layer makes the assumption that all the clocks are disabled when suspending the controller. For that reason, irqs are rejected if runtime_suspended is true. This patch duplicates the sdhci_runtime_suspend_host() but doesn't set runtime_suspended and doesn't disable the interface clock if there is a removable device and no gpio for card detection. Signed-off-by: Ludovic Desroches --- drivers/mmc/host/sdhci-of-at91.c | 71 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c index 2703aa9..6683f2d 100644 --- a/drivers/mmc/host/sdhci-of-at91.c +++ b/drivers/mmc/host/sdhci-of-at91.c @@ -35,6 +35,7 @@ struct sdhci_at91_priv { struct clk *hclock; struct clk *gck; struct clk *mainck; + bool disable_interface_clk; }; static const struct sdhci_ops sdhci_at91_sama5d2_ops = { @@ -55,20 +56,47 @@ static const struct of_device_id sdhci_at91_dt_match[] = { }; #ifdef CONFIG_PM +/* + * This function is the very same as sdhci_runtime_suspend_host but if the + * device is removable and we only have the controller card detect signal then + * we won't disable all the clocks. The interface clock will be needed to get + * card event interrupt. + * When calling sdhci_runtime_suspend_host(), the sdhci layer makes the + * assumption that all the clocks of the controller are disabled. If + * runtime_suspended is set, irqs will be rejected. That's why it won't be set + * if we want to wake up on card event. + */ 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 = sdhci_pltfm_priv(pltfm_host); - int ret; + unsigned long flags; + + mmc_retune_timer_stop(host->mmc); + mmc_retune_needed(host->mmc); + + spin_lock_irqsave(&host->lock, flags); + host->ier &= SDHCI_INT_CARD_INT; + if (!priv->disable_interface_clk) + host->ier |= SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE; + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); + spin_unlock_irqrestore(&host->lock, flags); - ret = sdhci_runtime_suspend_host(host); + synchronize_hardirq(host->irq); + + if (priv->disable_interface_clk) { + spin_lock_irqsave(&host->lock, flags); + host->runtime_suspended = true; + spin_unlock_irqrestore(&host->lock, flags); + clk_disable_unprepare(priv->hclock); + }; clk_disable_unprepare(priv->gck); - clk_disable_unprepare(priv->hclock); clk_disable_unprepare(priv->mainck); - return ret; + return 0; } static int sdhci_at91_runtime_resume(struct device *dev) @@ -84,18 +112,20 @@ 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; } + if (priv->disable_interface_clk) { + ret = clk_prepare_enable(priv->hclock); + if (ret) { + dev_err(dev, "can't enable hclock\n"); + return ret; + } + } + return sdhci_runtime_resume_host(host); } #endif /* CONFIG_PM */ @@ -206,23 +236,12 @@ static int sdhci_at91_probe(struct platform_device *pdev) goto pm_runtime_disable; /* - * When calling sdhci_runtime_suspend_host(), the sdhci layer makes - * the assumption that all the clocks of the controller are disabled. - * It means we can't get irq from it when it is runtime suspended. - * For that reason, it is not planned to wake-up on a card detect irq - * from the controller. - * If we want to use runtime PM and to be able to wake-up on card - * insertion, we have to use a GPIO for the card detection or we can - * use polling. Be aware that using polling will resume/suspend the - * controller between each attempt. - * Disable SDHCI_QUIRK_BROKEN_CARD_DETECTION to be sure nobody tries - * to enable polling via device tree with broken-cd property. + * If the device is non removable or if there is a gpio for the card + * detection, all the clocks can be disabled in runtime suspend state. */ - if (!(host->mmc->caps & MMC_CAP_NONREMOVABLE) && - IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc))) { - host->mmc->caps |= MMC_CAP_NEEDS_POLL; - host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; - } + priv->disable_interface_clk = (host->mmc->caps & MMC_CAP_NONREMOVABLE) + || !IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc)); + pm_runtime_put_autosuspend(&pdev->dev);