Commit 142dfeb2 authored by Alexander Shishkin's avatar Alexander Shishkin

intel_th: Add runtime power management handling

Currently, an Intel TH (pci) device will be always active, because the
devices on the 'intel_th' bus don't implement runtime pm to track their
usage.

To address this, this patch adds runtime pm support to the 'intel_th'
bus and some additional bits for the hub. The 'output' type device is
in use while a capture is active; the 'source' type device (STH) relies
on its child stm class device for runtime pm tracking.
Signed-off-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
parent 8e0469a4
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pm_runtime.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include "intel_th.h" #include "intel_th.h"
...@@ -67,23 +68,33 @@ static int intel_th_probe(struct device *dev) ...@@ -67,23 +68,33 @@ static int intel_th_probe(struct device *dev)
hubdrv = to_intel_th_driver(hub->dev.driver); hubdrv = to_intel_th_driver(hub->dev.driver);
pm_runtime_set_active(dev);
pm_runtime_no_callbacks(dev);
pm_runtime_enable(dev);
ret = thdrv->probe(to_intel_th_device(dev)); ret = thdrv->probe(to_intel_th_device(dev));
if (ret) if (ret)
return ret; goto out_pm;
if (thdrv->attr_group) { if (thdrv->attr_group) {
ret = sysfs_create_group(&thdev->dev.kobj, thdrv->attr_group); ret = sysfs_create_group(&thdev->dev.kobj, thdrv->attr_group);
if (ret) { if (ret)
thdrv->remove(thdev); goto out;
return ret;
}
} }
if (thdev->type == INTEL_TH_OUTPUT && if (thdev->type == INTEL_TH_OUTPUT &&
!intel_th_output_assigned(thdev)) !intel_th_output_assigned(thdev))
/* does not talk to hardware */
ret = hubdrv->assign(hub, thdev); ret = hubdrv->assign(hub, thdev);
out:
if (ret)
thdrv->remove(thdev);
out_pm:
if (ret)
pm_runtime_disable(dev);
return ret; return ret;
} }
...@@ -103,6 +114,8 @@ static int intel_th_remove(struct device *dev) ...@@ -103,6 +114,8 @@ static int intel_th_remove(struct device *dev)
if (thdrv->attr_group) if (thdrv->attr_group)
sysfs_remove_group(&thdev->dev.kobj, thdrv->attr_group); sysfs_remove_group(&thdev->dev.kobj, thdrv->attr_group);
pm_runtime_get_sync(dev);
thdrv->remove(thdev); thdrv->remove(thdev);
if (intel_th_output_assigned(thdev)) { if (intel_th_output_assigned(thdev)) {
...@@ -110,9 +123,14 @@ static int intel_th_remove(struct device *dev) ...@@ -110,9 +123,14 @@ static int intel_th_remove(struct device *dev)
to_intel_th_driver(dev->parent->driver); to_intel_th_driver(dev->parent->driver);
if (hub->dev.driver) if (hub->dev.driver)
/* does not talk to hardware */
hubdrv->unassign(hub, thdev); hubdrv->unassign(hub, thdev);
} }
pm_runtime_disable(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
return 0; return 0;
} }
...@@ -185,6 +203,7 @@ static int intel_th_output_activate(struct intel_th_device *thdev) ...@@ -185,6 +203,7 @@ static int intel_th_output_activate(struct intel_th_device *thdev)
{ {
struct intel_th_driver *thdrv = struct intel_th_driver *thdrv =
to_intel_th_driver_or_null(thdev->dev.driver); to_intel_th_driver_or_null(thdev->dev.driver);
int ret = 0;
if (!thdrv) if (!thdrv)
return -ENODEV; return -ENODEV;
...@@ -192,12 +211,17 @@ static int intel_th_output_activate(struct intel_th_device *thdev) ...@@ -192,12 +211,17 @@ static int intel_th_output_activate(struct intel_th_device *thdev)
if (!try_module_get(thdrv->driver.owner)) if (!try_module_get(thdrv->driver.owner))
return -ENODEV; return -ENODEV;
if (thdrv->activate) pm_runtime_get_sync(&thdev->dev);
return thdrv->activate(thdev);
if (thdrv->activate)
ret = thdrv->activate(thdev);
else
intel_th_trace_enable(thdev); intel_th_trace_enable(thdev);
return 0; if (ret)
pm_runtime_put(&thdev->dev);
return ret;
} }
static void intel_th_output_deactivate(struct intel_th_device *thdev) static void intel_th_output_deactivate(struct intel_th_device *thdev)
...@@ -213,6 +237,7 @@ static void intel_th_output_deactivate(struct intel_th_device *thdev) ...@@ -213,6 +237,7 @@ static void intel_th_output_deactivate(struct intel_th_device *thdev)
else else
intel_th_trace_disable(thdev); intel_th_trace_disable(thdev);
pm_runtime_put(&thdev->dev);
module_put(thdrv->driver.owner); module_put(thdrv->driver.owner);
} }
...@@ -628,6 +653,10 @@ intel_th_alloc(struct device *dev, struct resource *devres, ...@@ -628,6 +653,10 @@ intel_th_alloc(struct device *dev, struct resource *devres,
dev_set_drvdata(dev, th); dev_set_drvdata(dev, th);
pm_runtime_no_callbacks(dev);
pm_runtime_put(dev);
pm_runtime_allow(dev);
err = intel_th_populate(th, devres, ndevres, irq); err = intel_th_populate(th, devres, ndevres, irq);
if (err) if (err)
goto err_chrdev; goto err_chrdev;
...@@ -635,6 +664,8 @@ intel_th_alloc(struct device *dev, struct resource *devres, ...@@ -635,6 +664,8 @@ intel_th_alloc(struct device *dev, struct resource *devres,
return th; return th;
err_chrdev: err_chrdev:
pm_runtime_forbid(dev);
__unregister_chrdev(th->major, 0, TH_POSSIBLE_OUTPUTS, __unregister_chrdev(th->major, 0, TH_POSSIBLE_OUTPUTS,
"intel_th/output"); "intel_th/output");
...@@ -658,6 +689,9 @@ void intel_th_free(struct intel_th *th) ...@@ -658,6 +689,9 @@ void intel_th_free(struct intel_th *th)
intel_th_device_remove(th->hub); intel_th_device_remove(th->hub);
pm_runtime_get_sync(th->dev);
pm_runtime_forbid(th->dev);
__unregister_chrdev(th->major, 0, TH_POSSIBLE_OUTPUTS, __unregister_chrdev(th->major, 0, TH_POSSIBLE_OUTPUTS,
"intel_th/output"); "intel_th/output");
...@@ -682,6 +716,7 @@ int intel_th_trace_enable(struct intel_th_device *thdev) ...@@ -682,6 +716,7 @@ int intel_th_trace_enable(struct intel_th_device *thdev)
if (WARN_ON_ONCE(thdev->type != INTEL_TH_OUTPUT)) if (WARN_ON_ONCE(thdev->type != INTEL_TH_OUTPUT))
return -EINVAL; return -EINVAL;
pm_runtime_get_sync(&thdev->dev);
hubdrv->enable(hub, &thdev->output); hubdrv->enable(hub, &thdev->output);
return 0; return 0;
...@@ -702,6 +737,7 @@ int intel_th_trace_disable(struct intel_th_device *thdev) ...@@ -702,6 +737,7 @@ int intel_th_trace_disable(struct intel_th_device *thdev)
return -EINVAL; return -EINVAL;
hubdrv->disable(hub, &thdev->output); hubdrv->disable(hub, &thdev->output);
pm_runtime_put(&thdev->dev);
return 0; return 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/pm_runtime.h>
#include "intel_th.h" #include "intel_th.h"
#include "gth.h" #include "gth.h"
...@@ -190,6 +191,11 @@ static ssize_t master_attr_store(struct device *dev, ...@@ -190,6 +191,11 @@ static ssize_t master_attr_store(struct device *dev,
if (old_port >= 0) { if (old_port >= 0) {
gth->master[ma->master] = -1; gth->master[ma->master] = -1;
clear_bit(ma->master, gth->output[old_port].master); clear_bit(ma->master, gth->output[old_port].master);
/*
* if the port is active, program this setting,
* implies that runtime PM is on
*/
if (gth->output[old_port].output->active) if (gth->output[old_port].output->active)
gth_master_set(gth, ma->master, -1); gth_master_set(gth, ma->master, -1);
} }
...@@ -204,7 +210,7 @@ static ssize_t master_attr_store(struct device *dev, ...@@ -204,7 +210,7 @@ static ssize_t master_attr_store(struct device *dev,
set_bit(ma->master, gth->output[port].master); set_bit(ma->master, gth->output[port].master);
/* if the port is active, program this setting */ /* if the port is active, program this setting, see above */
if (gth->output[port].output->active) if (gth->output[port].output->active)
gth_master_set(gth, ma->master, port); gth_master_set(gth, ma->master, port);
} }
...@@ -326,11 +332,15 @@ static ssize_t output_attr_show(struct device *dev, ...@@ -326,11 +332,15 @@ static ssize_t output_attr_show(struct device *dev,
struct gth_device *gth = oa->gth; struct gth_device *gth = oa->gth;
size_t count; size_t count;
pm_runtime_get_sync(dev);
spin_lock(&gth->gth_lock); spin_lock(&gth->gth_lock);
count = snprintf(buf, PAGE_SIZE, "%x\n", count = snprintf(buf, PAGE_SIZE, "%x\n",
gth_output_parm_get(gth, oa->port, oa->parm)); gth_output_parm_get(gth, oa->port, oa->parm));
spin_unlock(&gth->gth_lock); spin_unlock(&gth->gth_lock);
pm_runtime_put(dev);
return count; return count;
} }
...@@ -346,10 +356,14 @@ static ssize_t output_attr_store(struct device *dev, ...@@ -346,10 +356,14 @@ static ssize_t output_attr_store(struct device *dev,
if (kstrtouint(buf, 16, &config) < 0) if (kstrtouint(buf, 16, &config) < 0)
return -EINVAL; return -EINVAL;
pm_runtime_get_sync(dev);
spin_lock(&gth->gth_lock); spin_lock(&gth->gth_lock);
gth_output_parm_set(gth, oa->port, oa->parm, config); gth_output_parm_set(gth, oa->port, oa->parm, config);
spin_unlock(&gth->gth_lock); spin_unlock(&gth->gth_lock);
pm_runtime_put(dev);
return count; return count;
} }
......
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