Lines Matching +full:parent +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
4 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
6 * Standard functionality for the common clock API. See Documentation/driver-api/clk.rst
9 #include <linux/clk.h>
10 #include <linux/clk-provider.h>
11 #include <linux/clk/clk-conf.h>
25 #include "clk.h"
68 struct clk_core *parent; member
100 #include <trace/events/clk.h>
102 struct clk { struct
116 if (!core->rpm_enabled) in clk_pm_runtime_get()
119 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
124 if (!core->rpm_enabled) in clk_pm_runtime_put()
127 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
131 * clk_pm_runtime_get_all() - Runtime "get" all clk provider devices argument
133 * Call clk_pm_runtime_get() on all runtime PM enabled clks in the clk tree so
165 pr_err("clk: Failed to runtime PM get '%s' for clk '%s'\n", in clk_pm_runtime_get_all()
166 dev_name(failed->dev), failed->name); in clk_pm_runtime_get_all()
186 * clk_pm_runtime_put_all() - Runtime "put" all clk provider devices
202 struct device *dev = core->dev; in clk_pm_runtime_init()
205 core->rpm_enabled = true; in clk_pm_runtime_init()
208 hlist_add_head(&core->rpm_node, &clk_rpm_list); in clk_pm_runtime_init()
234 if (--prepare_refcnt) in clk_prepare_unlock()
274 if (--enable_refcnt) { in clk_enable_unlock()
284 return core->protect_count; in clk_core_rate_is_protected()
295 if (!core->ops->is_prepared) in clk_core_is_prepared()
296 return core->prepare_count; in clk_core_is_prepared()
299 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
314 if (!core->ops->is_enabled) in clk_core_is_enabled()
315 return core->enable_count; in clk_core_is_enabled()
327 if (core->rpm_enabled) { in clk_core_is_enabled()
328 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
329 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
337 * context. If the parent isn't enabled already, we can't do in clk_core_is_enabled()
340 if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) in clk_core_is_enabled()
341 if (!clk_core_is_enabled(core->parent)) { in clk_core_is_enabled()
346 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
348 if (core->rpm_enabled) in clk_core_is_enabled()
349 pm_runtime_put(core->dev); in clk_core_is_enabled()
356 const char *__clk_get_name(const struct clk *clk) in __clk_get_name() argument
358 return !clk ? NULL : clk->core->name; in __clk_get_name()
364 return hw->core->name; in clk_hw_get_name()
368 struct clk_hw *__clk_get_hw(struct clk *clk) in __clk_get_hw() argument
370 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
376 return hw->core->num_parents; in clk_hw_get_num_parents()
382 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
392 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
395 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
412 /* search the 'proper' clk tree first */ in clk_core_lookup()
439 return -ENOENT; in of_parse_clkspec()
444 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
449 * clk_core_get - Find the clk_core parent of a clk
450 * @core: clk to find parent of
451 * @p_index: parent index to search for
453 * This is the preferred method for clk providers to find the parent of a
454 * clk when that parent is external to the clk controller. The parent_names
456 * node's 'clock-names' property or as the 'con_id' matching the device's
457 * dev_name() in a clk_lookup. This allows clk providers to use their own
458 * namespace instead of looking for a globally unique parent string.
461 * clock-controller@c001 that has a clk_init_data::parent_data array
463 * clock-controller@f00abcd without needing to get the globally unique name of
464 * the xtal clk.
466 * parent: clock-controller@f00abcd {
468 * #clock-cells = <0>;
471 * clock-controller@c001 {
473 * clocks = <&parent>;
474 * clock-names = "xtal";
475 * #clock-cells = <1>;
478 * Returns: -ENOENT when the provider can't be found or the clk doesn't
480 * in a clkdev lookup. NULL when the provider knows about the clk but it
482 * A valid clk_core pointer when the clk can be found in the provider.
486 const char *name = core->parents[p_index].fw_name; in clk_core_get()
487 int index = core->parents[p_index].index; in clk_core_get()
488 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
489 struct device *dev = core->dev; in clk_core_get()
491 struct device_node *np = core->of_node; in clk_core_get()
512 return hw->core; in clk_core_get()
517 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
518 struct clk_core *parent; in clk_core_fill_parent_index() local
520 if (entry->hw) { in clk_core_fill_parent_index()
521 parent = entry->hw->core; in clk_core_fill_parent_index()
523 parent = clk_core_get(core, index); in clk_core_fill_parent_index()
524 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
525 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
531 * when the parent is registered. in clk_core_fill_parent_index()
533 if (!parent) in clk_core_fill_parent_index()
534 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
537 if (!IS_ERR(parent)) in clk_core_fill_parent_index()
538 entry->core = parent; in clk_core_fill_parent_index()
544 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
547 if (!core->parents[index].core) in clk_core_get_parent_by_index()
550 return core->parents[index].core; in clk_core_get_parent_by_index()
556 struct clk_core *parent; in clk_hw_get_parent_by_index() local
558 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
560 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
564 unsigned int __clk_get_enable_count(struct clk *clk) in __clk_get_enable_count() argument
566 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
574 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
575 return core->rate; in clk_core_get_rate_nolock()
578 * Clk must have a parent because num_parents > 0 but the parent isn't in clk_core_get_rate_nolock()
579 * known yet. Best to return 0 as the rate of this clk until we can in clk_core_get_rate_nolock()
580 * properly recalc the rate based on the parent's rate. in clk_core_get_rate_nolock()
587 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
596 return core->accuracy; in clk_core_get_accuracy_no_lock()
601 return hw->core->flags; in clk_hw_get_flags()
607 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
613 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
619 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
623 bool __clk_is_enabled(struct clk *clk) in __clk_is_enabled() argument
625 if (!clk) in __clk_is_enabled()
628 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
636 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
648 static bool clk_core_has_parent(struct clk_core *core, const struct clk_core *parent) in clk_core_has_parent() argument
653 /* Optimize for the case where the parent is already the parent. */ in clk_core_has_parent()
654 if (core->parent == parent) in clk_core_has_parent()
657 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
662 if (tmp == parent) in clk_core_has_parent()
672 struct clk_core *parent, in clk_core_forward_rate_req() argument
676 if (WARN_ON(!clk_core_has_parent(core, parent))) in clk_core_forward_rate_req()
679 clk_core_init_rate_req(parent, req, parent_rate); in clk_core_forward_rate_req()
681 if (req->min_rate < old_req->min_rate) in clk_core_forward_rate_req()
682 req->min_rate = old_req->min_rate; in clk_core_forward_rate_req()
684 if (req->max_rate > old_req->max_rate) in clk_core_forward_rate_req()
685 req->max_rate = old_req->max_rate; in clk_core_forward_rate_req()
692 struct clk_core *core = hw->core; in clk_core_determine_rate_no_reparent()
693 struct clk_core *parent = core->parent; in clk_core_determine_rate_no_reparent() local
697 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_determine_rate_no_reparent()
700 if (!parent) { in clk_core_determine_rate_no_reparent()
701 req->rate = 0; in clk_core_determine_rate_no_reparent()
705 clk_core_forward_rate_req(core, req, parent, &parent_req, in clk_core_determine_rate_no_reparent()
706 req->rate); in clk_core_determine_rate_no_reparent()
710 ret = clk_core_round_rate_nolock(parent, &parent_req); in clk_core_determine_rate_no_reparent()
717 } else if (parent) { in clk_core_determine_rate_no_reparent()
718 best = clk_core_get_rate_nolock(parent); in clk_core_determine_rate_no_reparent()
723 req->best_parent_rate = best; in clk_core_determine_rate_no_reparent()
724 req->rate = best; in clk_core_determine_rate_no_reparent()
733 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
737 /* if NO_REPARENT flag set, pass through to current parent */ in clk_mux_determine_rate_flags()
738 if (core->flags & CLK_SET_RATE_NO_REPARENT) in clk_mux_determine_rate_flags()
741 /* find the parent that can provide the fastest rate <= rate */ in clk_mux_determine_rate_flags()
742 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
746 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
747 if (!parent) in clk_mux_determine_rate_flags()
750 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
753 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
757 ret = clk_core_round_rate_nolock(parent, &parent_req); in clk_mux_determine_rate_flags()
765 parent_rate = clk_core_get_rate_nolock(parent); in clk_mux_determine_rate_flags()
768 if (mux_is_better_rate(req->rate, parent_rate, in clk_mux_determine_rate_flags()
770 best_parent = parent; in clk_mux_determine_rate_flags()
776 return -EINVAL; in clk_mux_determine_rate_flags()
778 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
779 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
780 req->rate = best; in clk_mux_determine_rate_flags()
786 struct clk *__clk_lookup(const char *name) in __clk_lookup()
790 return !core ? NULL : core->hw->clk; in __clk_lookup()
797 struct clk *clk_user; in clk_core_get_boundaries()
801 *min_rate = core->min_rate; in clk_core_get_boundaries()
802 *max_rate = core->max_rate; in clk_core_get_boundaries()
804 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
805 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
807 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
808 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
812 * clk_hw_get_rate_range() - returns the clock rate range for a hw clk
813 * @hw: the hw clk we want to get the range from
823 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
831 struct clk *user; in clk_core_check_boundaries()
835 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
838 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
839 if (min_rate > user->max_rate || max_rate < user->min_rate) in clk_core_check_boundaries()
848 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
849 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
854 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
855 * @hw: mux type clk to determine rate on
856 * @req: rate request, also used to return preferred parent and frequencies
858 * Helper for finding best parent to provide a given frequency. This can be used
862 * Returns: 0 on success, -EERROR value on error
879 …* clk_hw_determine_rate_no_reparent - clk_ops::determine_rate implementation for a clk that doesn'…
880 * @hw: mux type clk to determine rate on
883 * Helper for finding best parent rate to provide a given frequency.
888 * Returns: 0 on success, -EERROR value on error
897 /*** clk api ***/
906 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
907 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
910 if (--core->protect_count > 0) in clk_core_rate_unprotect()
913 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
923 return -EINVAL; in clk_core_rate_nuke_protect()
925 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
928 ret = core->protect_count; in clk_core_rate_nuke_protect()
929 core->protect_count = 1; in clk_core_rate_nuke_protect()
936 * clk_rate_exclusive_put - release exclusivity over clock rate control
937 * @clk: the clk over which the exclusivity is released
943 * further up the parent chain of clocks. As a result, clocks up parent chain
953 void clk_rate_exclusive_put(struct clk *clk) in clk_rate_exclusive_put() argument
955 if (!clk) in clk_rate_exclusive_put()
964 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
967 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
968 clk->exclusive_count--; in clk_rate_exclusive_put()
981 if (core->protect_count == 0) in clk_core_rate_protect()
982 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
984 core->protect_count++; in clk_core_rate_protect()
998 core->protect_count = count; in clk_core_rate_restore_protect()
1002 * clk_rate_exclusive_get - get exclusivity over the clk rate control
1003 * @clk: the clk over which the exclusity of rate control is requested
1009 * further up the parent chain of clocks. As a result, clocks up parent chain
1017 * Returns 0 on success, -EERROR otherwise
1019 int clk_rate_exclusive_get(struct clk *clk) in clk_rate_exclusive_get() argument
1021 if (!clk) in clk_rate_exclusive_get()
1025 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
1026 clk->exclusive_count++; in clk_rate_exclusive_get()
1040 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
1041 "%s already unprepared\n", core->name)) in clk_core_unprepare()
1044 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
1045 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
1048 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
1051 if (--core->prepare_count > 0) in clk_core_unprepare()
1054 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
1058 if (core->ops->unprepare) in clk_core_unprepare()
1059 core->ops->unprepare(core->hw); in clk_core_unprepare()
1062 clk_core_unprepare(core->parent); in clk_core_unprepare()
1074 * clk_unprepare - undo preparation of a clock source
1075 * @clk: the clk being unprepared
1078 * simple case, clk_unprepare can be used instead of clk_disable to gate a clk
1079 * if the operation may sleep. One example is a clk which is accessed over
1080 * I2c. In the complex case a clk gate operation may require a fast and a slow
1084 void clk_unprepare(struct clk *clk) in clk_unprepare() argument
1086 if (IS_ERR_OR_NULL(clk)) in clk_unprepare()
1089 clk_core_unprepare_lock(clk->core); in clk_unprepare()
1102 if (core->prepare_count == 0) { in clk_core_prepare()
1107 ret = clk_core_prepare(core->parent); in clk_core_prepare()
1113 if (core->ops->prepare) in clk_core_prepare()
1114 ret = core->ops->prepare(core->hw); in clk_core_prepare()
1122 core->prepare_count++; in clk_core_prepare()
1131 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1136 clk_core_unprepare(core->parent); in clk_core_prepare()
1154 * clk_prepare - prepare a clock source
1155 * @clk: the clk being prepared
1158 * case, clk_prepare can be used instead of clk_enable to ungate a clk if the
1159 * operation may sleep. One example is a clk which is accessed over I2c. In
1160 * the complex case a clk ungate operation may require a fast and a slow part.
1163 * Returns 0 on success, -EERROR otherwise.
1165 int clk_prepare(struct clk *clk) in clk_prepare() argument
1167 if (!clk) in clk_prepare()
1170 return clk_core_prepare_lock(clk->core); in clk_prepare()
1181 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1184 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1185 "Disabling critical %s\n", core->name)) in clk_core_disable()
1188 if (--core->enable_count > 0) in clk_core_disable()
1193 if (core->ops->disable) in clk_core_disable()
1194 core->ops->disable(core->hw); in clk_core_disable()
1198 clk_core_disable(core->parent); in clk_core_disable()
1211 * clk_disable - gate a clock
1212 * @clk: the clk being gated
1216 * clk if the operation is fast and will never sleep. One example is a
1217 * SoC-internal clk which is controlled via simple register writes. In the
1218 * complex case a clk gate operation may require a fast and a slow part. It is
1222 void clk_disable(struct clk *clk) in clk_disable() argument
1224 if (IS_ERR_OR_NULL(clk)) in clk_disable()
1227 clk_core_disable_lock(clk->core); in clk_disable()
1240 if (WARN(core->prepare_count == 0, in clk_core_enable()
1241 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1242 return -ESHUTDOWN; in clk_core_enable()
1244 if (core->enable_count == 0) { in clk_core_enable()
1245 ret = clk_core_enable(core->parent); in clk_core_enable()
1252 if (core->ops->enable) in clk_core_enable()
1253 ret = core->ops->enable(core->hw); in clk_core_enable()
1258 clk_core_disable(core->parent); in clk_core_enable()
1263 core->enable_count++; in clk_core_enable()
1280 * clk_gate_restore_context - restore context for poweroff
1291 struct clk_core *core = hw->core; in clk_gate_restore_context()
1293 if (core->enable_count) in clk_gate_restore_context()
1294 core->ops->enable(hw); in clk_gate_restore_context()
1296 core->ops->disable(hw); in clk_gate_restore_context()
1305 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1311 if (core->ops && core->ops->save_context) in clk_core_save_context()
1312 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1321 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1322 core->ops->restore_context(core->hw); in clk_core_restore_context()
1324 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1329 * clk_save_context - save clock context for poweroff
1337 struct clk_core *clk; in clk_save_context() local
1340 hlist_for_each_entry(clk, &clk_root_list, child_node) { in clk_save_context()
1341 ret = clk_core_save_context(clk); in clk_save_context()
1346 hlist_for_each_entry(clk, &clk_orphan_list, child_node) { in clk_save_context()
1347 ret = clk_core_save_context(clk); in clk_save_context()
1357 * clk_restore_context - restore clock context after poweroff
1375 * clk_enable - ungate a clock
1376 * @clk: the clk being ungated
1379 * simple case, clk_enable can be used instead of clk_prepare to ungate a clk
1380 * if the operation will never sleep. One example is a SoC-internal clk which
1381 * is controlled via simple register writes. In the complex case a clk ungate
1384 * must be called before clk_enable. Returns 0 on success, -EERROR
1387 int clk_enable(struct clk *clk) in clk_enable() argument
1389 if (!clk) in clk_enable()
1392 return clk_core_enable_lock(clk->core); in clk_enable()
1397 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
1398 * @clk: clock source
1401 * making clk_enable()/clk_disable() no-ops, false otherwise.
1411 bool clk_is_enabled_when_prepared(struct clk *clk) in clk_is_enabled_when_prepared() argument
1413 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1444 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1447 if (core->prepare_count) in clk_unprepare_unused_subtree()
1450 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1455 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1456 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1457 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1458 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1470 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1473 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1474 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1478 if (core->enable_count) in clk_disable_unused_subtree()
1481 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1485 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1491 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1492 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1493 else if (core->ops->disable) in clk_disable_unused_subtree()
1494 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1500 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1501 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1518 pr_warn("clk: Not disabling unused clocks\n"); in clk_disable_unused()
1522 pr_info("clk: Disabling unused clocks\n"); in clk_disable_unused()
1528 * Grab the prepare lock to keep the clk topology stable while iterating in clk_disable_unused()
1564 * Some clock providers hand-craft their clk_rate_requests and in clk_core_determine_round_nolock()
1571 if (!req->min_rate && !req->max_rate) in clk_core_determine_round_nolock()
1573 __func__, core->name); in clk_core_determine_round_nolock()
1575 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in clk_core_determine_round_nolock()
1579 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1580 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1584 req->rate = core->rate; in clk_core_determine_round_nolock()
1585 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1586 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1587 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1588 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1589 &req->best_parent_rate); in clk_core_determine_round_nolock()
1593 req->rate = rate; in clk_core_determine_round_nolock()
1595 return -EINVAL; in clk_core_determine_round_nolock()
1605 struct clk_core *parent; in clk_core_init_rate_req() local
1611 req->max_rate = ULONG_MAX; in clk_core_init_rate_req()
1616 req->core = core; in clk_core_init_rate_req()
1617 req->rate = rate; in clk_core_init_rate_req()
1618 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1620 parent = core->parent; in clk_core_init_rate_req()
1621 if (parent) { in clk_core_init_rate_req()
1622 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1623 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1625 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1626 req->best_parent_rate = 0; in clk_core_init_rate_req()
1631 * clk_hw_init_rate_request - Initializes a clk_rate_request
1632 * @hw: the clk for which we want to submit a rate request
1646 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1651 * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent
1654 * @parent: the clk we want to forward @old_req to
1656 * @parent_rate: The rate which is to be requested to @parent
1658 * Initializes a clk_rate_request structure to submit to a clock parent
1663 const struct clk_hw *parent, in clk_hw_forward_rate_request() argument
1667 if (WARN_ON(!hw || !old_req || !parent || !req)) in clk_hw_forward_rate_request()
1670 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1671 parent->core, req, in clk_hw_forward_rate_request()
1678 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1689 req->rate = 0; in clk_core_round_rate_nolock()
1696 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1699 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1703 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1709 req->best_parent_rate = parent_req.rate; in clk_core_round_rate_nolock()
1710 req->rate = parent_req.rate; in clk_core_round_rate_nolock()
1715 req->rate = core->rate; in clk_core_round_rate_nolock()
1720 * __clk_determine_rate - get the closest rate actually supported by a clock
1729 req->rate = 0; in __clk_determine_rate()
1733 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1738 * clk_hw_round_rate() - round the given rate for a hw clk
1739 * @hw: the hw clk for which we are rounding a rate
1742 * Takes in a rate as input and rounds it to a rate that the clk can actually
1746 * For clk providers to call from within clk_ops such as .round_rate,
1749 * Return: returns rounded rate of hw clk if clk supports round_rate operation
1750 * else returns the parent rate.
1757 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1761 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1772 * clk_round_rate - round the given rate for a clk
1773 * @clk: the clk for which we are rounding a rate
1776 * Takes in a rate as input and rounds it to a rate that the clk can actually
1777 * use which is then returned. If clk doesn't support round_rate operation
1778 * then the parent rate is returned.
1780 long clk_round_rate(struct clk *clk, unsigned long rate) in clk_round_rate() argument
1785 if (!clk) in clk_round_rate()
1790 if (clk->exclusive_count) in clk_round_rate()
1791 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1793 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1797 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1801 if (clk->exclusive_count) in clk_round_rate()
1802 clk_core_rate_protect(clk->core); in clk_round_rate()
1814 * __clk_notify - call clk notifier chain
1815 * @core: clk that is changing rate
1816 * @msg: clk notifier type (see include/linux/clk.h)
1817 * @old_rate: old clk rate
1818 * @new_rate: new clk rate
1820 * Triggers a notifier call chain on the clk rate-change notification
1821 * for 'clk'. Passes a pointer to the struct clk and the previous
1838 if (cn->clk->core == core) { in __clk_notify()
1839 cnd.clk = cn->clk; in __clk_notify()
1840 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1852 * @core: first clk in the subtree
1854 * Walks the subtree of clks starting with clk and recalculates accuracies as
1855 * it goes. Note that if a clk does not implement the .recalc_accuracy
1857 * parent.
1866 if (core->parent) in __clk_recalc_accuracies()
1867 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1869 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1870 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1873 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1875 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1881 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1888 * clk_get_accuracy - return the accuracy of clk
1889 * @clk: the clk whose accuracy is being returned
1891 * Simply returns the cached accuracy of the clk, unless
1894 * If clk is NULL then returns 0.
1896 long clk_get_accuracy(struct clk *clk) in clk_get_accuracy() argument
1900 if (!clk) in clk_get_accuracy()
1904 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1916 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1917 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1925 * @core: first clk in the subtree
1927 * @msg: notification type (see include/linux/clk.h)
1929 * Walks the subtree of clks starting with clk and recalculates rates as it
1930 * goes. Note that if a clk does not implement the .recalc_rate callback then
1931 * it is assumed that the clock will take on the rate of its parent.
1945 old_rate = core->rate; in __clk_recalc_rates()
1947 if (core->parent) in __clk_recalc_rates()
1948 parent_rate = core->parent->rate; in __clk_recalc_rates()
1950 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1952 core->req_rate = core->rate; in __clk_recalc_rates()
1958 if (core->notifier_count && msg) in __clk_recalc_rates()
1959 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1961 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1967 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1974 * clk_get_rate - return the rate of clk
1975 * @clk: the clk whose rate is being returned
1977 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1979 * the clock enabledness. If clk is NULL, or if an error occurred, then returns
1982 unsigned long clk_get_rate(struct clk *clk) in clk_get_rate() argument
1986 if (!clk) in clk_get_rate()
1990 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1998 struct clk_core *parent) in clk_fetch_parent_index() argument
2002 if (!parent) in clk_fetch_parent_index()
2003 return -EINVAL; in clk_fetch_parent_index()
2005 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
2007 if (core->parents[i].core == parent) in clk_fetch_parent_index()
2011 if (core->parents[i].core) in clk_fetch_parent_index()
2015 if (core->parents[i].hw) { in clk_fetch_parent_index()
2016 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
2024 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
2028 if (core->parents[i].name && in clk_fetch_parent_index()
2029 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
2033 if (i == core->num_parents) in clk_fetch_parent_index()
2034 return -EINVAL; in clk_fetch_parent_index()
2036 core->parents[i].core = parent; in clk_fetch_parent_index()
2041 * clk_hw_get_parent_index - return the index of the parent clock
2042 * @hw: clk_hw associated with the clk being consumed
2044 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
2045 * clock does not have a current parent.
2049 struct clk_hw *parent = clk_hw_get_parent(hw); in clk_hw_get_parent_index() local
2051 if (WARN_ON(parent == NULL)) in clk_hw_get_parent_index()
2052 return -EINVAL; in clk_hw_get_parent_index()
2054 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
2065 core->orphan = is_orphan; in clk_core_update_orphan_status()
2067 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
2073 bool was_orphan = core->orphan; in clk_reparent()
2075 hlist_del(&core->child_node); in clk_reparent()
2078 bool becomes_orphan = new_parent->orphan; in clk_reparent()
2081 if (new_parent->new_child == core) in clk_reparent()
2082 new_parent->new_child = NULL; in clk_reparent()
2084 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
2089 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
2094 core->parent = new_parent; in clk_reparent()
2098 struct clk_core *parent) in __clk_set_parent_before() argument
2101 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
2115 * parent and also protect against a race with clk_enable() by in __clk_set_parent_before()
2116 * forcing the clock and the new parent on. This ensures that all in __clk_set_parent_before()
2123 /* enable old_parent & parent if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_before()
2124 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2126 clk_core_prepare_enable(parent); in __clk_set_parent_before()
2130 if (core->prepare_count) { in __clk_set_parent_before()
2131 clk_core_prepare_enable(parent); in __clk_set_parent_before()
2135 /* update the clk tree topology */ in __clk_set_parent_before()
2137 clk_reparent(core, parent); in __clk_set_parent_before()
2144 struct clk_core *parent, in __clk_set_parent_after() argument
2151 if (core->prepare_count) { in __clk_set_parent_after()
2156 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
2157 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2158 clk_core_disable_unprepare(parent); in __clk_set_parent_after()
2163 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
2170 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
2172 trace_clk_set_parent(core, parent); in __clk_set_parent()
2175 if (parent && core->ops->set_parent) in __clk_set_parent()
2176 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2178 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
2185 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
2190 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
2197 * @core: first clk in the subtree
2198 * @parent_rate: the "future" rate of clk's parent
2200 * Walks the subtree of clks starting with clk, speculating rates as it
2204 * pre-rate change notifications and returns early if no clks in the
2205 * subtree have subscribed to the notifications. Note that if a clk does not
2207 * take on the rate of its parent.
2221 if (core->notifier_count) in __clk_speculate_rates()
2222 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2225 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
2226 __func__, core->name, ret); in __clk_speculate_rates()
2230 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2245 core->new_rate = new_rate; in clk_calc_subtree()
2246 core->new_parent = new_parent; in clk_calc_subtree()
2247 core->new_parent_index = p_index; in clk_calc_subtree()
2248 /* include clk in new parent's PRE_RATE_CHANGE notifications */ in clk_calc_subtree()
2249 core->new_child = NULL; in clk_calc_subtree()
2250 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2251 new_parent->new_child = core; in clk_calc_subtree()
2253 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2254 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
2255 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
2267 struct clk_core *old_parent, *parent; in clk_calc_new_rates() local
2279 /* save parent rate, if it exists */ in clk_calc_new_rates()
2280 parent = old_parent = core->parent; in clk_calc_new_rates()
2281 if (parent) in clk_calc_new_rates()
2282 best_parent_rate = parent->rate; in clk_calc_new_rates()
2286 /* find the closest rate and parent clk/rate */ in clk_calc_new_rates()
2302 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2306 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2307 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
2308 core->new_rate = core->rate; in clk_calc_new_rates()
2311 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
2312 top = clk_calc_new_rates(parent, rate); in clk_calc_new_rates()
2313 new_rate = parent->new_rate; in clk_calc_new_rates()
2317 /* some clocks must be gated to change parent */ in clk_calc_new_rates()
2318 if (parent != old_parent && in clk_calc_new_rates()
2319 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2321 __func__, core->name); in clk_calc_new_rates()
2325 /* try finding the new parent index */ in clk_calc_new_rates()
2326 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2327 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
2329 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_calc_new_rates()
2330 __func__, parent->name, core->name); in clk_calc_new_rates()
2335 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2336 best_parent_rate != parent->rate) in clk_calc_new_rates()
2337 top = clk_calc_new_rates(parent, best_parent_rate); in clk_calc_new_rates()
2340 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
2356 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2359 if (core->notifier_count) { in clk_propagate_rate_change()
2360 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2365 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2367 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2374 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2375 if (core->new_child) { in clk_propagate_rate_change()
2376 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2396 struct clk_core *parent = NULL; in clk_change_rate() local
2398 old_rate = core->rate; in clk_change_rate()
2400 if (core->new_parent) { in clk_change_rate()
2401 parent = core->new_parent; in clk_change_rate()
2402 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2403 } else if (core->parent) { in clk_change_rate()
2404 parent = core->parent; in clk_change_rate()
2405 best_parent_rate = core->parent->rate; in clk_change_rate()
2411 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2416 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2417 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2418 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2420 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2422 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2424 core->new_parent_index); in clk_change_rate()
2425 } else if (core->ops->set_parent) { in clk_change_rate()
2426 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2429 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2430 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2433 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2434 clk_core_prepare_enable(parent); in clk_change_rate()
2436 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2438 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2439 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2441 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2443 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2445 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2450 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2451 clk_core_disable_unprepare(parent); in clk_change_rate()
2453 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2454 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2456 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2457 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2463 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2465 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2470 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2471 if (core->new_child) in clk_change_rate()
2472 clk_change_rate(core->new_child); in clk_change_rate()
2525 return -EBUSY; in clk_core_set_rate_nolock()
2530 return -EINVAL; in clk_core_set_rate_nolock()
2540 fail_clk->name); in clk_core_set_rate_nolock()
2542 ret = -EBUSY; in clk_core_set_rate_nolock()
2549 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2557 * clk_set_rate - specify a new rate for clk
2558 * @clk: the clk whose rate is being changed
2559 * @rate: the new rate for clk
2561 * In the simplest case clk_set_rate will only adjust the rate of clk.
2564 * propagate up to clk's parent; whether or not this happens depends on the
2565 * outcome of clk's .round_rate implementation. If *parent_rate is unchanged
2566 * after calling .round_rate then upstream parent propagation is ignored. If
2567 * *parent_rate comes back with a new rate for clk's parent then we propagate
2568 * up to clk's parent and set its rate. Upward propagation will continue
2569 * until either a clk does not support the CLK_SET_RATE_PARENT flag or
2570 * .round_rate stops requesting changes to clk's parent_rate.
2575 * Returns 0 on success, -EERROR otherwise.
2577 int clk_set_rate(struct clk *clk, unsigned long rate) in clk_set_rate() argument
2581 if (!clk) in clk_set_rate()
2587 if (clk->exclusive_count) in clk_set_rate()
2588 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2590 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2592 if (clk->exclusive_count) in clk_set_rate()
2593 clk_core_rate_protect(clk->core); in clk_set_rate()
2602 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2603 * @clk: the clk whose rate is being changed
2604 * @rate: the new rate for clk
2618 * Returns 0 on success, -EERROR otherwise.
2620 int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) in clk_set_rate_exclusive() argument
2624 if (!clk) in clk_set_rate_exclusive()
2636 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2638 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2639 clk->exclusive_count++; in clk_set_rate_exclusive()
2648 static int clk_set_rate_range_nolock(struct clk *clk, in clk_set_rate_range_nolock() argument
2657 if (!clk) in clk_set_rate_range_nolock()
2660 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2663 pr_err("%s: clk %s dev %s con %s: invalid range [%lu, %lu]\n", in clk_set_rate_range_nolock()
2664 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2666 return -EINVAL; in clk_set_rate_range_nolock()
2669 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2670 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2673 old_min = clk->min_rate; in clk_set_rate_range_nolock()
2674 old_max = clk->max_rate; in clk_set_rate_range_nolock()
2675 clk->min_rate = min; in clk_set_rate_range_nolock()
2676 clk->max_rate = max; in clk_set_rate_range_nolock()
2678 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2679 ret = -EINVAL; in clk_set_rate_range_nolock()
2683 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2684 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2685 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2699 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range_nolock()
2701 * - the determine_rate() callback does not really check for in clk_set_rate_range_nolock()
2705 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2708 clk->min_rate = old_min; in clk_set_rate_range_nolock()
2709 clk->max_rate = old_max; in clk_set_rate_range_nolock()
2713 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2714 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2720 * clk_set_rate_range - set a rate range for a clock source
2721 * @clk: clock source
2727 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) in clk_set_rate_range() argument
2731 if (!clk) in clk_set_rate_range()
2736 ret = clk_set_rate_range_nolock(clk, min, max); in clk_set_rate_range()
2745 * clk_set_min_rate - set a minimum clock rate for a clock source
2746 * @clk: clock source
2751 int clk_set_min_rate(struct clk *clk, unsigned long rate) in clk_set_min_rate() argument
2753 if (!clk) in clk_set_min_rate()
2756 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2758 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2763 * clk_set_max_rate - set a maximum clock rate for a clock source
2764 * @clk: clock source
2769 int clk_set_max_rate(struct clk *clk, unsigned long rate) in clk_set_max_rate() argument
2771 if (!clk) in clk_set_max_rate()
2774 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2776 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2781 * clk_get_parent - return the parent of a clk
2782 * @clk: the clk whose parent gets returned
2784 * Simply returns clk->parent. Returns NULL if clk is NULL.
2786 struct clk *clk_get_parent(struct clk *clk) in clk_get_parent() argument
2788 struct clk *parent; in clk_get_parent() local
2790 if (!clk) in clk_get_parent()
2794 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2795 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2798 return parent; in clk_get_parent()
2806 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2807 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2825 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2829 * clk_has_parent - check if a clock is a possible parent for another
2830 * @clk: clock source
2831 * @parent: parent clock source
2834 * the parent of another without actually changing the parent.
2836 * Returns true if @parent is a possible parent for @clk, false otherwise.
2838 bool clk_has_parent(const struct clk *clk, const struct clk *parent) in clk_has_parent() argument
2841 if (!clk || !parent) in clk_has_parent()
2844 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2849 struct clk_core *parent) in clk_core_set_parent_nolock() argument
2860 if (core->parent == parent) in clk_core_set_parent_nolock()
2863 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2864 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2865 return -EPERM; in clk_core_set_parent_nolock()
2867 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2868 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2869 return -EBUSY; in clk_core_set_parent_nolock()
2872 return -EBUSY; in clk_core_set_parent_nolock()
2874 /* try finding the new parent index */ in clk_core_set_parent_nolock()
2875 if (parent) { in clk_core_set_parent_nolock()
2876 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2878 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_core_set_parent_nolock()
2879 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2882 p_rate = parent->rate; in clk_core_set_parent_nolock()
2896 /* do the re-parent */ in clk_core_set_parent_nolock()
2897 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2913 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *parent) in clk_hw_set_parent() argument
2915 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2920 * clk_set_parent - switch the parent of a mux clk
2921 * @clk: the mux clk whose input we are switching
2922 * @parent: the new input to clk
2924 * Re-parent clk to use parent as its new input source. If clk is in
2925 * prepared state, the clk will get enabled for the duration of this call. If
2926 * that's not acceptable for a specific clk (Eg: the consumer can't handle
2928 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
2930 * After successfully changing clk's parent clk_set_parent will update the
2931 * clk topology, sysfs topology and propagate rate recalculation via
2934 * Returns 0 on success, -EERROR otherwise.
2936 int clk_set_parent(struct clk *clk, struct clk *parent) in clk_set_parent() argument
2940 if (!clk) in clk_set_parent()
2945 if (clk->exclusive_count) in clk_set_parent()
2946 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2948 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2949 parent ? parent->core : NULL); in clk_set_parent()
2951 if (clk->exclusive_count) in clk_set_parent()
2952 clk_core_rate_protect(clk->core); in clk_set_parent()
2962 int ret = -EINVAL; in clk_core_set_phase_nolock()
2970 return -EBUSY; in clk_core_set_phase_nolock()
2974 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2975 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2977 core->phase = degrees; in clk_core_set_phase_nolock()
2986 * clk_set_phase - adjust the phase shift of a clock signal
2987 * @clk: clock signal source
2991 * degrees. Returns 0 on success, -EERROR otherwise.
2995 * phase locked-loop clock signal generators we may shift phase with
3002 * clock accuracy. A parent clock phase attribute does not have an
3005 int clk_set_phase(struct clk *clk, int degrees) in clk_set_phase() argument
3009 if (!clk) in clk_set_phase()
3019 if (clk->exclusive_count) in clk_set_phase()
3020 clk_core_rate_unprotect(clk->core); in clk_set_phase()
3022 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
3024 if (clk->exclusive_count) in clk_set_phase()
3025 clk_core_rate_protect(clk->core); in clk_set_phase()
3038 if (!core->ops->get_phase) in clk_core_get_phase()
3042 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
3044 core->phase = ret; in clk_core_get_phase()
3050 * clk_get_phase - return the phase shift of a clock signal
3051 * @clk: clock signal source
3054 * -EERROR.
3056 int clk_get_phase(struct clk *clk) in clk_get_phase() argument
3060 if (!clk) in clk_get_phase()
3064 ret = clk_core_get_phase(clk->core); in clk_get_phase()
3074 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
3075 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
3082 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
3085 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
3088 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
3093 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
3094 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
3109 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
3110 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
3111 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
3112 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
3131 return -EBUSY; in clk_core_set_duty_cycle_nolock()
3135 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3138 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3140 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3152 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3153 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3154 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3155 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3162 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
3163 * @clk: clock signal source
3172 int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den) in clk_set_duty_cycle() argument
3177 if (!clk) in clk_set_duty_cycle()
3182 return -EINVAL; in clk_set_duty_cycle()
3189 if (clk->exclusive_count) in clk_set_duty_cycle()
3190 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3192 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3194 if (clk->exclusive_count) in clk_set_duty_cycle()
3195 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3206 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3213 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
3221 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
3222 * @clk: clock signal source
3228 int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale) in clk_get_scaled_duty_cycle() argument
3230 if (!clk) in clk_get_scaled_duty_cycle()
3233 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3238 * clk_is_match - check if two clk's point to the same hardware clock
3239 * @p: clk compared against q
3240 * @q: clk compared against p
3242 * Returns true if the two struct clk pointers both point to the same hardware
3243 * clock node. Put differently, returns true if struct clk *p and struct clk *q
3248 bool clk_is_match(const struct clk *p, const struct clk *q) in clk_is_match()
3250 /* trivial case: identical struct clk's or both NULL */ in clk_is_match()
3254 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
3256 if (p->core == q->core) in clk_is_match()
3282 struct clk *clk_user; in clk_summary_show_one()
3285 seq_printf(s, "%*s%-*s %-7d %-8d %-8d %-11lu %-10lu ", in clk_summary_show_one()
3287 35 - level * 3, c->name, in clk_summary_show_one()
3288 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
3294 seq_printf(s, "%-5d", phase); in clk_summary_show_one()
3296 seq_puts(s, "-----"); in clk_summary_show_one()
3298 seq_printf(s, " %-6d", clk_core_get_scaled_duty_cycle(c, 100000)); in clk_summary_show_one()
3300 if (c->ops->is_enabled) in clk_summary_show_one()
3302 else if (!c->ops->enable) in clk_summary_show_one()
3307 hlist_for_each_entry(clk_user, &c->clks, clks_node) { in clk_summary_show_one()
3308 seq_printf(s, "%*s%-*s %-25s\n", in clk_summary_show_one()
3311 clk_user->dev_id ? clk_user->dev_id : "deviceless", in clk_summary_show_one()
3312 clk_user->con_id ? clk_user->con_id : "no_connection_id"); in clk_summary_show_one()
3326 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
3333 struct hlist_head **lists = s->private; in clk_summary_show()
3338 …s(s, "--------------------------------------------------------------------------------------------… in clk_summary_show()
3365 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
3366 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
3367 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
3368 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
3386 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3398 struct hlist_head **lists = s->private; in clk_dump_show()
3453 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3455 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3464 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3511 struct clk_core *core = s->private; in clk_flags_show()
3512 unsigned long flags = core->flags; in clk_flags_show()
3533 struct clk_core *parent; in possible_parent_show() local
3537 * Go through the following options to fetch a parent's name. in possible_parent_show()
3539 * 1. Fetch the registered parent clock and use its name in possible_parent_show()
3542 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3544 * This may still fail in some cases, such as when the parent is in possible_parent_show()
3548 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3549 if (parent) { in possible_parent_show()
3550 seq_puts(s, parent->name); in possible_parent_show()
3551 } else if (core->parents[i].name) { in possible_parent_show()
3552 seq_puts(s, core->parents[i].name); in possible_parent_show()
3553 } else if (core->parents[i].fw_name) { in possible_parent_show()
3554 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3556 if (core->parents[i].index >= 0) in possible_parent_show()
3557 name = of_clk_get_parent_name(core->of_node, core->parents[i].index); in possible_parent_show()
3569 struct clk_core *core = s->private; in possible_parents_show()
3572 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3583 struct clk_core *core = s->private; in current_parent_show()
3585 if (core->parent) in current_parent_show()
3586 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3596 struct seq_file *s = file->private_data; in current_parent_write()
3597 struct clk_core *core = s->private; in current_parent_write()
3598 struct clk_core *parent; in current_parent_write() local
3606 parent = clk_core_get_parent_by_index(core, idx); in current_parent_write()
3607 if (!parent) in current_parent_write()
3608 return -ENOENT; in current_parent_write()
3611 err = clk_core_set_parent_nolock(core, parent); in current_parent_write()
3630 struct clk_core *core = s->private; in clk_duty_cycle_show()
3631 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3633 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3641 struct clk_core *core = s->private; in clk_min_rate_show()
3655 struct clk_core *core = s->private; in clk_max_rate_show()
3674 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3675 core->dentry = root; in clk_debug_create_one()
3681 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3682 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3684 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3685 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3686 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3687 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3694 if (core->num_parents > 1) in clk_debug_create_one()
3699 if (core->num_parents > 0) in clk_debug_create_one()
3703 if (core->num_parents > 1) in clk_debug_create_one()
3707 if (core->ops->debug_init) in clk_debug_create_one()
3708 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3712 * clk_debug_register - add a clk node to the debugfs clk directory
3713 * @core: the clk being added to the debugfs clk directory
3715 * Dynamically adds a clk to the debugfs clk directory if debugfs has been
3716 * initialized. Otherwise it bails out early since the debugfs clk directory
3722 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3729 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3730 * @core: the clk being removed from the debugfs clk directory
3732 * Dynamically removes a clk and all its child nodes from the
3733 * debugfs clk directory if clk->dentry points to debugfs created by
3739 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3740 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3741 core->dentry = NULL; in clk_debug_unregister()
3746 * clk_debug_init - lazily populate the debugfs clk directory
3750 * populates the debugfs clk directory once at boot-time when we know that
3751 * debugfs is setup. It should only be called once at boot-time, all other clks
3763 pr_warn("** WRITEABLE clk DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n"); in clk_debug_init()
3765 pr_warn("** This means that this kernel is built to expose clk operations **\n"); in clk_debug_init()
3766 pr_warn("** such as parent or rate setting, enabling, disabling, etc. **\n"); in clk_debug_init()
3776 rootdir = debugfs_create_dir("clk", NULL); in clk_debug_init()
3811 * parent. in clk_core_reparent_orphans_nolock()
3814 struct clk_core *parent = __clk_init_parent(orphan); in clk_core_reparent_orphans_nolock() local
3820 * are enabled during init but might not have a parent yet. in clk_core_reparent_orphans_nolock()
3822 if (parent) { in clk_core_reparent_orphans_nolock()
3823 /* update the clk tree topology */ in clk_core_reparent_orphans_nolock()
3824 __clk_set_parent_before(orphan, parent); in clk_core_reparent_orphans_nolock()
3825 __clk_set_parent_after(orphan, parent, NULL); in clk_core_reparent_orphans_nolock()
3837 * 'req_rate' is set to something non-zero so that in clk_core_reparent_orphans_nolock()
3840 orphan->req_rate = orphan->rate; in clk_core_reparent_orphans_nolock()
3846 * __clk_core_init - initialize the data structures in a struct clk_core
3850 * parent and rate and sets them both.
3855 struct clk_core *parent; in __clk_core_init() local
3862 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3863 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3864 * being NULL as the clk not being registered yet. This is crucial so in __clk_core_init()
3865 * that clks aren't parented until their parent is fully registered. in __clk_core_init()
3867 core->hw->core = core; in __clk_core_init()
3874 if (clk_core_lookup(core->name)) { in __clk_core_init()
3875 pr_debug("%s: clk %s already initialized\n", in __clk_core_init()
3876 __func__, core->name); in __clk_core_init()
3877 ret = -EEXIST; in __clk_core_init()
3881 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3882 if (core->ops->set_rate && in __clk_core_init()
3883 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3884 core->ops->recalc_rate)) { in __clk_core_init()
3886 __func__, core->name); in __clk_core_init()
3887 ret = -EINVAL; in __clk_core_init()
3891 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3893 __func__, core->name); in __clk_core_init()
3894 ret = -EINVAL; in __clk_core_init()
3898 if (core->ops->set_parent && !core->ops->determine_rate) { in __clk_core_init()
3900 __func__, core->name); in __clk_core_init()
3901 ret = -EINVAL; in __clk_core_init()
3905 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3907 __func__, core->name); in __clk_core_init()
3908 ret = -EINVAL; in __clk_core_init()
3912 if (core->ops->set_rate_and_parent && in __clk_core_init()
3913 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3915 __func__, core->name); in __clk_core_init()
3916 ret = -EINVAL; in __clk_core_init()
3921 * optional platform-specific magic in __clk_core_init()
3929 * such as rate, parent, etc ... in __clk_core_init()
3934 if (core->ops->init) { in __clk_core_init()
3935 ret = core->ops->init(core->hw); in __clk_core_init()
3940 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3943 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3944 * parent has not yet been clk_core_init'd then place clk in the orphan in __clk_core_init()
3945 * list. If clk doesn't have any parents then place it in the root in __clk_core_init()
3946 * clk list. in __clk_core_init()
3948 * Every time a new clk is clk_init'd then we walk the list of orphan in __clk_core_init()
3949 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
3952 if (parent) { in __clk_core_init()
3953 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3954 core->orphan = parent->orphan; in __clk_core_init()
3955 } else if (!core->num_parents) { in __clk_core_init()
3956 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3957 core->orphan = false; in __clk_core_init()
3959 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3960 core->orphan = true; in __clk_core_init()
3964 * Set clk's accuracy. The preferred method is to use in __clk_core_init()
3966 * fallback is to use the parent's accuracy. If a clock doesn't have a in __clk_core_init()
3967 * parent (or is orphaned) then accuracy is set to zero (perfect in __clk_core_init()
3970 if (core->ops->recalc_accuracy) in __clk_core_init()
3971 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3972 clk_core_get_accuracy_no_lock(parent)); in __clk_core_init()
3973 else if (parent) in __clk_core_init()
3974 core->accuracy = parent->accuracy; in __clk_core_init()
3976 core->accuracy = 0; in __clk_core_init()
3979 * Set clk's phase by clk_core_get_phase() caching the phase. in __clk_core_init()
3980 * Since a phase is by definition relative to its parent, just in __clk_core_init()
3986 pr_warn("%s: Failed to get phase for clk '%s'\n", __func__, in __clk_core_init()
3987 core->name); in __clk_core_init()
3992 * Set clk's duty cycle. in __clk_core_init()
3997 * Set clk's rate. The preferred method is to use .recalc_rate. For in __clk_core_init()
3999 * parent's rate. If a clock doesn't have a parent (or is orphaned) in __clk_core_init()
4002 if (core->ops->recalc_rate) in __clk_core_init()
4003 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
4004 clk_core_get_rate_nolock(parent)); in __clk_core_init()
4005 else if (parent) in __clk_core_init()
4006 rate = parent->rate; in __clk_core_init()
4009 core->rate = core->req_rate = rate; in __clk_core_init()
4016 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
4019 pr_warn("%s: critical clk '%s' failed to prepare\n", in __clk_core_init()
4020 __func__, core->name); in __clk_core_init()
4026 pr_warn("%s: critical clk '%s' failed to enable\n", in __clk_core_init()
4027 __func__, core->name); in __clk_core_init()
4038 hlist_del_init(&core->child_node); in __clk_core_init()
4039 core->hw->core = NULL; in __clk_core_init()
4051 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
4052 * @core: clk to add consumer to
4053 * @clk: consumer to link to a clk
4055 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
4058 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
4063 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
4064 * @clk: consumer to unlink
4066 static void clk_core_unlink_consumer(struct clk *clk) in clk_core_unlink_consumer() argument
4069 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
4073 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
4074 * @core: clk to allocate a consumer for
4078 * Returns: clk consumer left unlinked from the consumer list
4080 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk()
4083 struct clk *clk; in alloc_clk() local
4085 clk = kzalloc(sizeof(*clk), GFP_KERNEL); in alloc_clk()
4086 if (!clk) in alloc_clk()
4087 return ERR_PTR(-ENOMEM); in alloc_clk()
4089 clk->core = core; in alloc_clk()
4090 clk->dev_id = dev_id; in alloc_clk()
4091 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
4092 clk->max_rate = ULONG_MAX; in alloc_clk()
4094 return clk; in alloc_clk()
4098 * free_clk - Free a clk consumer
4099 * @clk: clk consumer to free
4101 * Note, this assumes the clk has been unlinked from the clk_core consumer
4104 static void free_clk(struct clk *clk) in free_clk() argument
4106 kfree_const(clk->con_id); in free_clk()
4107 kfree(clk); in free_clk()
4111 * clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given
4113 * @dev: clk consumer device
4114 * @hw: clk_hw associated with the clk being consumed
4118 * This is the main function used to create a clk pointer for use by clk
4120 * used by the framework and clk provider respectively.
4122 struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, in clk_hw_create_clk()
4125 struct clk *clk; in clk_hw_create_clk() local
4132 core = hw->core; in clk_hw_create_clk()
4133 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
4134 if (IS_ERR(clk)) in clk_hw_create_clk()
4135 return clk; in clk_hw_create_clk()
4136 clk->dev = dev; in clk_hw_create_clk()
4138 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
4139 free_clk(clk); in clk_hw_create_clk()
4140 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
4143 kref_get(&core->ref); in clk_hw_create_clk()
4144 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
4146 return clk; in clk_hw_create_clk()
4150 * clk_hw_get_clk - get clk consumer given an clk_hw
4151 * @hw: clk_hw associated with the clk being consumed
4154 * Returns: new clk consumer
4156 * to get a consumer clk and act on the clock element
4159 struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id) in clk_hw_get_clk()
4161 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4174 return -EINVAL; in clk_cpy_name()
4180 return -ENOMEM; in clk_cpy_name()
4188 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
4189 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
4190 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
4191 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
4193 struct clk_parent_map *parents, *parent; in clk_core_populate_parent_map() local
4199 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
4203 core->parents = parents; in clk_core_populate_parent_map()
4205 return -ENOMEM; in clk_core_populate_parent_map()
4208 for (i = 0, parent = parents; i < num_parents; i++, parent++) { in clk_core_populate_parent_map()
4209 parent->index = -1; in clk_core_populate_parent_map()
4214 __func__, core->name); in clk_core_populate_parent_map()
4215 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
4218 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
4219 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
4220 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
4223 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
4227 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
4229 ret = -EINVAL; in clk_core_populate_parent_map()
4237 } while (--i >= 0); in clk_core_populate_parent_map()
4249 int i = core->num_parents; in clk_core_free_parent_map()
4251 if (!core->num_parents) in clk_core_free_parent_map()
4254 while (--i >= 0) { in clk_core_free_parent_map()
4255 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4256 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4259 kfree(core->parents); in clk_core_free_parent_map()
4267 if (core->rpm_enabled) { in __clk_release()
4269 hlist_del(&core->rpm_node); in __clk_release()
4274 kfree_const(core->name); in __clk_release()
4278 static struct clk *
4283 const struct clk_init_data *init = hw->init; in __clk_register()
4288 * we catch use of hw->init early on in the core. in __clk_register()
4290 hw->init = NULL; in __clk_register()
4294 ret = -ENOMEM; in __clk_register()
4298 kref_init(&core->ref); in __clk_register()
4300 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4301 if (!core->name) { in __clk_register()
4302 ret = -ENOMEM; in __clk_register()
4306 if (WARN_ON(!init->ops)) { in __clk_register()
4307 ret = -EINVAL; in __clk_register()
4310 core->ops = init->ops; in __clk_register()
4312 core->dev = dev; in __clk_register()
4314 core->of_node = np; in __clk_register()
4315 if (dev && dev->driver) in __clk_register()
4316 core->owner = dev->driver->owner; in __clk_register()
4317 core->hw = hw; in __clk_register()
4318 core->flags = init->flags; in __clk_register()
4319 core->num_parents = init->num_parents; in __clk_register()
4320 core->min_rate = 0; in __clk_register()
4321 core->max_rate = ULONG_MAX; in __clk_register()
4327 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4333 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4334 if (IS_ERR(hw->clk)) { in __clk_register()
4335 ret = PTR_ERR(hw->clk); in __clk_register()
4339 clk_core_link_consumer(core, hw->clk); in __clk_register()
4343 return hw->clk; in __clk_register()
4346 clk_core_unlink_consumer(hw->clk); in __clk_register()
4349 free_clk(hw->clk); in __clk_register()
4350 hw->clk = NULL; in __clk_register()
4356 kref_put(&core->ref, __clk_release); in __clk_register()
4362 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
4366 * @dev->parent if dev doesn't have a device node, or NULL if neither
4367 * @dev or @dev->parent have a device node.
4378 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
4384 * clk_register - allocate a new clock, register it and return an opaque cookie
4386 * @hw: link to hardware-specific clock data
4391 * Returns: a pointer to the newly allocated struct clk which
4396 struct clk *clk_register(struct device *dev, struct clk_hw *hw) in clk_register()
4403 * clk_hw_register - register a clk_hw and return an error code
4405 * @hw: link to hardware-specific clock data
4420 * of_clk_hw_register - register a clk_hw and return an error code
4422 * @hw: link to hardware-specific clock data
4439 * consumer calls clk_put() and the struct clk object is freed.
4443 return -ENXIO; in clk_nodrv_prepare_enable()
4454 return -ENXIO; in clk_nodrv_set_rate()
4459 return -ENXIO; in clk_nodrv_set_parent()
4465 return -ENXIO; in clk_nodrv_determine_rate()
4484 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
4485 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4486 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4488 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
4492 /* Remove this clk from all parent caches */
4507 * clk_unregister - unregister a currently registered clock
4508 * @clk: clock to unregister
4510 void clk_unregister(struct clk *clk) in clk_unregister() argument
4515 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in clk_unregister()
4518 clk_debug_unregister(clk->core); in clk_unregister()
4522 ops = clk->core->ops; in clk_unregister()
4525 clk->core->name); in clk_unregister()
4534 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4537 if (ops->terminate) in clk_unregister()
4538 ops->terminate(clk->core->hw); in clk_unregister()
4540 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4545 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4550 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4552 hlist_del_init(&clk->core->child_node); in clk_unregister()
4554 if (clk->core->prepare_count) in clk_unregister()
4556 __func__, clk->core->name); in clk_unregister()
4558 if (clk->core->protect_count) in clk_unregister()
4560 __func__, clk->core->name); in clk_unregister()
4563 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4564 free_clk(clk); in clk_unregister()
4569 * clk_hw_unregister - unregister a currently registered clk_hw
4570 * @hw: hardware-specific clock data to unregister
4574 clk_unregister(hw->clk); in clk_hw_unregister()
4580 clk_unregister(*(struct clk **)res); in devm_clk_unregister_cb()
4589 * devm_clk_register - resource managed clk_register()
4591 * @hw: link to hardware-specific clock data
4598 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw) in devm_clk_register()
4600 struct clk *clk; in devm_clk_register() local
4601 struct clk **clkp; in devm_clk_register()
4605 return ERR_PTR(-ENOMEM); in devm_clk_register()
4607 clk = clk_register(dev, hw); in devm_clk_register()
4608 if (!IS_ERR(clk)) { in devm_clk_register()
4609 *clkp = clk; in devm_clk_register()
4615 return clk; in devm_clk_register()
4620 * devm_clk_hw_register - resource managed clk_hw_register()
4622 * @hw: link to hardware-specific clock data
4635 return -ENOMEM; in devm_clk_hw_register()
4651 clk_put(*(struct clk **)res); in devm_clk_release()
4655 * devm_clk_hw_get_clk - resource managed clk_hw_get_clk()
4657 * @hw: clk_hw associated with the clk being consumed
4664 struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw, in devm_clk_hw_get_clk()
4667 struct clk *clk; in devm_clk_hw_get_clk() local
4668 struct clk **clkp; in devm_clk_hw_get_clk()
4674 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4678 return ERR_PTR(-ENOMEM); in devm_clk_hw_get_clk()
4680 clk = clk_hw_get_clk(hw, con_id); in devm_clk_hw_get_clk()
4681 if (!IS_ERR(clk)) { in devm_clk_hw_get_clk()
4682 *clkp = clk; in devm_clk_hw_get_clk()
4688 return clk; in devm_clk_hw_get_clk()
4696 void __clk_put(struct clk *clk) in __clk_put() argument
4700 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in __clk_put()
4710 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4712 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4713 clk_core_rate_unprotect(clk->core); in __clk_put()
4714 clk->exclusive_count = 0; in __clk_put()
4717 hlist_del(&clk->clks_node); in __clk_put()
4720 if (clk->min_rate > 0 || clk->max_rate < ULONG_MAX) in __clk_put()
4721 clk_set_rate_range_nolock(clk, 0, ULONG_MAX); in __clk_put()
4725 owner = clk->core->owner; in __clk_put()
4726 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4728 free_clk(clk); in __clk_put()
4731 /*** clk rate change notifiers ***/
4734 * clk_notifier_register - add a clk rate change notifier
4735 * @clk: struct clk * to watch
4738 * Request notification when clk's rate changes. This uses an SRCU
4741 * re-enter into the clk framework by calling any top-level clk APIs;
4748 * clk_notifier_register() must be called from non-atomic context.
4749 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4753 int clk_notifier_register(struct clk *clk, struct notifier_block *nb) in clk_notifier_register() argument
4756 int ret = -ENOMEM; in clk_notifier_register()
4758 if (!clk || !nb) in clk_notifier_register()
4759 return -EINVAL; in clk_notifier_register()
4763 /* search the list of notifiers for this clk */ in clk_notifier_register()
4765 if (cn->clk == clk) in clk_notifier_register()
4768 /* if clk wasn't in the notifier list, allocate new clk_notifier */ in clk_notifier_register()
4773 cn->clk = clk; in clk_notifier_register()
4774 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4776 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4779 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4781 clk->core->notifier_count++; in clk_notifier_register()
4791 * clk_notifier_unregister - remove a clk rate change notifier
4792 * @clk: struct clk *
4795 * Request no further notification for changes to 'clk' and frees memory
4798 * Returns -EINVAL if called with null arguments; otherwise, passes
4801 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb) in clk_notifier_unregister() argument
4804 int ret = -ENOENT; in clk_notifier_unregister()
4806 if (!clk || !nb) in clk_notifier_unregister()
4807 return -EINVAL; in clk_notifier_unregister()
4812 if (cn->clk == clk) { in clk_notifier_unregister()
4813 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4815 clk->core->notifier_count--; in clk_notifier_unregister()
4818 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4819 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4820 list_del(&cn->node); in clk_notifier_unregister()
4834 struct clk *clk; member
4842 clk_notifier_unregister(devres->clk, devres->nb); in devm_clk_notifier_release()
4845 int devm_clk_notifier_register(struct device *dev, struct clk *clk, in devm_clk_notifier_register() argument
4855 return -ENOMEM; in devm_clk_notifier_register()
4857 ret = clk_notifier_register(clk, nb); in devm_clk_notifier_register()
4859 devres->clk = clk; in devm_clk_notifier_register()
4860 devres->nb = nb; in devm_clk_notifier_register()
4879 * struct of_clk_provider - Clock provider registration structure
4882 * @get: Get clock callback. Returns NULL or a struct clk for the
4892 struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
4904 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec, in of_clk_src_simple_get()
4917 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) in of_clk_src_onecell_get()
4920 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4922 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4924 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4927 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4935 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4937 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4939 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4942 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4947 * of_clk_add_provider() - Register a clock provider for a node
4955 struct clk *(*clk_src_get)(struct of_phandle_args *clkspec, in of_clk_add_provider()
4967 return -ENOMEM; in of_clk_add_provider()
4969 cp->node = of_node_get(np); in of_clk_add_provider()
4970 cp->data = data; in of_clk_add_provider()
4971 cp->get = clk_src_get; in of_clk_add_provider()
4974 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
4984 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_provider()
4991 * of_clk_add_hw_provider() - Register a clock provider for a node
5009 return -ENOMEM; in of_clk_add_hw_provider()
5011 cp->node = of_node_get(np); in of_clk_add_hw_provider()
5012 cp->data = data; in of_clk_add_hw_provider()
5013 cp->get_hw = get; in of_clk_add_hw_provider()
5016 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
5026 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_hw_provider()
5038 * We allow a child device to use its parent device as the clock provider node
5039 * for cases like MFD sub-devices where the child device driver wants to use
5040 * devm_*() APIs but not list the device in DT as a sub-node.
5046 np = dev->of_node; in get_clk_provider_node()
5047 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
5049 if (!of_property_present(np, "#clock-cells")) in get_clk_provider_node()
5050 if (of_property_present(parent_np, "#clock-cells")) in get_clk_provider_node()
5057 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
5063 * node or if the device node lacks of clock provider information (#clock-cells)
5064 * then the parent device's node is scanned for this information. If parent node
5065 * has the #clock-cells then it is used in registration. Provider is
5081 return -ENOMEM; in devm_of_clk_add_hw_provider()
5097 * of_clk_del_provider() - Remove a previously registered clock provider
5109 if (cp->node == np) { in of_clk_del_provider()
5110 list_del(&cp->link); in of_clk_del_provider()
5111 fwnode_dev_initialized(&np->fwnode, false); in of_clk_del_provider()
5112 of_node_put(cp->node); in of_clk_del_provider()
5122 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
5128 * Parses a device node's "clocks" and "clock-names" properties to find the
5131 * parsing error. The @index argument is ignored if @name is non-NULL.
5135 * phandle1: clock-controller@1 {
5136 * #clock-cells = <2>;
5139 * phandle2: clock-controller@2 {
5140 * #clock-cells = <1>;
5143 * clock-consumer@3 {
5145 * clock-names = "name1", "name2";
5148 * To get a device_node for `clock-controller@2' node you may call this
5151 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
5152 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
5153 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
5155 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
5156 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
5157 * the "clock-names" property of @np.
5162 int ret = -ENOENT; in of_parse_clkspec()
5168 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
5170 * return -EINVAL. in of_parse_clkspec()
5173 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
5174 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
5182 * No matching clock found on this node. If the parent node in of_parse_clkspec()
5183 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
5186 np = np->parent; in of_parse_clkspec()
5187 if (np && !of_get_property(np, "clock-ranges", NULL)) in of_parse_clkspec()
5199 struct clk *clk; in __of_clk_get_hw_from_provider() local
5201 if (provider->get_hw) in __of_clk_get_hw_from_provider()
5202 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5204 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5205 if (IS_ERR(clk)) in __of_clk_get_hw_from_provider()
5206 return ERR_CAST(clk); in __of_clk_get_hw_from_provider()
5207 return __clk_get_hw(clk); in __of_clk_get_hw_from_provider()
5214 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
5217 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
5221 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
5233 * of_clk_get_from_provider() - Lookup a clock from a clock provider
5236 * This function looks up a struct clk from the registered list of clock
5240 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) in of_clk_get_from_provider()
5265 static struct clk *__of_clk_get(struct device_node *np, in __of_clk_get()
5274 struct clk *of_clk_get(struct device_node *np, int index) in of_clk_get()
5276 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
5281 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
5285 * This function parses the clocks and clock-names properties,
5286 * and uses them to look up the struct clk from the registered list of clock
5289 struct clk *of_clk_get_by_name(struct device_node *np, const char *name) in of_clk_get_by_name()
5292 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
5294 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
5299 * of_clk_get_parent_count() - Count the number of clocks a device node has
5308 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
5324 struct clk *clk; in of_clk_get_parent_name() local
5326 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
5335 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
5337 of_property_for_each_u32(clkspec.np, "clock-indices", pv) { in of_clk_get_parent_name()
5345 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
5346 if (of_property_present(clkspec.np, "clock-indices") && !found) { in of_clk_get_parent_name()
5351 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
5358 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
5360 clk = of_clk_get_from_provider(&clkspec); in of_clk_get_parent_name()
5361 if (IS_ERR(clk)) { in of_clk_get_parent_name()
5363 clk_name = clkspec.np->name; in of_clk_get_parent_name()
5367 clk_name = __clk_get_name(clk); in of_clk_get_parent_name()
5368 clk_put(clk); in of_clk_get_parent_name()
5379 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
5406 * This function looks for a parent clock. If there is one, then it
5407 * checks that the provider for this parent clock was initialized, in
5408 * this case the parent clock will be ready.
5415 struct clk *clk = of_clk_get(np, i); in parent_ready() local
5417 /* this parent is ready we can check the next one */ in parent_ready()
5418 if (!IS_ERR(clk)) { in parent_ready()
5419 clk_put(clk); in parent_ready()
5424 /* at least one parent is not ready, we exit now */ in parent_ready()
5425 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
5431 * no more parent. As we didn't exit yet, then the in parent_ready()
5432 * previous parent are ready. If there is no clock in parent_ready()
5433 * parent, no need to wait for them, then we can in parent_ready()
5441 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
5444 * @flags: pointer to top-level framework flags
5446 * Detects if the clock-critical property exists and, if so, sets the
5450 * bindings, such as the one-clock-per-node style that are outdated.
5464 return -EINVAL; in of_clk_detect_critical()
5466 of_property_for_each_u32(np, "clock-critical", idx) in of_clk_detect_critical()
5474 * of_clk_init() - Scan and init clock providers from the DT
5495 struct clock_provider *parent; in of_clk_init() local
5500 parent = kzalloc(sizeof(*parent), GFP_KERNEL); in of_clk_init()
5501 if (!parent) { in of_clk_init()
5504 list_del(&clk_provider->node); in of_clk_init()
5505 of_node_put(clk_provider->np); in of_clk_init()
5512 parent->clk_init_cb = match->data; in of_clk_init()
5513 parent->np = of_node_get(np); in of_clk_init()
5514 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5521 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5524 of_node_set_flag(clk_provider->np, in of_clk_init()
5527 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5528 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5530 list_del(&clk_provider->node); in of_clk_init()
5531 of_node_put(clk_provider->np); in of_clk_init()
5541 * in case the clock parent was not mandatory in of_clk_init()