From 19d06f1973bcc8c10d48c6111cc3f7865af99720 Mon Sep 17 00:00:00 2001 From: Anson Huang Date: Tue, 8 Nov 2016 20:33:16 +0800 Subject: [PATCH] MLK-13441-16 mmc: host: imx: add pm_qos to interact with cpuidle On some SoCs such as i.MX7ULP, there is no busfreq driver, but cpuidle has some levels which may disable system/bus clocks, so need to add pm_qos to prevent cpuidle from entering low level idles and make sure system/bus clocks are enabled when usdhc is active. Signed-off-by: Anson Huang --- drivers/mmc/host/sdhci-esdhc-imx.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 7eb32af793d0..c3c930c122f5 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -153,6 +154,8 @@ #define ESDHC_FLAG_ERR010450 BIT(11) /* need request bus freq during low power */ #define ESDHC_FLAG_BUSFREQ BIT(12) +/* need request pmqos during low power */ +#define ESDHC_FLAG_PMQOS BIT(13) /* A higher clock ferquency than this rate requires strobell dll control */ #define ESDHC_STROBE_DLL_CLK_FREQ 100000000 @@ -222,6 +225,13 @@ static struct esdhc_soc_data usdhc_imx7d_data = { | ESDHC_FLAG_BUSFREQ, }; +static struct esdhc_soc_data usdhc_imx7ulp_data = { + .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING + | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200 + | ESDHC_FLAG_STATE_LOST_IN_LPMODE + | ESDHC_FLAG_PMQOS, +}; + struct pltfm_imx_data { u32 scratchpad; struct pinctrl *pinctrl; @@ -239,6 +249,7 @@ struct pltfm_imx_data { WAIT_FOR_INT, /* sent CMD12, waiting for response INT */ } multiblock_status; u32 is_ddr; + struct pm_qos_request pm_qos_req; }; static const struct platform_device_id imx_esdhc_devtype[] = { @@ -267,6 +278,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = { { .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, }, { .compatible = "fsl,imx6ull-usdhc", .data = &usdhc_imx6ull_data, }, { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, }, + { .compatible = "fsl,imx7ulp-usdhc", .data = &usdhc_imx7ulp_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids); @@ -1312,6 +1324,10 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) if (imx_data->socdata->flags & ESDHC_FLAG_BUSFREQ) request_bus_freq(BUS_FREQ_HIGH); + if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) + pm_qos_add_request(&imx_data->pm_qos_req, + PM_QOS_CPU_DMA_LATENCY, 0); + clk_prepare_enable(imx_data->clk_per); clk_prepare_enable(imx_data->clk_ipg); clk_prepare_enable(imx_data->clk_ahb); @@ -1384,6 +1400,9 @@ disable_clk: clk_disable_unprepare(imx_data->clk_ahb); if (imx_data->socdata->flags & ESDHC_FLAG_BUSFREQ) release_bus_freq(BUS_FREQ_HIGH); + + if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) + pm_qos_remove_request(&imx_data->pm_qos_req); free_sdhci: sdhci_pltfm_free(pdev); return err; @@ -1396,6 +1415,9 @@ static int sdhci_esdhc_imx_remove(struct platform_device *pdev) struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host); int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); + if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) + pm_qos_remove_request(&imx_data->pm_qos_req); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); @@ -1471,6 +1493,9 @@ static int sdhci_esdhc_runtime_suspend(struct device *dev) if (imx_data->socdata->flags & ESDHC_FLAG_BUSFREQ) release_bus_freq(BUS_FREQ_HIGH); + if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) + pm_qos_remove_request(&imx_data->pm_qos_req); + return ret; } @@ -1483,6 +1508,10 @@ static int sdhci_esdhc_runtime_resume(struct device *dev) if (imx_data->socdata->flags & ESDHC_FLAG_BUSFREQ) request_bus_freq(BUS_FREQ_HIGH); + if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) + pm_qos_add_request(&imx_data->pm_qos_req, + PM_QOS_CPU_DMA_LATENCY, 0); + if (!sdhci_sdio_irq_enabled(host)) { clk_prepare_enable(imx_data->clk_per); clk_prepare_enable(imx_data->clk_ipg); -- 2.17.1