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

coresight: etm: 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 4339b699
...@@ -141,7 +141,6 @@ ...@@ -141,7 +141,6 @@
* @base: memory mapped base address for this component. * @base: memory mapped base address for this component.
* @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.
* @clk: the clock this component is associated to.
* @spinlock: only one at a time pls. * @spinlock: only one at a time pls.
* @cpu: the cpu this component is affined to. * @cpu: the cpu this component is affined to.
* @port_size: port size as reported by ETMCR bit 4-6 and 21. * @port_size: port size as reported by ETMCR bit 4-6 and 21.
...@@ -193,7 +192,6 @@ struct etm_drvdata { ...@@ -193,7 +192,6 @@ struct etm_drvdata {
void __iomem *base; void __iomem *base;
struct device *dev; struct device *dev;
struct coresight_device *csdev; struct coresight_device *csdev;
struct clk *clk;
spinlock_t spinlock; spinlock_t spinlock;
int cpu; int cpu;
int port_size; int port_size;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/clk.h> #include <linux/pm_runtime.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/coresight.h> #include <linux/coresight.h>
...@@ -325,9 +325,7 @@ static int etm_trace_id(struct coresight_device *csdev) ...@@ -325,9 +325,7 @@ static int etm_trace_id(struct coresight_device *csdev)
if (!drvdata->enable) if (!drvdata->enable)
return drvdata->traceid; return drvdata->traceid;
pm_runtime_get_sync(csdev->dev.parent);
if (clk_prepare_enable(drvdata->clk))
goto out;
spin_lock_irqsave(&drvdata->spinlock, flags); spin_lock_irqsave(&drvdata->spinlock, flags);
...@@ -336,8 +334,8 @@ static int etm_trace_id(struct coresight_device *csdev) ...@@ -336,8 +334,8 @@ static int etm_trace_id(struct coresight_device *csdev)
CS_LOCK(drvdata->base); CS_LOCK(drvdata->base);
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(csdev->dev.parent);
out:
return trace_id; return trace_id;
} }
...@@ -346,10 +344,7 @@ static int etm_enable(struct coresight_device *csdev) ...@@ -346,10 +344,7 @@ static int etm_enable(struct coresight_device *csdev)
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
int ret; int ret;
ret = clk_prepare_enable(drvdata->clk); pm_runtime_get_sync(csdev->dev.parent);
if (ret)
goto err_clk;
spin_lock(&drvdata->spinlock); spin_lock(&drvdata->spinlock);
/* /*
...@@ -373,8 +368,7 @@ static int etm_enable(struct coresight_device *csdev) ...@@ -373,8 +368,7 @@ static int etm_enable(struct coresight_device *csdev)
return 0; return 0;
err: err:
spin_unlock(&drvdata->spinlock); spin_unlock(&drvdata->spinlock);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(csdev->dev.parent);
err_clk:
return ret; return ret;
} }
...@@ -423,8 +417,7 @@ static void etm_disable(struct coresight_device *csdev) ...@@ -423,8 +417,7 @@ static void etm_disable(struct coresight_device *csdev)
spin_unlock(&drvdata->spinlock); spin_unlock(&drvdata->spinlock);
put_online_cpus(); put_online_cpus();
pm_runtime_put(csdev->dev.parent);
clk_disable_unprepare(drvdata->clk);
dev_info(drvdata->dev, "ETM tracing disabled\n"); dev_info(drvdata->dev, "ETM tracing disabled\n");
} }
...@@ -474,14 +467,10 @@ static DEVICE_ATTR_RO(nr_ctxid_cmp); ...@@ -474,14 +467,10 @@ static DEVICE_ATTR_RO(nr_ctxid_cmp);
static ssize_t etmsr_show(struct device *dev, static ssize_t etmsr_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int ret;
unsigned long flags, val; unsigned long flags, val;
struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
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);
CS_UNLOCK(drvdata->base); CS_UNLOCK(drvdata->base);
...@@ -489,7 +478,7 @@ static ssize_t etmsr_show(struct device *dev, ...@@ -489,7 +478,7 @@ static ssize_t etmsr_show(struct device *dev,
CS_LOCK(drvdata->base); CS_LOCK(drvdata->base);
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(drvdata->dev);
return sprintf(buf, "%#lx\n", val); return sprintf(buf, "%#lx\n", val);
} }
...@@ -1317,7 +1306,6 @@ static DEVICE_ATTR_RW(seq_13_event); ...@@ -1317,7 +1306,6 @@ static DEVICE_ATTR_RW(seq_13_event);
static ssize_t seq_curr_state_show(struct device *dev, static ssize_t seq_curr_state_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int ret;
unsigned long val, flags; unsigned long val, flags;
struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
...@@ -1326,9 +1314,7 @@ static ssize_t seq_curr_state_show(struct device *dev, ...@@ -1326,9 +1314,7 @@ static ssize_t seq_curr_state_show(struct device *dev,
goto out; goto out;
} }
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);
...@@ -1337,7 +1323,7 @@ static ssize_t seq_curr_state_show(struct device *dev, ...@@ -1337,7 +1323,7 @@ static ssize_t seq_curr_state_show(struct device *dev,
CS_LOCK(drvdata->base); CS_LOCK(drvdata->base);
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(drvdata->dev);
out: out:
return sprintf(buf, "%#lx\n", val); return sprintf(buf, "%#lx\n", val);
} }
...@@ -1521,10 +1507,7 @@ static ssize_t status_show(struct device *dev, ...@@ -1521,10 +1507,7 @@ static ssize_t status_show(struct device *dev,
unsigned long flags; unsigned long flags;
struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
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);
CS_UNLOCK(drvdata->base); CS_UNLOCK(drvdata->base);
...@@ -1550,7 +1533,7 @@ static ssize_t status_show(struct device *dev, ...@@ -1550,7 +1533,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);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(drvdata->dev);
return ret; return ret;
} }
...@@ -1559,7 +1542,6 @@ static DEVICE_ATTR_RO(status); ...@@ -1559,7 +1542,6 @@ static DEVICE_ATTR_RO(status);
static ssize_t traceid_show(struct device *dev, static ssize_t traceid_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int ret;
unsigned long val, flags; unsigned long val, flags;
struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
...@@ -1568,10 +1550,7 @@ static ssize_t traceid_show(struct device *dev, ...@@ -1568,10 +1550,7 @@ static ssize_t traceid_show(struct device *dev,
goto out; goto out;
} }
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);
CS_UNLOCK(drvdata->base); CS_UNLOCK(drvdata->base);
...@@ -1579,7 +1558,7 @@ static ssize_t traceid_show(struct device *dev, ...@@ -1579,7 +1558,7 @@ static ssize_t traceid_show(struct device *dev,
CS_LOCK(drvdata->base); CS_LOCK(drvdata->base);
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
clk_disable_unprepare(drvdata->clk); pm_runtime_put(drvdata->dev);
out: out:
return sprintf(buf, "%#lx\n", val); return sprintf(buf, "%#lx\n", val);
} }
...@@ -1817,11 +1796,6 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -1817,11 +1796,6 @@ static int etm_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;
drvdata->cpu = pdata ? pdata->cpu : 0; drvdata->cpu = pdata ? pdata->cpu : 0;
get_online_cpus(); get_online_cpus();
...@@ -1845,8 +1819,6 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -1845,8 +1819,6 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
} }
etm_init_default_data(drvdata); etm_init_default_data(drvdata);
clk_disable_unprepare(drvdata->clk);
desc->type = CORESIGHT_DEV_TYPE_SOURCE; desc->type = CORESIGHT_DEV_TYPE_SOURCE;
desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC; desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
desc->ops = &etm_cs_ops; desc->ops = &etm_cs_ops;
...@@ -1859,6 +1831,7 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -1859,6 +1831,7 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
goto err_arch_supported; goto err_arch_supported;
} }
pm_runtime_put(&adev->dev);
dev_info(dev, "%s initialized\n", (char *)id->data); dev_info(dev, "%s initialized\n", (char *)id->data);
if (boot_enable) { if (boot_enable) {
...@@ -1869,7 +1842,6 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -1869,7 +1842,6 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
return 0; return 0;
err_arch_supported: err_arch_supported:
clk_disable_unprepare(drvdata->clk);
if (--etm_count == 0) if (--etm_count == 0)
unregister_hotcpu_notifier(&etm_cpu_notifier); unregister_hotcpu_notifier(&etm_cpu_notifier);
return ret; return ret;
......
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