From: Kristen Carlson Accardi Date: Thu, 25 Aug 2011 11:12:47 +0000 (+0100) Subject: sdhci: Add runtime pm support for sdhci-pci X-Git-Tag: 2.1b_release~2079 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98cf73549f416124e1fca318de2688914c9e821b;p=kernel%2Fkernel-mfld-blackbay.git sdhci: Add runtime pm support for sdhci-pci Ported the parts that were not upstream from the mrst kernel. Change-Id: I78ada0b020c11376e09120236fc8bbec92d036ea Signed-off-by: Kristen Carlson Accardi --- diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c index 26c5286..29e6b7c 100644 --- a/drivers/mmc/host/sdhci-pci.c +++ b/drivers/mmc/host/sdhci-pci.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "sdhci.h" @@ -944,6 +945,95 @@ static int sdhci_pci_resume(struct pci_dev *pdev) #endif /* CONFIG_PM */ +#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; + pm_message_t state = { .event = PM_EVENT_SUSPEND }; + int i, ret; + + 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_host(slot->host); + + if (ret) { + for (i--; i >= 0; i--) + sdhci_runtime_resume_host(chip->slots[i]->host); + return ret; + } + } + + 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_host(chip->slots[i]->host); + return ret; + } + } + + 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; + + 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_host(slot->host); + if (ret) + return ret; + } + + return 0; +} + +static int sdhci_pci_runtime_idle(struct device *dev) +{ + return 0; +} + +#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, +}; + /*****************************************************************************\ * * * Device probing/removal * @@ -1133,6 +1223,12 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev, chip->slots[i] = slot; } + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_allow(&pdev->dev); + pm_runtime_set_autosuspend_delay(&pdev->dev, 50); + pm_runtime_use_autosuspend(&pdev->dev); + pm_suspend_ignore_children(&pdev->dev, 1); + return 0; free: @@ -1159,6 +1255,8 @@ static void __devexit sdhci_pci_remove(struct pci_dev *pdev) kfree(chip); } + pm_runtime_forbid(&pdev->dev); + pm_runtime_get_noresume(&pdev->dev); pci_disable_device(pdev); } @@ -1169,6 +1267,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 5345a40..ef9bd6c 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -1274,6 +1275,7 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) struct sdhci_host *host; unsigned long flags; u8 ctrl; + unsigned int lastclock; host = mmc_priv(mmc); @@ -1282,6 +1284,19 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (host->flags & SDHCI_DEVICE_DEAD) goto out; + lastclock = host->iosclock; + host->iosclock = ios->clock; + if (lastclock == 0 && ios->clock != 0) { + spin_unlock_irqrestore(&host->lock, flags); + pm_runtime_get_sync(host->mmc->parent); + spin_lock_irqsave(&host->lock, flags); + } else if (lastclock != 0 && ios->clock == 0) { + spin_unlock_irqrestore(&host->lock, flags); + pm_runtime_mark_last_busy(host->mmc->parent); + pm_runtime_put_autosuspend(host->mmc->parent); + spin_lock_irqsave(&host->lock, flags); + } + /* * Reset the chip on each power off. * Should clear out any weird states. @@ -2313,6 +2328,32 @@ void sdhci_enable_irq_wakeups(struct sdhci_host *host) EXPORT_SYMBOL_GPL(sdhci_enable_irq_wakeups); #endif /* CONFIG_PM */ +#ifdef CONFIG_PM_RUNTIME + +int sdhci_runtime_suspend_host(struct sdhci_host *host) +{ + int ret = 0; + + if (host->vmmc) + ret = regulator_disable(host->vmmc); + + return ret; +} +EXPORT_SYMBOL_GPL(sdhci_runtime_suspend_host); + +int sdhci_runtime_resume_host(struct sdhci_host *host) +{ + int ret = 0; + + if (host->vmmc) + if ((ret = regulator_enable(host->vmmc))) + return ret; + + return ret; +} +EXPORT_SYMBOL_GPL(sdhci_runtime_resume_host); + +#endif /*****************************************************************************\ * * @@ -2334,6 +2375,7 @@ struct sdhci_host *sdhci_alloc_host(struct device *dev, host = mmc_priv(mmc); host->mmc = mmc; + host->iosclock = 0; return host; } diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 745c42f..9372981 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -379,4 +379,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_host(struct sdhci_host *host); +extern int sdhci_runtime_resume_host(struct sdhci_host *host); +#endif + #endif /* __SDHCI_HW_H */ diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h index 6a68c4e..c8b9519 100644 --- a/include/linux/mmc/sdhci.h +++ b/include/linux/mmc/sdhci.h @@ -123,6 +123,7 @@ struct sdhci_host { unsigned int clk_mul; /* Clock Muliplier value */ unsigned int clock; /* Current clock (MHz) */ + unsigned int iosclock; /* Last clock asked via set_ios */ u8 pwr; /* Current voltage */ struct mmc_request *mrq; /* Current request */