Commit 1ecd34dd authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Tejun Heo

ata: sata_rcar: Add rudimentary Runtime PM support

Replace the explicit clock handling to enable/disable the SATA module by
calls to Runtime PM.

This makes the driver independent of actual SoC clock/power hierarchies,
and is needed to support virtualization, where the guest is not in full
control of power management.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent c01e229f
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <linux/libata.h> #include <linux/libata.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/clk.h> #include <linux/pm_runtime.h>
#include <linux/err.h> #include <linux/err.h>
#define DRV_NAME "sata_rcar" #define DRV_NAME "sata_rcar"
...@@ -152,7 +152,6 @@ enum sata_rcar_type { ...@@ -152,7 +152,6 @@ enum sata_rcar_type {
struct sata_rcar_priv { struct sata_rcar_priv {
void __iomem *base; void __iomem *base;
struct clk *clk;
enum sata_rcar_type type; enum sata_rcar_type type;
}; };
...@@ -897,21 +896,17 @@ static int sata_rcar_probe(struct platform_device *pdev) ...@@ -897,21 +896,17 @@ static int sata_rcar_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
priv->type = (enum sata_rcar_type)of_device_get_match_data(dev); priv->type = (enum sata_rcar_type)of_device_get_match_data(dev);
priv->clk = devm_clk_get(dev, NULL);
if (IS_ERR(priv->clk)) {
dev_err(dev, "failed to get access to sata clock\n");
return PTR_ERR(priv->clk);
}
ret = clk_prepare_enable(priv->clk); pm_runtime_enable(dev);
if (ret) ret = pm_runtime_get_sync(dev);
return ret; if (ret < 0)
goto err_pm_disable;
host = ata_host_alloc(dev, 1); host = ata_host_alloc(dev, 1);
if (!host) { if (!host) {
dev_err(dev, "ata_host_alloc failed\n"); dev_err(dev, "ata_host_alloc failed\n");
ret = -ENOMEM; ret = -ENOMEM;
goto cleanup; goto err_pm_put;
} }
host->private_data = priv; host->private_data = priv;
...@@ -920,7 +915,7 @@ static int sata_rcar_probe(struct platform_device *pdev) ...@@ -920,7 +915,7 @@ static int sata_rcar_probe(struct platform_device *pdev)
priv->base = devm_ioremap_resource(dev, mem); priv->base = devm_ioremap_resource(dev, mem);
if (IS_ERR(priv->base)) { if (IS_ERR(priv->base)) {
ret = PTR_ERR(priv->base); ret = PTR_ERR(priv->base);
goto cleanup; goto err_pm_put;
} }
/* setup port */ /* setup port */
...@@ -934,9 +929,10 @@ static int sata_rcar_probe(struct platform_device *pdev) ...@@ -934,9 +929,10 @@ static int sata_rcar_probe(struct platform_device *pdev)
if (!ret) if (!ret)
return 0; return 0;
cleanup: err_pm_put:
clk_disable_unprepare(priv->clk); pm_runtime_put(dev);
err_pm_disable:
pm_runtime_disable(dev);
return ret; return ret;
} }
...@@ -954,7 +950,8 @@ static int sata_rcar_remove(struct platform_device *pdev) ...@@ -954,7 +950,8 @@ static int sata_rcar_remove(struct platform_device *pdev)
iowrite32(0, base + SATAINTSTAT_REG); iowrite32(0, base + SATAINTSTAT_REG);
iowrite32(0x7ff, base + SATAINTMASK_REG); iowrite32(0x7ff, base + SATAINTMASK_REG);
clk_disable_unprepare(priv->clk); pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev);
return 0; return 0;
} }
...@@ -974,7 +971,7 @@ static int sata_rcar_suspend(struct device *dev) ...@@ -974,7 +971,7 @@ static int sata_rcar_suspend(struct device *dev)
/* mask */ /* mask */
iowrite32(0x7ff, base + SATAINTMASK_REG); iowrite32(0x7ff, base + SATAINTMASK_REG);
clk_disable_unprepare(priv->clk); pm_runtime_put(dev);
} }
return ret; return ret;
...@@ -987,8 +984,8 @@ static int sata_rcar_resume(struct device *dev) ...@@ -987,8 +984,8 @@ static int sata_rcar_resume(struct device *dev)
void __iomem *base = priv->base; void __iomem *base = priv->base;
int ret; int ret;
ret = clk_prepare_enable(priv->clk); ret = pm_runtime_get_sync(dev);
if (ret) if (ret < 0)
return ret; return ret;
if (priv->type == RCAR_GEN3_SATA) { if (priv->type == RCAR_GEN3_SATA) {
...@@ -1012,11 +1009,10 @@ static int sata_rcar_resume(struct device *dev) ...@@ -1012,11 +1009,10 @@ static int sata_rcar_resume(struct device *dev)
static int sata_rcar_restore(struct device *dev) static int sata_rcar_restore(struct device *dev)
{ {
struct ata_host *host = dev_get_drvdata(dev); struct ata_host *host = dev_get_drvdata(dev);
struct sata_rcar_priv *priv = host->private_data;
int ret; int ret;
ret = clk_prepare_enable(priv->clk); ret = pm_runtime_get_sync(dev);
if (ret) if (ret < 0)
return ret; return ret;
sata_rcar_setup_port(host); sata_rcar_setup_port(host);
......
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