summaryrefslogtreecommitdiffstats
path: root/drivers/clk/clkdev.c
diff options
context:
space:
mode:
authorMark Brown <broonie@sirena.org.uk>2012-04-05 11:42:09 +0100
committerRussell King <rmk+kernel@arm.linux.org.uk>2012-04-19 19:34:18 +0100
commita8a97db984bdc5e89d42e41891543d2daaf314cb (patch)
treef265e535723e3e2b7011f7e16d782d24e3589e02 /drivers/clk/clkdev.c
parente816b57a337ea3b755de72bec38c10c864f23015 (diff)
downloadop-kernel-dev-a8a97db984bdc5e89d42e41891543d2daaf314cb.zip
op-kernel-dev-a8a97db984bdc5e89d42e41891543d2daaf314cb.tar.gz
ARM: 7376/1: clkdev: Implement managed clk_get()
Allow clk API users to simplify their cleanup paths by providing a managed version of clk_get() and clk_put(). Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/clk/clkdev.c')
-rw-r--r--drivers/clk/clkdev.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 6db161f..a9a1137 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -89,6 +89,51 @@ void clk_put(struct clk *clk)
}
EXPORT_SYMBOL(clk_put);
+static void devm_clk_release(struct device *dev, void *res)
+{
+ clk_put(*(struct clk **)res);
+}
+
+struct clk *devm_clk_get(struct device *dev, const char *id)
+{
+ struct clk **ptr, *clk;
+
+ ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ clk = clk_get(dev, id);
+ if (!IS_ERR(clk)) {
+ *ptr = clk;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return clk;
+}
+EXPORT_SYMBOL(devm_clk_get);
+
+static int devm_clk_match(struct device *dev, void *res, void *data)
+{
+ struct clk **c = res;
+ if (!c || !*c) {
+ WARN_ON(!c || !*c);
+ return 0;
+ }
+ return *c == data;
+}
+
+void devm_clk_put(struct device *dev, struct clk *clk)
+{
+ int ret;
+
+ ret = devres_destroy(dev, devm_clk_release, devm_clk_match, clk);
+
+ WARN_ON(ret);
+}
+EXPORT_SYMBOL(devm_clk_put);
+
void clkdev_add(struct clk_lookup *cl)
{
mutex_lock(&clocks_mutex);
OpenPOWER on IntegriCloud