2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
8 #include <linux/device.h>
9 #include <linux/export.h>
10 #include <linux/gfp.h>
12 static void devm_clk_release(struct device *dev, void *res)
14 clk_put(*(struct clk **)res);
17 struct clk *devm_clk_get(struct device *dev, const char *id)
19 struct clk **ptr, *clk;
21 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
23 return ERR_PTR(-ENOMEM);
25 clk = clk_get(dev, id);
35 EXPORT_SYMBOL(devm_clk_get);
37 struct clk_bulk_devres {
38 struct clk_bulk_data *clks;
42 static void devm_clk_bulk_release(struct device *dev, void *res)
44 struct clk_bulk_devres *devres = res;
46 clk_bulk_put(devres->num_clks, devres->clks);
49 int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
50 struct clk_bulk_data *clks)
52 struct clk_bulk_devres *devres;
55 devres = devres_alloc(devm_clk_bulk_release,
56 sizeof(*devres), GFP_KERNEL);
60 ret = clk_bulk_get(dev, num_clks, clks);
63 devres->num_clks = num_clks;
64 devres_add(dev, devres);
71 EXPORT_SYMBOL_GPL(devm_clk_bulk_get);
73 static int devm_clk_match(struct device *dev, void *res, void *data)
83 void devm_clk_put(struct device *dev, struct clk *clk)
87 ret = devres_release(dev, devm_clk_release, devm_clk_match, clk);
91 EXPORT_SYMBOL(devm_clk_put);
93 struct clk *devm_get_clk_from_child(struct device *dev,
94 struct device_node *np, const char *con_id)
96 struct clk **ptr, *clk;
98 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
100 return ERR_PTR(-ENOMEM);
102 clk = of_clk_get_by_name(np, con_id);
105 devres_add(dev, ptr);
112 EXPORT_SYMBOL(devm_get_clk_from_child);