KVM: arm/arm64: GICv4: Handle INVALL applied to a vPE
[linux/fpc-iii.git] / drivers / clk / clk-devres.c
blobd854e26a8ddbca3dfb96aad123e974f2175cc455
1 /*
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.
5 */
7 #include <linux/clk.h>
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);
22 if (!ptr)
23 return ERR_PTR(-ENOMEM);
25 clk = clk_get(dev, id);
26 if (!IS_ERR(clk)) {
27 *ptr = clk;
28 devres_add(dev, ptr);
29 } else {
30 devres_free(ptr);
33 return clk;
35 EXPORT_SYMBOL(devm_clk_get);
37 struct clk_bulk_devres {
38 struct clk_bulk_data *clks;
39 int num_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;
53 int ret;
55 devres = devres_alloc(devm_clk_bulk_release,
56 sizeof(*devres), GFP_KERNEL);
57 if (!devres)
58 return -ENOMEM;
60 ret = clk_bulk_get(dev, num_clks, clks);
61 if (!ret) {
62 devres->clks = clks;
63 devres->num_clks = num_clks;
64 devres_add(dev, devres);
65 } else {
66 devres_free(devres);
69 return ret;
71 EXPORT_SYMBOL_GPL(devm_clk_bulk_get);
73 static int devm_clk_match(struct device *dev, void *res, void *data)
75 struct clk **c = res;
76 if (!c || !*c) {
77 WARN_ON(!c || !*c);
78 return 0;
80 return *c == data;
83 void devm_clk_put(struct device *dev, struct clk *clk)
85 int ret;
87 ret = devres_release(dev, devm_clk_release, devm_clk_match, clk);
89 WARN_ON(ret);
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);
99 if (!ptr)
100 return ERR_PTR(-ENOMEM);
102 clk = of_clk_get_by_name(np, con_id);
103 if (!IS_ERR(clk)) {
104 *ptr = clk;
105 devres_add(dev, ptr);
106 } else {
107 devres_free(ptr);
110 return clk;
112 EXPORT_SYMBOL(devm_get_clk_from_child);