Merge branch 'for-next-merge' of git://git.kernel.org/pub/scm/linux/kernel/git/nab...
[cascardo/linux.git] / drivers / clk / clk.c
index 58ef3da..fb74dc1 100644 (file)
@@ -1841,6 +1841,10 @@ int clk_set_phase(struct clk *clk, int degrees)
 
        clk_prepare_lock();
 
+       /* bail early if nothing to do */
+       if (degrees == clk->core->phase)
+               goto out;
+
        trace_clk_set_phase(clk->core, degrees);
 
        if (clk->core->ops->set_phase)
@@ -1851,6 +1855,7 @@ int clk_set_phase(struct clk *clk, int degrees)
        if (!ret)
                clk->core->phase = degrees;
 
+out:
        clk_prepare_unlock();
 
        return ret;
@@ -2157,7 +2162,7 @@ unlock:
  *
  * Dynamically removes a clk and all its child nodes from the
  * debugfs clk directory if clk->dentry points to debugfs created by
- * clk_debug_register in __clk_init.
+ * clk_debug_register in __clk_core_init.
  */
 static void clk_debug_unregister(struct clk_core *core)
 {
@@ -2241,38 +2246,6 @@ static inline void clk_debug_unregister(struct clk_core *core)
 }
 #endif
 
-/**
- * __clk_is_ancestor - check if a clk_core is a possible ancestor of another
- * @core: clock core
- * @ancestor: ancestor clock core
- *
- * Returns true if there is a possibility that @ancestor can be an ancestor
- * of @core, false otherwise.
- *
- * This function can be used against @core or @ancestor that has not been
- * registered yet.
- */
-static bool __clk_is_ancestor(struct clk_core *core, struct clk_core *ancestor)
-{
-       struct clk_core *parent;
-       int i;
-
-       for (i = 0; i < core->num_parents; i++) {
-               parent = clk_core_get_parent_by_index(core, i);
-               /*
-                * If ancestor has not been added to clk_{root,orphan}_list
-                * yet, clk_core_lookup() cannot find it.  If parent is NULL,
-                * compare the name strings, too.
-                */
-               if ((parent && (parent == ancestor ||
-                               __clk_is_ancestor(parent, ancestor))) ||
-                   (!parent && !strcmp(core->parent_names[i], ancestor->name)))
-                       return true;
-       }
-
-       return false;
-}
-
 /**
  * __clk_core_init - initialize the data structures in a struct clk_core
  * @core:      clk_core being initialized
@@ -2338,19 +2311,11 @@ static int __clk_core_init(struct clk_core *core)
                                "%s: invalid NULL in %s's .parent_names\n",
                                __func__, core->name);
 
-       /* If core is an ancestor of itself, it would make a loop. */
-       if (__clk_is_ancestor(core, core)) {
-               pr_err("%s: %s would create circular parent\n", __func__,
-                      core->name);
-               ret = -EINVAL;
-               goto out;
-       }
-
        core->parent = __clk_init_parent(core);
 
        /*
-        * Populate core->parent if parent has already been __clk_init'd.  If
-        * parent has not yet been __clk_init'd then place clk in the orphan
+        * Populate core->parent if parent has already been clk_core_init'd. If
+        * parent has not yet been clk_core_init'd then place clk in the orphan
         * list.  If clk doesn't have any parents then place it in the root
         * clk list.
         *
@@ -3021,9 +2986,21 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_from_provider);
 
-int of_clk_get_parent_count(struct device_node *np)
+/**
+ * of_clk_get_parent_count() - Count the number of clocks a device node has
+ * @np: device node to count
+ *
+ * Returns: The number of clocks that are possible parents of this node
+ */
+unsigned int of_clk_get_parent_count(struct device_node *np)
 {
-       return of_count_phandle_with_args(np, "clocks", "#clock-cells");
+       int count;
+
+       count = of_count_phandle_with_args(np, "clocks", "#clock-cells");
+       if (count < 0)
+               return 0;
+
+       return count;
 }
 EXPORT_SYMBOL_GPL(of_clk_get_parent_count);
 
@@ -3173,6 +3150,9 @@ void __init of_clk_init(const struct of_device_id *matches)
        for_each_matching_node_and_match(np, matches, &match) {
                struct clock_provider *parent;
 
+               if (!of_device_is_available(np))
+                       continue;
+
                parent = kzalloc(sizeof(*parent), GFP_KERNEL);
                if (!parent) {
                        list_for_each_entry_safe(clk_provider, next,