diff mbox

[04/13] coresight: tpiu: let runtime PM handle core clock

Message ID 1429261140-13910-5-git-send-email-linus.walleij@linaro.org
State New
Headers show

Commit Message

Linus Walleij April 17, 2015, 8:58 a.m. UTC
This uses runtime PM to manage the PCLK ("amba_pclk") instead
of screwing around with the framework by going in and taking
a copy from the amba device. The amba bus core will uprepare
and disable the clock when the device is unused when
CONFIG_PM is selected, else the clock will be always on.

Prior to this patch, as the AMBA primecell bus code enables
the PCLK, it would be left on after probe as
the clk_prepare_enable() and clk_disable_unprepare() was
called and thus just increase and decreas the refcount by
one, without it reaching zero and actually disabling the
clock. Now the runtime PM callbacks will make sure the PCLK
is properly disabled after probe.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/coresight/coresight-tpiu.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

Comments

Ulf Hansson April 17, 2015, 9:07 a.m. UTC | #1
On 17 April 2015 at 10:58, Linus Walleij <linus.walleij@linaro.org> wrote:
> This uses runtime PM to manage the PCLK ("amba_pclk") instead
> of screwing around with the framework by going in and taking
> a copy from the amba device. The amba bus core will uprepare
> and disable the clock when the device is unused when
> CONFIG_PM is selected, else the clock will be always on.
>
> Prior to this patch, as the AMBA primecell bus code enables
> the PCLK, it would be left on after probe as
> the clk_prepare_enable() and clk_disable_unprepare() was
> called and thus just increase and decreas the refcount by
> one, without it reaching zero and actually disabling the
> clock. Now the runtime PM callbacks will make sure the PCLK
> is properly disabled after probe.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

> ---
>  drivers/coresight/coresight-tpiu.c | 21 ++++-----------------
>  1 file changed, 4 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/coresight/coresight-tpiu.c b/drivers/coresight/coresight-tpiu.c
> index 88b6b0c32538..688ba937069e 100644
> --- a/drivers/coresight/coresight-tpiu.c
> +++ b/drivers/coresight/coresight-tpiu.c
> @@ -17,7 +17,7 @@
>  #include <linux/io.h>
>  #include <linux/err.h>
>  #include <linux/slab.h>
> -#include <linux/clk.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/coresight.h>
>  #include <linux/amba/bus.h>
>
> @@ -51,13 +51,11 @@
>   * @base:      memory mapped base address for this component.
>   * @dev:       the device entity associated to this component.
>   * @csdev:     component vitals needed by the framework.
> - * @clk:       the clock this component is associated to.
>   */
>  struct tpiu_drvdata {
>         void __iomem            *base;
>         struct device           *dev;
>         struct coresight_device *csdev;
> -       struct clk              *clk;
>  };
>
>  static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
> @@ -72,12 +70,8 @@ static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
>  static int tpiu_enable(struct coresight_device *csdev)
>  {
>         struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
> -       int ret;
> -
> -       ret = clk_prepare_enable(drvdata->clk);
> -       if (ret)
> -               return ret;
>
> +       pm_runtime_get_sync(csdev->dev.parent);
>         tpiu_enable_hw(drvdata);
>
>         dev_info(drvdata->dev, "TPIU enabled\n");
> @@ -101,8 +95,7 @@ static void tpiu_disable(struct coresight_device *csdev)
>         struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
>
>         tpiu_disable_hw(drvdata);
> -
> -       clk_disable_unprepare(drvdata->clk);
> +       pm_runtime_put(csdev->dev.parent);
>
>         dev_info(drvdata->dev, "TPIU disabled\n");
>  }
> @@ -118,7 +111,6 @@ static const struct coresight_ops tpiu_cs_ops = {
>
>  static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
>  {
> -       int ret;
>         void __iomem *base;
>         struct device *dev = &adev->dev;
>         struct coresight_platform_data *pdata = NULL;
> @@ -148,15 +140,10 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
>
>         drvdata->base = base;
>
> -       drvdata->clk = adev->pclk;
> -       ret = clk_prepare_enable(drvdata->clk);
> -       if (ret)
> -               return ret;
> -
>         /* Disable tpiu to support older devices */
>         tpiu_disable_hw(drvdata);
>
> -       clk_disable_unprepare(drvdata->clk);
> +       pm_runtime_put(&adev->dev);
>
>         desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
>         if (!desc)
> --
> 1.9.3
>
diff mbox

Patch

diff --git a/drivers/coresight/coresight-tpiu.c b/drivers/coresight/coresight-tpiu.c
index 88b6b0c32538..688ba937069e 100644
--- a/drivers/coresight/coresight-tpiu.c
+++ b/drivers/coresight/coresight-tpiu.c
@@ -17,7 +17,7 @@ 
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/slab.h>
-#include <linux/clk.h>
+#include <linux/pm_runtime.h>
 #include <linux/coresight.h>
 #include <linux/amba/bus.h>
 
@@ -51,13 +51,11 @@ 
  * @base:	memory mapped base address for this component.
  * @dev:	the device entity associated to this component.
  * @csdev:	component vitals needed by the framework.
- * @clk:	the clock this component is associated to.
  */
 struct tpiu_drvdata {
 	void __iomem		*base;
 	struct device		*dev;
 	struct coresight_device	*csdev;
-	struct clk		*clk;
 };
 
 static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
@@ -72,12 +70,8 @@  static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
 static int tpiu_enable(struct coresight_device *csdev)
 {
 	struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
-	int ret;
-
-	ret = clk_prepare_enable(drvdata->clk);
-	if (ret)
-		return ret;
 
+	pm_runtime_get_sync(csdev->dev.parent);
 	tpiu_enable_hw(drvdata);
 
 	dev_info(drvdata->dev, "TPIU enabled\n");
@@ -101,8 +95,7 @@  static void tpiu_disable(struct coresight_device *csdev)
 	struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
 
 	tpiu_disable_hw(drvdata);
-
-	clk_disable_unprepare(drvdata->clk);
+	pm_runtime_put(csdev->dev.parent);
 
 	dev_info(drvdata->dev, "TPIU disabled\n");
 }
@@ -118,7 +111,6 @@  static const struct coresight_ops tpiu_cs_ops = {
 
 static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
 {
-	int ret;
 	void __iomem *base;
 	struct device *dev = &adev->dev;
 	struct coresight_platform_data *pdata = NULL;
@@ -148,15 +140,10 @@  static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
 
 	drvdata->base = base;
 
-	drvdata->clk = adev->pclk;
-	ret = clk_prepare_enable(drvdata->clk);
-	if (ret)
-		return ret;
-
 	/* Disable tpiu to support older devices */
 	tpiu_disable_hw(drvdata);
 
-	clk_disable_unprepare(drvdata->clk);
+	pm_runtime_put(&adev->dev);
 
 	desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
 	if (!desc)