aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMark Brown <broonie@sirena.org.uk>2012-04-05 06:42:09 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2012-04-19 14:34:18 -0400
commita8a97db984bdc5e89d42e41891543d2daaf314cb (patch)
treef265e535723e3e2b7011f7e16d782d24e3589e02 /drivers
parente816b57a337ea3b755de72bec38c10c864f23015 (diff)
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')
-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 6db161f64ae0..a9a113782821 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -89,6 +89,51 @@ void clk_put(struct clk *clk)
89} 89}
90EXPORT_SYMBOL(clk_put); 90EXPORT_SYMBOL(clk_put);
91 91
92static void devm_clk_release(struct device *dev, void *res)
93{
94 clk_put(*(struct clk **)res);
95}
96
97struct clk *devm_clk_get(struct device *dev, const char *id)
98{
99 struct clk **ptr, *clk;
100
101 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
102 if (!ptr)
103 return ERR_PTR(-ENOMEM);
104
105 clk = clk_get(dev, id);
106 if (!IS_ERR(clk)) {
107 *ptr = clk;
108 devres_add(dev, ptr);
109 } else {
110 devres_free(ptr);
111 }
112
113 return clk;
114}
115EXPORT_SYMBOL(devm_clk_get);
116
117static int devm_clk_match(struct device *dev, void *res, void *data)
118{
119 struct clk **c = res;
120 if (!c || !*c) {
121 WARN_ON(!c || !*c);
122 return 0;
123 }
124 return *c == data;
125}
126
127void devm_clk_put(struct device *dev, struct clk *clk)
128{
129 int ret;
130
131 ret = devres_destroy(dev, devm_clk_release, devm_clk_match, clk);
132
133 WARN_ON(ret);
134}
135EXPORT_SYMBOL(devm_clk_put);
136
92void clkdev_add(struct clk_lookup *cl) 137void clkdev_add(struct clk_lookup *cl)
93{ 138{
94 mutex_lock(&clocks_mutex); 139 mutex_lock(&clocks_mutex);