Commit 67e6db11 authored by Pramod Gurav's avatar Pramod Gurav Committed by Ulf Hansson

mmc: sdhci-msm: Add pm_runtime and system PM support

Provides runtime PM callbacks to enable and disable clock resources
when idle. Also support system PM callbacks to be called during system
suspend and resume.
Reviewed-by: default avatarRitesh Harjani <riteshh@codeaurora.org>
Reviewed-by: default avatarGeorgi Djakov <georgi.djakov@linaro.org>
Tested-by: default avatarRitesh Harjani <riteshh@codeaurora.org>
Signed-off-by: default avatarPramod Gurav <pramod.gurav@linaro.org>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 424feb59
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/mmc/mmc.h> #include <linux/mmc/mmc.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "sdhci-pltfm.h" #include "sdhci-pltfm.h"
...@@ -68,6 +69,7 @@ ...@@ -68,6 +69,7 @@
#define CMUX_SHIFT_PHASE_SHIFT 24 #define CMUX_SHIFT_PHASE_SHIFT 24
#define CMUX_SHIFT_PHASE_MASK (7 << CMUX_SHIFT_PHASE_SHIFT) #define CMUX_SHIFT_PHASE_MASK (7 << CMUX_SHIFT_PHASE_SHIFT)
#define MSM_MMC_AUTOSUSPEND_DELAY_MS 50
struct sdhci_msm_host { struct sdhci_msm_host {
struct platform_device *pdev; struct platform_device *pdev;
void __iomem *core_mem; /* MSM SDCC mapped address */ void __iomem *core_mem; /* MSM SDCC mapped address */
...@@ -659,12 +661,26 @@ static int sdhci_msm_probe(struct platform_device *pdev) ...@@ -659,12 +661,26 @@ static int sdhci_msm_probe(struct platform_device *pdev)
goto clk_disable; goto clk_disable;
} }
pm_runtime_get_noresume(&pdev->dev);
pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
pm_runtime_set_autosuspend_delay(&pdev->dev,
MSM_MMC_AUTOSUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(&pdev->dev);
ret = sdhci_add_host(host); ret = sdhci_add_host(host);
if (ret) if (ret)
goto clk_disable; goto pm_runtime_disable;
pm_runtime_mark_last_busy(&pdev->dev);
pm_runtime_put_autosuspend(&pdev->dev);
return 0; return 0;
pm_runtime_disable:
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
clk_disable: clk_disable:
clk_disable_unprepare(msm_host->clk); clk_disable_unprepare(msm_host->clk);
pclk_disable: pclk_disable:
...@@ -686,6 +702,11 @@ static int sdhci_msm_remove(struct platform_device *pdev) ...@@ -686,6 +702,11 @@ static int sdhci_msm_remove(struct platform_device *pdev)
0xffffffff); 0xffffffff);
sdhci_remove_host(host, dead); sdhci_remove_host(host, dead);
pm_runtime_get_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
clk_disable_unprepare(msm_host->clk); clk_disable_unprepare(msm_host->clk);
clk_disable_unprepare(msm_host->pclk); clk_disable_unprepare(msm_host->pclk);
if (!IS_ERR(msm_host->bus_clk)) if (!IS_ERR(msm_host->bus_clk))
...@@ -694,12 +715,57 @@ static int sdhci_msm_remove(struct platform_device *pdev) ...@@ -694,12 +715,57 @@ static int sdhci_msm_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_PM
static int sdhci_msm_runtime_suspend(struct device *dev)
{
struct sdhci_host *host = dev_get_drvdata(dev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
clk_disable_unprepare(msm_host->clk);
clk_disable_unprepare(msm_host->pclk);
return 0;
}
static int sdhci_msm_runtime_resume(struct device *dev)
{
struct sdhci_host *host = dev_get_drvdata(dev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
int ret;
ret = clk_prepare_enable(msm_host->clk);
if (ret) {
dev_err(dev, "clk_enable failed for core_clk: %d\n", ret);
return ret;
}
ret = clk_prepare_enable(msm_host->pclk);
if (ret) {
dev_err(dev, "clk_enable failed for iface_clk: %d\n", ret);
clk_disable_unprepare(msm_host->clk);
return ret;
}
return 0;
}
#endif
static const struct dev_pm_ops sdhci_msm_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
pm_runtime_force_resume)
SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend,
sdhci_msm_runtime_resume,
NULL)
};
static struct platform_driver sdhci_msm_driver = { static struct platform_driver sdhci_msm_driver = {
.probe = sdhci_msm_probe, .probe = sdhci_msm_probe,
.remove = sdhci_msm_remove, .remove = sdhci_msm_remove,
.driver = { .driver = {
.name = "sdhci_msm", .name = "sdhci_msm",
.of_match_table = sdhci_msm_dt_match, .of_match_table = sdhci_msm_dt_match,
.pm = &sdhci_msm_pm_ops,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment