summaryrefslogtreecommitdiff
path: root/drivers/clk/clk.c
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2017-11-14 21:07:39 +0300
committerStephen Boyd <sboyd@codeaurora.org>2017-11-14 21:07:39 +0300
commit2dd850ef6e1e525a06b4ba111968199a32844177 (patch)
treeee74051c65cf3dd2ed15446ffd9b4ba74216602f /drivers/clk/clk.c
parented9c62f75aef10297fb6da4e24292fb354cb8307 (diff)
parentb87206f8addc52b07e0aba30f8c8ee1a5093cfa9 (diff)
downloadlinux-2dd850ef6e1e525a06b4ba111968199a32844177.tar.xz
Merge branch 'clk-devm-provider' into clk-next
* clk-devm-provider: clk: qcom: common: Migrate to devm_* APIs for resets and clk providers clk: Add devm_of_clk_add_hw_provider()/del_provider() APIs
Diffstat (limited to 'drivers/clk/clk.c')
-rw-r--r--drivers/clk/clk.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index b6495a12f65f..647d056df88c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3275,6 +3275,37 @@ int of_clk_add_hw_provider(struct device_node *np,
}
EXPORT_SYMBOL_GPL(of_clk_add_hw_provider);
+static void devm_of_clk_release_provider(struct device *dev, void *res)
+{
+ of_clk_del_provider(*(struct device_node **)res);
+}
+
+int devm_of_clk_add_hw_provider(struct device *dev,
+ struct clk_hw *(*get)(struct of_phandle_args *clkspec,
+ void *data),
+ void *data)
+{
+ struct device_node **ptr, *np;
+ int ret;
+
+ ptr = devres_alloc(devm_of_clk_release_provider, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ np = dev->of_node;
+ ret = of_clk_add_hw_provider(np, get, data);
+ if (!ret) {
+ *ptr = np;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_of_clk_add_hw_provider);
+
/**
* of_clk_del_provider() - Remove a previously registered clock provider
* @np: Device node pointer associated with clock provider
@@ -3296,6 +3327,27 @@ void of_clk_del_provider(struct device_node *np)
}
EXPORT_SYMBOL_GPL(of_clk_del_provider);
+static int devm_clk_provider_match(struct device *dev, void *res, void *data)
+{
+ struct device_node **np = res;
+
+ if (WARN_ON(!np || !*np))
+ return 0;
+
+ return *np == data;
+}
+
+void devm_of_clk_del_provider(struct device *dev)
+{
+ int ret;
+
+ ret = devres_release(dev, devm_of_clk_release_provider,
+ devm_clk_provider_match, dev->of_node);
+
+ WARN_ON(ret);
+}
+EXPORT_SYMBOL(devm_of_clk_del_provider);
+
static struct clk_hw *
__of_clk_get_hw_from_provider(struct of_clk_provider *provider,
struct of_phandle_args *clkspec)