From patchwork Sun Feb 6 18:02:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Tardy X-Patchwork-Id: 538391 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p17Gt8Vh009965 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 7 Feb 2011 16:55:28 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p17Grd2V001804; Mon, 7 Feb 2011 08:53:39 -0800 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p16I3Mkh001550 for ; Sun, 6 Feb 2011 10:03:23 -0800 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 06 Feb 2011 10:03:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.60,434,1291622400"; d="scan'208";a="884836438" Received: from ptardy-mobl3.ger.corp.intel.com (HELO ptardy-VirtualBox.ger.corp.intel.com) ([10.254.185.112]) by fmsmga001.fm.intel.com with ESMTP; 06 Feb 2011 10:03:20 -0800 From: Pierre Tardy To: linux-pm@lists.linux-foundation.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sun, 6 Feb 2011 19:02:49 +0100 Message-Id: <6722fa7986194808f4d69a1e5ba6d3f163b77da9.1297014479.git.pierre.tardy@intel.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-103.798 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, USER_IN_WHITELIST X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 X-Mailman-Approved-At: Mon, 07 Feb 2011 08:48:36 -0800 Cc: Pierre Tardy , Yunpeng Gao Subject: [linux-pm] [PATCH v2 2/3] sdhci-pci : Enable runtime PM support X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 07 Feb 2011 16:55:28 +0000 (UTC) diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c index 0dc905b..22581a1 100644 --- a/drivers/mmc/host/sdhci-pci.c +++ b/drivers/mmc/host/sdhci-pci.c @@ -1027,6 +1027,8 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev, if (ret) return ret; + pm_runtime_set_active(&pdev->dev); + slots = PCI_SLOT_INFO_SLOTS(slots) + 1; dev_dbg(&pdev->dev, "found %d slot(s)\n", slots); if (slots == 0) @@ -1082,6 +1084,8 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev, chip->slots[i] = slot; } + pm_runtime_enable(&pdev->dev); + pm_runtime_allow(&pdev->dev); return 0; @@ -1110,8 +1114,122 @@ static void __devexit sdhci_pci_remove(struct pci_dev *pdev) } pci_disable_device(pdev); + + pm_runtime_forbid(&pdev->dev); + pm_runtime_disable(&pdev->dev); + +} + +#ifdef CONFIG_PM_RUNTIME + +static int sdhci_pci_runtime_suspend(struct device *dev) +{ + struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); + struct sdhci_pci_chip *chip; + struct sdhci_pci_slot *slot; + int i, ret; + mmc_pm_flag_t pm_flags = 0; + pm_message_t state; + + chip = pci_get_drvdata(pdev); + if (!chip) + return 0; + + for (i = 0; i < chip->num_slots; i++) { + slot = chip->slots[i]; + if (!slot) + continue; + + ret = sdhci_runtime_suspend(slot->host); + + if (ret) { + for (i--; i >= 0; i--) + sdhci_runtime_resume(chip->slots[i]->host); + return ret; + } + + pm_flags |= slot->host->mmc->pm_flags; + } + + state.event = PM_EVENT_AUTO_SUSPEND; + if (chip->fixes && chip->fixes->suspend) { + ret = chip->fixes->suspend(chip, state); + if (ret) { + for (i = chip->num_slots - 1; i >= 0; i--) + sdhci_runtime_resume(chip->slots[i]->host); + return ret; + } + } + + pci_save_state(pdev); + if (pm_flags & MMC_PM_KEEP_POWER) { + if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) + pci_enable_wake(pdev, PCI_D3hot, 1); + } else { + pci_enable_wake(pdev, PCI_D3hot, 0); + pci_disable_device(pdev); + } + pci_set_power_state(pdev, PCI_D3hot); + + return 0; } +static int sdhci_pci_runtime_resume(struct device *dev) +{ + struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); + struct sdhci_pci_chip *chip; + struct sdhci_pci_slot *slot; + int i, ret; + + chip = pci_get_drvdata(pdev); + if (!chip) + return 0; + + pci_set_power_state(pdev, PCI_D0); + pci_restore_state(pdev); + ret = pci_enable_device(pdev); + if (ret) + return ret; + + if (chip->fixes && chip->fixes->resume) { + ret = chip->fixes->resume(chip); + if (ret) + return ret; + } + + for (i = 0; i < chip->num_slots; i++) { + slot = chip->slots[i]; + if (!slot) + continue; + + ret = sdhci_runtime_resume(slot->host); + if (ret) + return ret; + } + + return 0; +} + +static int sdhci_pci_runtime_idle(struct device *dev) +{ + pm_runtime_autosuspend(dev); + return -EAGAIN; +} + +#else + +#define sdhci_pci_runtime_suspend NULL +#define sdhci_pci_runtime_resume NULL +#define sdhci_pci_runtime_idle NULL + +#endif + +static const struct dev_pm_ops sdhci_pci_pm_ops = { + .runtime_suspend = sdhci_pci_runtime_suspend, + .runtime_resume = sdhci_pci_runtime_resume, + .runtime_idle = sdhci_pci_runtime_idle, +}; + static struct pci_driver sdhci_driver = { .name = "sdhci-pci", .id_table = pci_ids, @@ -1119,6 +1237,9 @@ static struct pci_driver sdhci_driver = { .remove = __devexit_p(sdhci_pci_remove), .suspend = sdhci_pci_suspend, .resume = sdhci_pci_resume, + .driver = { + .pm = &sdhci_pci_pm_ops + }, }; /*****************************************************************************\ diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 9e15f41..3e65d94 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1715,6 +1715,37 @@ EXPORT_SYMBOL_GPL(sdhci_enable_irq_wakeups); #endif /* CONFIG_PM */ +#ifdef CONFIG_PM_RUNTIME + +int sdhci_runtime_suspend(struct sdhci_host *host) +{ + /* Nothing to do yet. Still leave the placeholder */ + return 0; +} + +EXPORT_SYMBOL_GPL(sdhci_runtime_suspend); + +int sdhci_runtime_resume(struct sdhci_host *host) +{ + int ret = 0; + + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { + if (host->ops->enable_dma) + host->ops->enable_dma(host); + } + + sdhci_init(host, (host->mmc->pm_flags & MMC_PM_KEEP_POWER)); + host->pwr = 0; /* force power reprogram */ + host->clock = 0; /* force clock reprogram */ + sdhci_set_ios(host->mmc, &host->mmc->ios); + mmiowb(); + + return ret; +} +EXPORT_SYMBOL_GPL(sdhci_runtime_resume); + +#endif /* CONFIG_PM_RUNTIME */ + /*****************************************************************************\ * * * Device allocation/registration * diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 6e0969e..1f032c0 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -327,4 +327,9 @@ extern int sdhci_resume_host(struct sdhci_host *host); extern void sdhci_enable_irq_wakeups(struct sdhci_host *host); #endif +#ifdef CONFIG_PM_RUNTIME +extern int sdhci_runtime_suspend(struct sdhci_host *host); +extern int sdhci_runtime_resume(struct sdhci_host *host); +#endif + #endif /* __SDHCI_HW_H */