Commit 32398ef6 authored by Linus Walleij's avatar Linus Walleij Committed by Greg Kroah-Hartman

coresight: tmc: let runtime PM handle core clock

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 unprepare
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.
Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e2d08f96
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/clk.h> #include <linux/pm_runtime.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/coresight.h> #include <linux/coresight.h>
#include <linux/amba/bus.h> #include <linux/amba/bus.h>
...@@ -104,7 +104,6 @@ enum tmc_mem_intf_width { ...@@ -104,7 +104,6 @@ enum tmc_mem_intf_width {
* @dev: the device entity associated to this component. * @dev: the device entity associated to this component.
* @csdev: component vitals needed by the framework. * @csdev: component vitals needed by the framework.
* @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @miscdev: specifics to handle "/dev/xyz.tmc" entry.
* @clk: the clock this component is associated to.
* @spinlock: only one at a time pls. * @spinlock: only one at a time pls.
* @read_count: manages preparation of buffer for reading. * @read_count: manages preparation of buffer for reading.
* @buf: area of memory where trace data get sent. * @buf: area of memory where trace data get sent.
...@@ -120,7 +119,6 @@ struct tmc_drvdata { ...@@ -120,7 +119,6 @@ struct tmc_drvdata {
struct device *dev; struct device *dev;
struct coresight_device *csdev; struct coresight_device *csdev;
struct miscdevice miscdev; struct miscdevice miscdev;
struct clk *clk;
spinlock_t spinlock; spinlock_t spinlock;
int read_count; int read_count;
bool reading; bool reading;
...@@ -242,17 +240,14 @@ static void tmc_etf_enable_hw(struct tmc_drvdata *drvdata) ...@@ -242,17 +240,14 @@ static void tmc_etf_enable_hw(struct tmc_drvdata *drvdata)
static int tmc_enable(struct tmc_drvdata *drvdata, enum tmc_mode mode) static int tmc_enable(struct tmc_drvdata *drvdata, enum tmc_mode mode)
{ {
int ret;
unsigned long flags; unsigned long flags;
ret = clk_prepare_enable(drvdata->clk); pm_runtime_get_sync(drvdata->dev);
if (ret)
return ret;
spin_lock_irqsave(&drvdata->spinlock, flags); spin_lock_irqsave(&drvdata->spinlock, flags);
if (drvdata->reading) { if (drvdata->reading) {
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(drvdata->dev);
return -EBUSY; return -EBUSY;
} }
...@@ -386,7 +381,7 @@ static void tmc_disable(struct tmc_drvdata *drvdata, enum tmc_mode mode) ...@@ -386,7 +381,7 @@ static void tmc_disable(struct tmc_drvdata *drvdata, enum tmc_mode mode)
drvdata->enable = false; drvdata->enable = false;
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(drvdata->dev);
dev_info(drvdata->dev, "TMC disabled\n"); dev_info(drvdata->dev, "TMC disabled\n");
} }
...@@ -568,17 +563,13 @@ static const struct file_operations tmc_fops = { ...@@ -568,17 +563,13 @@ static const struct file_operations tmc_fops = {
static ssize_t status_show(struct device *dev, static ssize_t status_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int ret;
unsigned long flags; unsigned long flags;
u32 tmc_rsz, tmc_sts, tmc_rrp, tmc_rwp, tmc_trg; u32 tmc_rsz, tmc_sts, tmc_rrp, tmc_rwp, tmc_trg;
u32 tmc_ctl, tmc_ffsr, tmc_ffcr, tmc_mode, tmc_pscr; u32 tmc_ctl, tmc_ffsr, tmc_ffcr, tmc_mode, tmc_pscr;
u32 devid; u32 devid;
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
ret = clk_prepare_enable(drvdata->clk); pm_runtime_get_sync(drvdata->dev);
if (ret)
goto out;
spin_lock_irqsave(&drvdata->spinlock, flags); spin_lock_irqsave(&drvdata->spinlock, flags);
CS_UNLOCK(drvdata->base); CS_UNLOCK(drvdata->base);
...@@ -596,8 +587,7 @@ static ssize_t status_show(struct device *dev, ...@@ -596,8 +587,7 @@ static ssize_t status_show(struct device *dev,
CS_LOCK(drvdata->base); CS_LOCK(drvdata->base);
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
pm_runtime_put(drvdata->dev);
clk_disable_unprepare(drvdata->clk);
return sprintf(buf, return sprintf(buf,
"Depth:\t\t0x%x\n" "Depth:\t\t0x%x\n"
...@@ -613,7 +603,7 @@ static ssize_t status_show(struct device *dev, ...@@ -613,7 +603,7 @@ static ssize_t status_show(struct device *dev,
"DEVID:\t\t0x%x\n", "DEVID:\t\t0x%x\n",
tmc_rsz, tmc_sts, tmc_rrp, tmc_rwp, tmc_trg, tmc_rsz, tmc_sts, tmc_rrp, tmc_rwp, tmc_trg,
tmc_ctl, tmc_ffsr, tmc_ffcr, tmc_mode, tmc_pscr, devid); tmc_ctl, tmc_ffsr, tmc_ffcr, tmc_mode, tmc_pscr, devid);
out:
return -EINVAL; return -EINVAL;
} }
static DEVICE_ATTR_RO(status); static DEVICE_ATTR_RO(status);
...@@ -700,11 +690,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -700,11 +690,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
spin_lock_init(&drvdata->spinlock); spin_lock_init(&drvdata->spinlock);
drvdata->clk = adev->pclk;
ret = clk_prepare_enable(drvdata->clk);
if (ret)
return ret;
devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID); devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
drvdata->config_type = BMVAL(devid, 6, 7); drvdata->config_type = BMVAL(devid, 6, 7);
...@@ -719,7 +704,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -719,7 +704,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
drvdata->size = readl_relaxed(drvdata->base + TMC_RSZ) * 4; drvdata->size = readl_relaxed(drvdata->base + TMC_RSZ) * 4;
} }
clk_disable_unprepare(drvdata->clk); pm_runtime_put(&adev->dev);
if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
drvdata->vaddr = dma_alloc_coherent(dev, drvdata->size, drvdata->vaddr = dma_alloc_coherent(dev, drvdata->size,
......
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