Skip to content

Commit 89d7e5c

Browse files
Dong Aishengcjb
authored andcommitted
mmc: sdhci-esdhc-imx: add runtime pm support
The root clock will be disabled in runtime pm to save power. Signed-off-by: Dong Aisheng <[email protected]> Acked-by: Ulf Hansson <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent ce090a4 commit 89d7e5c

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

drivers/mmc/host/sdhci-esdhc-imx.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/of_gpio.h>
2828
#include <linux/pinctrl/consumer.h>
2929
#include <linux/platform_data/mmc-esdhc-imx.h>
30+
#include <linux/pm_runtime.h>
3031
#include "sdhci-pltfm.h"
3132
#include "sdhci-esdhc.h"
3233

@@ -1121,6 +1122,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
11211122
if (err)
11221123
goto disable_clk;
11231124

1125+
pm_runtime_set_active(&pdev->dev);
1126+
pm_runtime_enable(&pdev->dev);
1127+
pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
1128+
pm_runtime_use_autosuspend(&pdev->dev);
1129+
pm_suspend_ignore_children(&pdev->dev, 1);
1130+
11241131
return 0;
11251132

11261133
disable_clk:
@@ -1141,6 +1148,9 @@ static int sdhci_esdhc_imx_remove(struct platform_device *pdev)
11411148

11421149
sdhci_remove_host(host, dead);
11431150

1151+
pm_runtime_dont_use_autosuspend(&pdev->dev);
1152+
pm_runtime_disable(&pdev->dev);
1153+
11441154
clk_disable_unprepare(imx_data->clk_per);
11451155
clk_disable_unprepare(imx_data->clk_ipg);
11461156
clk_disable_unprepare(imx_data->clk_ahb);
@@ -1150,12 +1160,49 @@ static int sdhci_esdhc_imx_remove(struct platform_device *pdev)
11501160
return 0;
11511161
}
11521162

1163+
#ifdef CONFIG_PM_RUNTIME
1164+
static int sdhci_esdhc_runtime_suspend(struct device *dev)
1165+
{
1166+
struct sdhci_host *host = dev_get_drvdata(dev);
1167+
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
1168+
struct pltfm_imx_data *imx_data = pltfm_host->priv;
1169+
int ret;
1170+
1171+
ret = sdhci_runtime_suspend_host(host);
1172+
1173+
clk_disable_unprepare(imx_data->clk_per);
1174+
clk_disable_unprepare(imx_data->clk_ipg);
1175+
clk_disable_unprepare(imx_data->clk_ahb);
1176+
1177+
return ret;
1178+
}
1179+
1180+
static int sdhci_esdhc_runtime_resume(struct device *dev)
1181+
{
1182+
struct sdhci_host *host = dev_get_drvdata(dev);
1183+
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
1184+
struct pltfm_imx_data *imx_data = pltfm_host->priv;
1185+
1186+
clk_prepare_enable(imx_data->clk_per);
1187+
clk_prepare_enable(imx_data->clk_ipg);
1188+
clk_prepare_enable(imx_data->clk_ahb);
1189+
1190+
return sdhci_runtime_resume_host(host);
1191+
}
1192+
#endif
1193+
1194+
static const struct dev_pm_ops sdhci_esdhc_pmops = {
1195+
SET_SYSTEM_SLEEP_PM_OPS(sdhci_pltfm_suspend, sdhci_pltfm_resume)
1196+
SET_RUNTIME_PM_OPS(sdhci_esdhc_runtime_suspend,
1197+
sdhci_esdhc_runtime_resume, NULL)
1198+
};
1199+
11531200
static struct platform_driver sdhci_esdhc_imx_driver = {
11541201
.driver = {
11551202
.name = "sdhci-esdhc-imx",
11561203
.owner = THIS_MODULE,
11571204
.of_match_table = imx_esdhc_dt_ids,
1158-
.pm = SDHCI_PLTFM_PMOPS,
1205+
.pm = &sdhci_esdhc_pmops,
11591206
},
11601207
.id_table = imx_esdhc_devtype,
11611208
.probe = sdhci_esdhc_imx_probe,

0 commit comments

Comments
 (0)