Commit a232a8f2 authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Ulf Hansson

mmc: sdhci-cadence: add suspend / resume support

Currently, the probe function initializes the PHY, but PHY settings
are lost during the sleep state.  Restore the PHY registers when
resuming.

To facilitate this, split sdhci_cdns_phy_init() into the DT parse
part and PHY update part so that the latter can be invoked from the
resume hook.
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent aab6e25a
...@@ -67,9 +67,16 @@ ...@@ -67,9 +67,16 @@
*/ */
#define SDHCI_CDNS_MAX_TUNING_LOOP 40 #define SDHCI_CDNS_MAX_TUNING_LOOP 40
struct sdhci_cdns_phy_param {
u8 addr;
u8 data;
};
struct sdhci_cdns_priv { struct sdhci_cdns_priv {
void __iomem *hrs_addr; void __iomem *hrs_addr;
bool enhanced_strobe; bool enhanced_strobe;
unsigned int nr_phy_params;
struct sdhci_cdns_phy_param phy_params[0];
}; };
struct sdhci_cdns_phy_cfg { struct sdhci_cdns_phy_cfg {
...@@ -115,9 +122,22 @@ static int sdhci_cdns_write_phy_reg(struct sdhci_cdns_priv *priv, ...@@ -115,9 +122,22 @@ static int sdhci_cdns_write_phy_reg(struct sdhci_cdns_priv *priv,
return 0; return 0;
} }
static int sdhci_cdns_phy_init(struct device_node *np, static unsigned int sdhci_cdns_phy_param_count(struct device_node *np)
struct sdhci_cdns_priv *priv)
{ {
unsigned int count = 0;
int i;
for (i = 0; i < ARRAY_SIZE(sdhci_cdns_phy_cfgs); i++)
if (of_property_read_bool(np, sdhci_cdns_phy_cfgs[i].property))
count++;
return count;
}
static void sdhci_cdns_phy_param_parse(struct device_node *np,
struct sdhci_cdns_priv *priv)
{
struct sdhci_cdns_phy_param *p = priv->phy_params;
u32 val; u32 val;
int ret, i; int ret, i;
...@@ -127,9 +147,19 @@ static int sdhci_cdns_phy_init(struct device_node *np, ...@@ -127,9 +147,19 @@ static int sdhci_cdns_phy_init(struct device_node *np,
if (ret) if (ret)
continue; continue;
ret = sdhci_cdns_write_phy_reg(priv, p->addr = sdhci_cdns_phy_cfgs[i].addr;
sdhci_cdns_phy_cfgs[i].addr, p->data = val;
val); p++;
}
}
static int sdhci_cdns_phy_init(struct sdhci_cdns_priv *priv)
{
int ret, i;
for (i = 0; i < priv->nr_phy_params; i++) {
ret = sdhci_cdns_write_phy_reg(priv, priv->phy_params[i].addr,
priv->phy_params[i].data);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -302,6 +332,8 @@ static int sdhci_cdns_probe(struct platform_device *pdev) ...@@ -302,6 +332,8 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
struct sdhci_pltfm_host *pltfm_host; struct sdhci_pltfm_host *pltfm_host;
struct sdhci_cdns_priv *priv; struct sdhci_cdns_priv *priv;
struct clk *clk; struct clk *clk;
size_t priv_size;
unsigned int nr_phy_params;
int ret; int ret;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -313,7 +345,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev) ...@@ -313,7 +345,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
host = sdhci_pltfm_init(pdev, &sdhci_cdns_pltfm_data, sizeof(*priv)); nr_phy_params = sdhci_cdns_phy_param_count(dev->of_node);
priv_size = sizeof(*priv) + sizeof(priv->phy_params[0]) * nr_phy_params;
host = sdhci_pltfm_init(pdev, &sdhci_cdns_pltfm_data, priv_size);
if (IS_ERR(host)) { if (IS_ERR(host)) {
ret = PTR_ERR(host); ret = PTR_ERR(host);
goto disable_clk; goto disable_clk;
...@@ -322,7 +356,8 @@ static int sdhci_cdns_probe(struct platform_device *pdev) ...@@ -322,7 +356,8 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
pltfm_host = sdhci_priv(host); pltfm_host = sdhci_priv(host);
pltfm_host->clk = clk; pltfm_host->clk = clk;
priv = sdhci_cdns_priv(host); priv = sdhci_pltfm_priv(pltfm_host);
priv->nr_phy_params = nr_phy_params;
priv->hrs_addr = host->ioaddr; priv->hrs_addr = host->ioaddr;
priv->enhanced_strobe = false; priv->enhanced_strobe = false;
host->ioaddr += SDHCI_CDNS_SRS_BASE; host->ioaddr += SDHCI_CDNS_SRS_BASE;
...@@ -336,7 +371,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev) ...@@ -336,7 +371,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
if (ret) if (ret)
goto free; goto free;
ret = sdhci_cdns_phy_init(dev->of_node, priv); sdhci_cdns_phy_param_parse(dev->of_node, priv);
ret = sdhci_cdns_phy_init(priv);
if (ret) if (ret)
goto free; goto free;
...@@ -353,6 +390,57 @@ static int sdhci_cdns_probe(struct platform_device *pdev) ...@@ -353,6 +390,57 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
return ret; return ret;
} }
#ifdef CONFIG_PM_SLEEP
static int sdhci_cdns_suspend(struct device *dev)
{
struct sdhci_host *host = dev_get_drvdata(dev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
int ret;
if (host->tuning_mode != SDHCI_TUNING_MODE_3)
mmc_retune_needed(host->mmc);
ret = sdhci_suspend_host(host);
if (ret)
return ret;
clk_disable_unprepare(pltfm_host->clk);
return 0;
}
static int sdhci_cdns_resume(struct device *dev)
{
struct sdhci_host *host = dev_get_drvdata(dev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_cdns_priv *priv = sdhci_pltfm_priv(pltfm_host);
int ret;
ret = clk_prepare_enable(pltfm_host->clk);
if (ret)
return ret;
ret = sdhci_cdns_phy_init(priv);
if (ret)
goto disable_clk;
ret = sdhci_resume_host(host);
if (ret)
goto disable_clk;
return 0;
disable_clk:
clk_disable_unprepare(pltfm_host->clk);
return ret;
}
#endif
static const struct dev_pm_ops sdhci_cdns_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(sdhci_cdns_suspend, sdhci_cdns_resume)
};
static const struct of_device_id sdhci_cdns_match[] = { static const struct of_device_id sdhci_cdns_match[] = {
{ .compatible = "socionext,uniphier-sd4hc" }, { .compatible = "socionext,uniphier-sd4hc" },
{ .compatible = "cdns,sd4hc" }, { .compatible = "cdns,sd4hc" },
...@@ -363,7 +451,7 @@ MODULE_DEVICE_TABLE(of, sdhci_cdns_match); ...@@ -363,7 +451,7 @@ MODULE_DEVICE_TABLE(of, sdhci_cdns_match);
static struct platform_driver sdhci_cdns_driver = { static struct platform_driver sdhci_cdns_driver = {
.driver = { .driver = {
.name = "sdhci-cdns", .name = "sdhci-cdns",
.pm = &sdhci_pltfm_pmops, .pm = &sdhci_cdns_pm_ops,
.of_match_table = sdhci_cdns_match, .of_match_table = sdhci_cdns_match,
}, },
.probe = sdhci_cdns_probe, .probe = sdhci_cdns_probe,
......
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