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/clk-conf.h>
11 #include <linux/clk.h>
12 #include <linux/clk-provider.h>
28 #include "clk.h"
74 struct clk_core *parent; member
107 #include <trace/events/clk.h>
109 struct clk { struct
123 if (!core->rpm_enabled) in clk_pm_runtime_get()
126 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
131 if (!core->rpm_enabled) in clk_pm_runtime_put()
134 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
138 * clk_pm_runtime_get_all() - Runtime "get" all clk provider devices argument
140 * Call clk_pm_runtime_get() on all runtime PM enabled clks in the clk tree so
172 pr_err("clk: Failed to runtime PM get '%s' for clk '%s'\n", in clk_pm_runtime_get_all()
173 dev_name(failed->dev), failed->name); in clk_pm_runtime_get_all()
193 * clk_pm_runtime_put_all() - Runtime "put" all clk provider devices
209 struct device *dev = core->dev; in clk_pm_runtime_init()
212 core->rpm_enabled = true; in clk_pm_runtime_init()
215 hlist_add_head(&core->rpm_node, &clk_rpm_list); in clk_pm_runtime_init()
241 if (--prepare_refcnt) in clk_prepare_unlock()
281 if (--enable_refcnt) { in clk_enable_unlock()
291 return core->protect_count; in clk_core_rate_is_protected()
302 if (!core->ops->is_prepared) in clk_core_is_prepared()
303 return core->prepare_count; in clk_core_is_prepared()
306 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
321 if (!core->ops->is_enabled) in clk_core_is_enabled()
322 return core->enable_count; in clk_core_is_enabled()
334 if (core->rpm_enabled) { in clk_core_is_enabled()
335 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
336 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
344 * context. If the parent isn't enabled already, we can't do in clk_core_is_enabled()
347 if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) in clk_core_is_enabled()
348 if (!clk_core_is_enabled(core->parent)) { in clk_core_is_enabled()
353 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
355 if (core->rpm_enabled) in clk_core_is_enabled()
356 pm_runtime_put(core->dev); in clk_core_is_enabled()
363 const char *__clk_get_name(const struct clk *clk) in __clk_get_name() argument
365 return !clk ? NULL : clk->core->name; in __clk_get_name()
371 return hw->core->name; in clk_hw_get_name()
377 return hw->core->dev; in clk_hw_get_dev()
383 return hw->core->of_node; in clk_hw_get_of_node()
387 struct clk_hw *__clk_get_hw(struct clk *clk) in __clk_get_hw() argument
389 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
395 return hw->core->num_parents; in clk_hw_get_num_parents()
401 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
417 if (!strcmp(core->name, name)) in clk_core_lookup()
433 return -ENOENT; in of_parse_clkspec()
438 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
443 * clk_core_get - Find the clk_core parent of a clk
444 * @core: clk to find parent of
445 * @p_index: parent index to search for
447 * This is the preferred method for clk providers to find the parent of a
448 * clk when that parent is external to the clk controller. The parent_names
450 * node's 'clock-names' property or as the 'con_id' matching the device's
451 * dev_name() in a clk_lookup. This allows clk providers to use their own
452 * namespace instead of looking for a globally unique parent string.
455 * clock-controller@c001 that has a clk_init_data::parent_data array
457 * clock-controller@f00abcd without needing to get the globally unique name of
458 * the xtal clk.
460 * parent: clock-controller@f00abcd {
462 * #clock-cells = <0>;
465 * clock-controller@c001 {
467 * clocks = <&parent>;
468 * clock-names = "xtal";
469 * #clock-cells = <1>;
472 * Returns: -ENOENT when the provider can't be found or the clk doesn't
474 * in a clkdev lookup. NULL when the provider knows about the clk but it
476 * A valid clk_core pointer when the clk can be found in the provider.
480 const char *name = core->parents[p_index].fw_name; in clk_core_get()
481 int index = core->parents[p_index].index; in clk_core_get()
482 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
483 struct device *dev = core->dev; in clk_core_get()
485 struct device_node *np = core->of_node; in clk_core_get()
506 return hw->core; in clk_core_get()
511 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
512 struct clk_core *parent; in clk_core_fill_parent_index() local
514 if (entry->hw) { in clk_core_fill_parent_index()
515 parent = entry->hw->core; in clk_core_fill_parent_index()
517 parent = clk_core_get(core, index); in clk_core_fill_parent_index()
518 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
519 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
525 * when the parent is registered. in clk_core_fill_parent_index()
527 if (!parent) in clk_core_fill_parent_index()
528 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
531 if (!IS_ERR(parent)) in clk_core_fill_parent_index()
532 entry->core = parent; in clk_core_fill_parent_index()
538 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
541 if (!core->parents[index].core) in clk_core_get_parent_by_index()
544 return core->parents[index].core; in clk_core_get_parent_by_index()
550 struct clk_core *parent; in clk_hw_get_parent_by_index() local
552 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
554 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
558 unsigned int __clk_get_enable_count(struct clk *clk) in __clk_get_enable_count() argument
560 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
568 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
569 return core->rate; in clk_core_get_rate_nolock()
572 * Clk must have a parent because num_parents > 0 but the parent isn't in clk_core_get_rate_nolock()
573 * known yet. Best to return 0 as the rate of this clk until we can in clk_core_get_rate_nolock()
574 * properly recalc the rate based on the parent's rate. in clk_core_get_rate_nolock()
581 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
590 return core->accuracy; in clk_core_get_accuracy_no_lock()
595 return hw->core->flags; in clk_hw_get_flags()
601 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
607 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
611 bool __clk_is_enabled(struct clk *clk) in __clk_is_enabled() argument
613 if (!clk) in __clk_is_enabled()
616 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
624 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
636 static bool clk_core_has_parent(struct clk_core *core, const struct clk_core *parent) in clk_core_has_parent() argument
641 /* Optimize for the case where the parent is already the parent. */ in clk_core_has_parent()
642 if (core->parent == parent) in clk_core_has_parent()
645 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
650 if (tmp == parent) in clk_core_has_parent()
660 struct clk_core *parent, in clk_core_forward_rate_req() argument
664 if (WARN_ON(!clk_core_has_parent(core, parent))) in clk_core_forward_rate_req()
667 clk_core_init_rate_req(parent, req, parent_rate); in clk_core_forward_rate_req()
669 if (req->min_rate < old_req->min_rate) in clk_core_forward_rate_req()
670 req->min_rate = old_req->min_rate; in clk_core_forward_rate_req()
672 if (req->max_rate > old_req->max_rate) in clk_core_forward_rate_req()
673 req->max_rate = old_req->max_rate; in clk_core_forward_rate_req()
680 struct clk_core *core = hw->core; in clk_core_determine_rate_no_reparent()
681 struct clk_core *parent = core->parent; in clk_core_determine_rate_no_reparent() local
685 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_determine_rate_no_reparent()
688 if (!parent) { in clk_core_determine_rate_no_reparent()
689 req->rate = 0; in clk_core_determine_rate_no_reparent()
693 clk_core_forward_rate_req(core, req, parent, &parent_req, in clk_core_determine_rate_no_reparent()
694 req->rate); in clk_core_determine_rate_no_reparent()
698 ret = clk_core_round_rate_nolock(parent, &parent_req); in clk_core_determine_rate_no_reparent()
705 } else if (parent) { in clk_core_determine_rate_no_reparent()
706 best = clk_core_get_rate_nolock(parent); in clk_core_determine_rate_no_reparent()
711 req->best_parent_rate = best; in clk_core_determine_rate_no_reparent()
712 req->rate = best; in clk_core_determine_rate_no_reparent()
721 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
725 /* if NO_REPARENT flag set, pass through to current parent */ in clk_mux_determine_rate_flags()
726 if (core->flags & CLK_SET_RATE_NO_REPARENT) in clk_mux_determine_rate_flags()
729 /* find the parent that can provide the fastest rate <= rate */ in clk_mux_determine_rate_flags()
730 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
734 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
735 if (!parent) in clk_mux_determine_rate_flags()
738 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
741 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
745 ret = clk_core_round_rate_nolock(parent, &parent_req); in clk_mux_determine_rate_flags()
753 parent_rate = clk_core_get_rate_nolock(parent); in clk_mux_determine_rate_flags()
756 if (mux_is_better_rate(req->rate, parent_rate, in clk_mux_determine_rate_flags()
758 best_parent = parent; in clk_mux_determine_rate_flags()
764 return -EINVAL; in clk_mux_determine_rate_flags()
766 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
767 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
768 req->rate = best; in clk_mux_determine_rate_flags()
774 struct clk *__clk_lookup(const char *name) in __clk_lookup()
778 return !core ? NULL : core->hw->clk; in __clk_lookup()
785 struct clk *clk_user; in clk_core_get_boundaries()
789 *min_rate = core->min_rate; in clk_core_get_boundaries()
790 *max_rate = core->max_rate; in clk_core_get_boundaries()
792 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
793 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
795 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
796 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
800 * clk_hw_get_rate_range() - returns the clock rate range for a hw clk
801 * @hw: the hw clk we want to get the range from
811 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
819 struct clk *user; in clk_core_check_boundaries()
823 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
826 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
827 if (min_rate > user->max_rate || max_rate < user->min_rate) in clk_core_check_boundaries()
836 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
837 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
842 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
843 * @hw: mux type clk to determine rate on
844 * @req: rate request, also used to return preferred parent and frequencies
846 * Helper for finding best parent to provide a given frequency. This can be used
850 * Returns: 0 on success, -EERROR value on error
867 …* clk_hw_determine_rate_no_reparent - clk_ops::determine_rate implementation for a clk that doesn'…
868 * @hw: mux type clk to determine rate on
871 * Helper for finding best parent rate to provide a given frequency.
876 * Returns: 0 on success, -EERROR value on error
885 /*** clk api ***/
894 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
895 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
898 if (--core->protect_count > 0) in clk_core_rate_unprotect()
901 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
911 return -EINVAL; in clk_core_rate_nuke_protect()
913 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
916 ret = core->protect_count; in clk_core_rate_nuke_protect()
917 core->protect_count = 1; in clk_core_rate_nuke_protect()
924 * clk_rate_exclusive_put - release exclusivity over clock rate control
925 * @clk: the clk over which the exclusivity is released
931 * further up the parent chain of clocks. As a result, clocks up parent chain
941 void clk_rate_exclusive_put(struct clk *clk) in clk_rate_exclusive_put() argument
943 if (!clk) in clk_rate_exclusive_put()
952 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
955 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
956 clk->exclusive_count--; in clk_rate_exclusive_put()
969 if (core->protect_count == 0) in clk_core_rate_protect()
970 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
972 core->protect_count++; in clk_core_rate_protect()
986 core->protect_count = count; in clk_core_rate_restore_protect()
990 * clk_rate_exclusive_get - get exclusivity over the clk rate control
991 * @clk: the clk over which the exclusity of rate control is requested
997 * further up the parent chain of clocks. As a result, clocks up parent chain
1005 * Returns 0 on success, -EERROR otherwise
1007 int clk_rate_exclusive_get(struct clk *clk) in clk_rate_exclusive_get() argument
1009 if (!clk) in clk_rate_exclusive_get()
1013 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
1014 clk->exclusive_count++; in clk_rate_exclusive_get()
1023 struct clk *clk = data; in devm_clk_rate_exclusive_put() local
1025 clk_rate_exclusive_put(clk); in devm_clk_rate_exclusive_put()
1028 int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk) in devm_clk_rate_exclusive_get() argument
1032 ret = clk_rate_exclusive_get(clk); in devm_clk_rate_exclusive_get()
1036 return devm_add_action_or_reset(dev, devm_clk_rate_exclusive_put, clk); in devm_clk_rate_exclusive_get()
1047 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
1048 "%s already unprepared\n", core->name)) in clk_core_unprepare()
1051 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
1052 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
1055 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
1058 if (--core->prepare_count > 0) in clk_core_unprepare()
1061 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
1065 if (core->ops->unprepare) in clk_core_unprepare()
1066 core->ops->unprepare(core->hw); in clk_core_unprepare()
1069 clk_core_unprepare(core->parent); in clk_core_unprepare()
1081 * clk_unprepare - undo preparation of a clock source
1082 * @clk: the clk being unprepared
1085 * simple case, clk_unprepare can be used instead of clk_disable to gate a clk
1086 * if the operation may sleep. One example is a clk which is accessed over
1087 * I2c. In the complex case a clk gate operation may require a fast and a slow
1091 void clk_unprepare(struct clk *clk) in clk_unprepare() argument
1093 if (IS_ERR_OR_NULL(clk)) in clk_unprepare()
1096 clk_core_unprepare_lock(clk->core); in clk_unprepare()
1109 if (core->prepare_count == 0) { in clk_core_prepare()
1114 ret = clk_core_prepare(core->parent); in clk_core_prepare()
1120 if (core->ops->prepare) in clk_core_prepare()
1121 ret = core->ops->prepare(core->hw); in clk_core_prepare()
1129 core->prepare_count++; in clk_core_prepare()
1138 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1143 clk_core_unprepare(core->parent); in clk_core_prepare()
1161 * clk_prepare - prepare a clock source
1162 * @clk: the clk being prepared
1165 * case, clk_prepare can be used instead of clk_enable to ungate a clk if the
1166 * operation may sleep. One example is a clk which is accessed over I2c. In
1167 * the complex case a clk ungate operation may require a fast and a slow part.
1170 * Returns 0 on success, -EERROR otherwise.
1172 int clk_prepare(struct clk *clk) in clk_prepare() argument
1174 if (!clk) in clk_prepare()
1177 return clk_core_prepare_lock(clk->core); in clk_prepare()
1188 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1191 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1192 "Disabling critical %s\n", core->name)) in clk_core_disable()
1195 if (--core->enable_count > 0) in clk_core_disable()
1200 if (core->ops->disable) in clk_core_disable()
1201 core->ops->disable(core->hw); in clk_core_disable()
1205 clk_core_disable(core->parent); in clk_core_disable()
1218 * clk_disable - gate a clock
1219 * @clk: the clk being gated
1223 * clk if the operation is fast and will never sleep. One example is a
1224 * SoC-internal clk which is controlled via simple register writes. In the
1225 * complex case a clk gate operation may require a fast and a slow part. It is
1229 void clk_disable(struct clk *clk) in clk_disable() argument
1231 if (IS_ERR_OR_NULL(clk)) in clk_disable()
1234 clk_core_disable_lock(clk->core); in clk_disable()
1247 if (WARN(core->prepare_count == 0, in clk_core_enable()
1248 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1249 return -ESHUTDOWN; in clk_core_enable()
1251 if (core->enable_count == 0) { in clk_core_enable()
1252 ret = clk_core_enable(core->parent); in clk_core_enable()
1259 if (core->ops->enable) in clk_core_enable()
1260 ret = core->ops->enable(core->hw); in clk_core_enable()
1265 clk_core_disable(core->parent); in clk_core_enable()
1270 core->enable_count++; in clk_core_enable()
1287 * clk_gate_restore_context - restore context for poweroff
1298 struct clk_core *core = hw->core; in clk_gate_restore_context()
1300 if (core->enable_count) in clk_gate_restore_context()
1301 core->ops->enable(hw); in clk_gate_restore_context()
1303 core->ops->disable(hw); in clk_gate_restore_context()
1312 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1318 if (core->ops && core->ops->save_context) in clk_core_save_context()
1319 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1328 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1329 core->ops->restore_context(core->hw); in clk_core_restore_context()
1331 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1336 * clk_save_context - save clock context for poweroff
1344 struct clk_core *clk; in clk_save_context() local
1347 hlist_for_each_entry(clk, &clk_root_list, child_node) { in clk_save_context()
1348 ret = clk_core_save_context(clk); in clk_save_context()
1353 hlist_for_each_entry(clk, &clk_orphan_list, child_node) { in clk_save_context()
1354 ret = clk_core_save_context(clk); in clk_save_context()
1364 * clk_restore_context - restore clock context after poweroff
1382 * clk_enable - ungate a clock
1383 * @clk: the clk being ungated
1386 * simple case, clk_enable can be used instead of clk_prepare to ungate a clk
1387 * if the operation will never sleep. One example is a SoC-internal clk which
1388 * is controlled via simple register writes. In the complex case a clk ungate
1391 * must be called before clk_enable. Returns 0 on success, -EERROR
1394 int clk_enable(struct clk *clk) in clk_enable() argument
1396 if (!clk) in clk_enable()
1399 return clk_core_enable_lock(clk->core); in clk_enable()
1404 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
1405 * @clk: clock source
1408 * making clk_enable()/clk_disable() no-ops, false otherwise.
1418 bool clk_is_enabled_when_prepared(struct clk *clk) in clk_is_enabled_when_prepared() argument
1420 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1451 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1454 if (core->prepare_count) in clk_unprepare_unused_subtree()
1457 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1462 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1463 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1464 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1465 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1477 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1480 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1481 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1485 if (core->enable_count) in clk_disable_unused_subtree()
1488 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1492 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1498 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1499 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1500 else if (core->ops->disable) in clk_disable_unused_subtree()
1501 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1507 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1508 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1525 pr_warn("clk: Not disabling unused clocks\n"); in clk_disable_unused()
1529 pr_info("clk: Disabling unused clocks\n"); in clk_disable_unused()
1535 * Grab the prepare lock to keep the clk topology stable while iterating in clk_disable_unused()
1571 * Some clock providers hand-craft their clk_rate_requests and in clk_core_determine_round_nolock()
1578 if (!req->min_rate && !req->max_rate) in clk_core_determine_round_nolock()
1580 __func__, core->name); in clk_core_determine_round_nolock()
1582 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in clk_core_determine_round_nolock()
1586 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1587 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1591 req->rate = core->rate; in clk_core_determine_round_nolock()
1592 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1593 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1594 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1595 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1596 &req->best_parent_rate); in clk_core_determine_round_nolock()
1600 req->rate = rate; in clk_core_determine_round_nolock()
1602 return -EINVAL; in clk_core_determine_round_nolock()
1612 struct clk_core *parent; in clk_core_init_rate_req() local
1618 req->max_rate = ULONG_MAX; in clk_core_init_rate_req()
1623 req->core = core; in clk_core_init_rate_req()
1624 req->rate = rate; in clk_core_init_rate_req()
1625 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1627 parent = core->parent; in clk_core_init_rate_req()
1628 if (parent) { in clk_core_init_rate_req()
1629 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1630 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1632 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1633 req->best_parent_rate = 0; in clk_core_init_rate_req()
1638 * clk_hw_init_rate_request - Initializes a clk_rate_request
1639 * @hw: the clk for which we want to submit a rate request
1653 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1658 * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent
1661 * @parent: the clk we want to forward @old_req to
1663 * @parent_rate: The rate which is to be requested to @parent
1665 * Initializes a clk_rate_request structure to submit to a clock parent
1670 const struct clk_hw *parent, in clk_hw_forward_rate_request() argument
1674 if (WARN_ON(!hw || !old_req || !parent || !req)) in clk_hw_forward_rate_request()
1677 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1678 parent->core, req, in clk_hw_forward_rate_request()
1685 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1696 req->rate = 0; in clk_core_round_rate_nolock()
1703 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1706 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1710 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1716 req->best_parent_rate = parent_req.rate; in clk_core_round_rate_nolock()
1717 req->rate = parent_req.rate; in clk_core_round_rate_nolock()
1722 req->rate = core->rate; in clk_core_round_rate_nolock()
1727 * __clk_determine_rate - get the closest rate actually supported by a clock
1736 req->rate = 0; in __clk_determine_rate()
1740 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1745 * clk_hw_round_rate() - round the given rate for a hw clk
1746 * @hw: the hw clk for which we are rounding a rate
1749 * Takes in a rate as input and rounds it to a rate that the clk can actually
1753 * For clk providers to call from within clk_ops such as .round_rate,
1756 * Return: returns rounded rate of hw clk if clk supports round_rate operation
1757 * else returns the parent rate.
1764 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1768 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1779 * clk_round_rate - round the given rate for a clk
1780 * @clk: the clk for which we are rounding a rate
1783 * Takes in a rate as input and rounds it to a rate that the clk can actually
1784 * use which is then returned. If clk doesn't support round_rate operation
1785 * then the parent rate is returned.
1787 long clk_round_rate(struct clk *clk, unsigned long rate) in clk_round_rate() argument
1792 if (!clk) in clk_round_rate()
1797 if (clk->exclusive_count) in clk_round_rate()
1798 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1800 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1804 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1808 if (clk->exclusive_count) in clk_round_rate()
1809 clk_core_rate_protect(clk->core); in clk_round_rate()
1821 * __clk_notify - call clk notifier chain
1822 * @core: clk that is changing rate
1823 * @msg: clk notifier type (see include/linux/clk.h)
1824 * @old_rate: old clk rate
1825 * @new_rate: new clk rate
1827 * Triggers a notifier call chain on the clk rate-change notification
1828 * for 'clk'. Passes a pointer to the struct clk and the previous
1845 if (cn->clk->core == core) { in __clk_notify()
1846 cnd.clk = cn->clk; in __clk_notify()
1847 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1859 * @core: first clk in the subtree
1861 * Walks the subtree of clks starting with clk and recalculates accuracies as
1862 * it goes. Note that if a clk does not implement the .recalc_accuracy
1864 * parent.
1873 if (core->parent) in __clk_recalc_accuracies()
1874 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1876 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1877 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1880 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1882 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1888 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1895 * clk_get_accuracy - return the accuracy of clk
1896 * @clk: the clk whose accuracy is being returned
1898 * Simply returns the cached accuracy of the clk, unless
1901 * If clk is NULL then returns 0.
1903 long clk_get_accuracy(struct clk *clk) in clk_get_accuracy() argument
1907 if (!clk) in clk_get_accuracy()
1911 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1923 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1924 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1932 * @core: first clk in the subtree
1934 * @msg: notification type (see include/linux/clk.h)
1936 * Walks the subtree of clks starting with clk and recalculates rates as it
1937 * goes. Note that if a clk does not implement the .recalc_rate callback then
1938 * it is assumed that the clock will take on the rate of its parent.
1952 old_rate = core->rate; in __clk_recalc_rates()
1954 if (core->parent) in __clk_recalc_rates()
1955 parent_rate = core->parent->rate; in __clk_recalc_rates()
1957 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1959 core->req_rate = core->rate; in __clk_recalc_rates()
1965 if (core->notifier_count && msg) in __clk_recalc_rates()
1966 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1968 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1974 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1981 * clk_get_rate - return the rate of clk
1982 * @clk: the clk whose rate is being returned
1984 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1986 * the clock enabledness. If clk is NULL, or if an error occurred, then returns
1989 unsigned long clk_get_rate(struct clk *clk) in clk_get_rate() argument
1993 if (!clk) in clk_get_rate()
1997 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
2005 struct clk_core *parent) in clk_fetch_parent_index() argument
2009 if (!parent) in clk_fetch_parent_index()
2010 return -EINVAL; in clk_fetch_parent_index()
2012 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
2014 if (core->parents[i].core == parent) in clk_fetch_parent_index()
2018 if (core->parents[i].core) in clk_fetch_parent_index()
2022 if (core->parents[i].hw) { in clk_fetch_parent_index()
2023 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
2031 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
2035 if (core->parents[i].name && in clk_fetch_parent_index()
2036 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
2040 if (i == core->num_parents) in clk_fetch_parent_index()
2041 return -EINVAL; in clk_fetch_parent_index()
2043 core->parents[i].core = parent; in clk_fetch_parent_index()
2048 * clk_hw_get_parent_index - return the index of the parent clock
2049 * @hw: clk_hw associated with the clk being consumed
2051 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
2052 * clock does not have a current parent.
2056 struct clk_hw *parent = clk_hw_get_parent(hw); in clk_hw_get_parent_index() local
2058 if (WARN_ON(parent == NULL)) in clk_hw_get_parent_index()
2059 return -EINVAL; in clk_hw_get_parent_index()
2061 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
2072 core->orphan = is_orphan; in clk_core_update_orphan_status()
2074 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
2080 bool was_orphan = core->orphan; in clk_reparent()
2082 hlist_del(&core->child_node); in clk_reparent()
2085 bool becomes_orphan = new_parent->orphan; in clk_reparent()
2088 if (new_parent->new_child == core) in clk_reparent()
2089 new_parent->new_child = NULL; in clk_reparent()
2091 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
2096 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
2101 core->parent = new_parent; in clk_reparent()
2105 struct clk_core *parent) in __clk_set_parent_before() argument
2108 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
2122 * parent and also protect against a race with clk_enable() by in __clk_set_parent_before()
2123 * forcing the clock and the new parent on. This ensures that all in __clk_set_parent_before()
2130 /* enable old_parent & parent if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_before()
2131 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2133 clk_core_prepare_enable(parent); in __clk_set_parent_before()
2137 if (core->prepare_count) { in __clk_set_parent_before()
2138 clk_core_prepare_enable(parent); in __clk_set_parent_before()
2142 /* update the clk tree topology */ in __clk_set_parent_before()
2144 clk_reparent(core, parent); in __clk_set_parent_before()
2151 struct clk_core *parent, in __clk_set_parent_after() argument
2158 if (core->prepare_count) { in __clk_set_parent_after()
2163 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
2164 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2165 clk_core_disable_unprepare(parent); in __clk_set_parent_after()
2170 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
2177 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
2179 trace_clk_set_parent(core, parent); in __clk_set_parent()
2182 if (parent && core->ops->set_parent) in __clk_set_parent()
2183 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2185 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
2192 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
2197 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
2204 * @core: first clk in the subtree
2205 * @parent_rate: the "future" rate of clk's parent
2207 * Walks the subtree of clks starting with clk, speculating rates as it
2211 * pre-rate change notifications and returns early if no clks in the
2212 * subtree have subscribed to the notifications. Note that if a clk does not
2214 * take on the rate of its parent.
2228 if (core->notifier_count) in __clk_speculate_rates()
2229 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2232 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
2233 __func__, core->name, ret); in __clk_speculate_rates()
2237 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2252 core->new_rate = new_rate; in clk_calc_subtree()
2253 core->new_parent = new_parent; in clk_calc_subtree()
2254 core->new_parent_index = p_index; in clk_calc_subtree()
2255 /* include clk in new parent's PRE_RATE_CHANGE notifications */ in clk_calc_subtree()
2256 core->new_child = NULL; in clk_calc_subtree()
2257 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2258 new_parent->new_child = core; in clk_calc_subtree()
2260 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2261 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
2262 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
2274 struct clk_core *old_parent, *parent; in clk_calc_new_rates() local
2286 /* save parent rate, if it exists */ in clk_calc_new_rates()
2287 parent = old_parent = core->parent; in clk_calc_new_rates()
2288 if (parent) in clk_calc_new_rates()
2289 best_parent_rate = parent->rate; in clk_calc_new_rates()
2293 /* find the closest rate and parent clk/rate */ in clk_calc_new_rates()
2309 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2313 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2314 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
2315 core->new_rate = core->rate; in clk_calc_new_rates()
2318 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
2319 top = clk_calc_new_rates(parent, rate); in clk_calc_new_rates()
2320 new_rate = parent->new_rate; in clk_calc_new_rates()
2324 /* some clocks must be gated to change parent */ in clk_calc_new_rates()
2325 if (parent != old_parent && in clk_calc_new_rates()
2326 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2328 __func__, core->name); in clk_calc_new_rates()
2332 /* try finding the new parent index */ in clk_calc_new_rates()
2333 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2334 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
2336 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_calc_new_rates()
2337 __func__, parent->name, core->name); in clk_calc_new_rates()
2342 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2343 best_parent_rate != parent->rate) in clk_calc_new_rates()
2344 top = clk_calc_new_rates(parent, best_parent_rate); in clk_calc_new_rates()
2347 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
2363 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2366 if (core->notifier_count) { in clk_propagate_rate_change()
2367 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2372 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2374 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2381 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2382 if (core->new_child) { in clk_propagate_rate_change()
2383 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2403 struct clk_core *parent = NULL; in clk_change_rate() local
2405 old_rate = core->rate; in clk_change_rate()
2407 if (core->new_parent) { in clk_change_rate()
2408 parent = core->new_parent; in clk_change_rate()
2409 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2410 } else if (core->parent) { in clk_change_rate()
2411 parent = core->parent; in clk_change_rate()
2412 best_parent_rate = core->parent->rate; in clk_change_rate()
2418 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2423 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2424 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2425 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2427 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2429 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2431 core->new_parent_index); in clk_change_rate()
2432 } else if (core->ops->set_parent) { in clk_change_rate()
2433 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2436 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2437 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2440 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2441 clk_core_prepare_enable(parent); in clk_change_rate()
2443 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2445 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2446 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2448 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2450 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2452 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2457 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2458 clk_core_disable_unprepare(parent); in clk_change_rate()
2460 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2461 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2463 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2464 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2470 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2472 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2477 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2478 if (core->new_child) in clk_change_rate()
2479 clk_change_rate(core->new_child); in clk_change_rate()
2532 return -EBUSY; in clk_core_set_rate_nolock()
2537 return -EINVAL; in clk_core_set_rate_nolock()
2547 fail_clk->name); in clk_core_set_rate_nolock()
2549 ret = -EBUSY; in clk_core_set_rate_nolock()
2556 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2564 * clk_set_rate - specify a new rate for clk
2565 * @clk: the clk whose rate is being changed
2566 * @rate: the new rate for clk
2568 * In the simplest case clk_set_rate will only adjust the rate of clk.
2571 * propagate up to clk's parent; whether or not this happens depends on the
2572 * outcome of clk's .round_rate implementation. If *parent_rate is unchanged
2573 * after calling .round_rate then upstream parent propagation is ignored. If
2574 * *parent_rate comes back with a new rate for clk's parent then we propagate
2575 * up to clk's parent and set its rate. Upward propagation will continue
2576 * until either a clk does not support the CLK_SET_RATE_PARENT flag or
2577 * .round_rate stops requesting changes to clk's parent_rate.
2582 * Returns 0 on success, -EERROR otherwise.
2584 int clk_set_rate(struct clk *clk, unsigned long rate) in clk_set_rate() argument
2588 if (!clk) in clk_set_rate()
2594 if (clk->exclusive_count) in clk_set_rate()
2595 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2597 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2599 if (clk->exclusive_count) in clk_set_rate()
2600 clk_core_rate_protect(clk->core); in clk_set_rate()
2609 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2610 * @clk: the clk whose rate is being changed
2611 * @rate: the new rate for clk
2625 * Returns 0 on success, -EERROR otherwise.
2627 int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) in clk_set_rate_exclusive() argument
2631 if (!clk) in clk_set_rate_exclusive()
2643 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2645 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2646 clk->exclusive_count++; in clk_set_rate_exclusive()
2655 static int clk_set_rate_range_nolock(struct clk *clk, in clk_set_rate_range_nolock() argument
2664 if (!clk) in clk_set_rate_range_nolock()
2667 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2670 pr_err("%s: clk %s dev %s con %s: invalid range [%lu, %lu]\n", in clk_set_rate_range_nolock()
2671 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2673 return -EINVAL; in clk_set_rate_range_nolock()
2676 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2677 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2680 old_min = clk->min_rate; in clk_set_rate_range_nolock()
2681 old_max = clk->max_rate; in clk_set_rate_range_nolock()
2682 clk->min_rate = min; in clk_set_rate_range_nolock()
2683 clk->max_rate = max; in clk_set_rate_range_nolock()
2685 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2686 ret = -EINVAL; in clk_set_rate_range_nolock()
2690 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2691 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2692 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2706 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range_nolock()
2708 * - the determine_rate() callback does not really check for in clk_set_rate_range_nolock()
2712 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2715 clk->min_rate = old_min; in clk_set_rate_range_nolock()
2716 clk->max_rate = old_max; in clk_set_rate_range_nolock()
2720 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2721 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2727 * clk_set_rate_range - set a rate range for a clock source
2728 * @clk: clock source
2734 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) in clk_set_rate_range() argument
2738 if (!clk) in clk_set_rate_range()
2743 ret = clk_set_rate_range_nolock(clk, min, max); in clk_set_rate_range()
2752 * clk_set_min_rate - set a minimum clock rate for a clock source
2753 * @clk: clock source
2758 int clk_set_min_rate(struct clk *clk, unsigned long rate) in clk_set_min_rate() argument
2760 if (!clk) in clk_set_min_rate()
2763 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2765 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2770 * clk_set_max_rate - set a maximum clock rate for a clock source
2771 * @clk: clock source
2776 int clk_set_max_rate(struct clk *clk, unsigned long rate) in clk_set_max_rate() argument
2778 if (!clk) in clk_set_max_rate()
2781 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2783 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2788 * clk_get_parent - return the parent of a clk
2789 * @clk: the clk whose parent gets returned
2791 * Simply returns clk->parent. Returns NULL if clk is NULL.
2793 struct clk *clk_get_parent(struct clk *clk) in clk_get_parent() argument
2795 struct clk *parent; in clk_get_parent() local
2797 if (!clk) in clk_get_parent()
2801 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2802 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2805 return parent; in clk_get_parent()
2813 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2814 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2832 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2836 * clk_has_parent - check if a clock is a possible parent for another
2837 * @clk: clock source
2838 * @parent: parent clock source
2841 * the parent of another without actually changing the parent.
2843 * Returns true if @parent is a possible parent for @clk, false otherwise.
2845 bool clk_has_parent(const struct clk *clk, const struct clk *parent) in clk_has_parent() argument
2848 if (!clk || !parent) in clk_has_parent()
2851 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2856 struct clk_core *parent) in clk_core_set_parent_nolock() argument
2867 if (core->parent == parent) in clk_core_set_parent_nolock()
2870 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2871 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2872 return -EPERM; in clk_core_set_parent_nolock()
2874 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2875 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2876 return -EBUSY; in clk_core_set_parent_nolock()
2879 return -EBUSY; in clk_core_set_parent_nolock()
2881 /* try finding the new parent index */ in clk_core_set_parent_nolock()
2882 if (parent) { in clk_core_set_parent_nolock()
2883 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2885 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_core_set_parent_nolock()
2886 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2889 p_rate = parent->rate; in clk_core_set_parent_nolock()
2903 /* do the re-parent */ in clk_core_set_parent_nolock()
2904 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2920 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *parent) in clk_hw_set_parent() argument
2922 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2927 * clk_set_parent - switch the parent of a mux clk
2928 * @clk: the mux clk whose input we are switching
2929 * @parent: the new input to clk
2931 * Re-parent clk to use parent as its new input source. If clk is in
2932 * prepared state, the clk will get enabled for the duration of this call. If
2933 * that's not acceptable for a specific clk (Eg: the consumer can't handle
2935 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
2937 * After successfully changing clk's parent clk_set_parent will update the
2938 * clk topology, sysfs topology and propagate rate recalculation via
2941 * Returns 0 on success, -EERROR otherwise.
2943 int clk_set_parent(struct clk *clk, struct clk *parent) in clk_set_parent() argument
2947 if (!clk) in clk_set_parent()
2952 if (clk->exclusive_count) in clk_set_parent()
2953 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2955 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2956 parent ? parent->core : NULL); in clk_set_parent()
2958 if (clk->exclusive_count) in clk_set_parent()
2959 clk_core_rate_protect(clk->core); in clk_set_parent()
2969 int ret = -EINVAL; in clk_core_set_phase_nolock()
2977 return -EBUSY; in clk_core_set_phase_nolock()
2981 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2982 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2984 core->phase = degrees; in clk_core_set_phase_nolock()
2993 * clk_set_phase - adjust the phase shift of a clock signal
2994 * @clk: clock signal source
2998 * degrees. Returns 0 on success, -EERROR otherwise.
3002 * phase locked-loop clock signal generators we may shift phase with
3009 * clock accuracy. A parent clock phase attribute does not have an
3012 int clk_set_phase(struct clk *clk, int degrees) in clk_set_phase() argument
3016 if (!clk) in clk_set_phase()
3026 if (clk->exclusive_count) in clk_set_phase()
3027 clk_core_rate_unprotect(clk->core); in clk_set_phase()
3029 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
3031 if (clk->exclusive_count) in clk_set_phase()
3032 clk_core_rate_protect(clk->core); in clk_set_phase()
3045 if (!core->ops->get_phase) in clk_core_get_phase()
3049 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
3051 core->phase = ret; in clk_core_get_phase()
3057 * clk_get_phase - return the phase shift of a clock signal
3058 * @clk: clock signal source
3061 * -EERROR.
3063 int clk_get_phase(struct clk *clk) in clk_get_phase() argument
3067 if (!clk) in clk_get_phase()
3071 ret = clk_core_get_phase(clk->core); in clk_get_phase()
3081 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
3082 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
3089 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
3092 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
3095 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
3100 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
3101 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
3116 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
3117 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
3118 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
3119 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
3138 return -EBUSY; in clk_core_set_duty_cycle_nolock()
3142 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3145 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3147 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3159 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3160 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3161 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3162 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3169 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
3170 * @clk: clock signal source
3179 int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den) in clk_set_duty_cycle() argument
3184 if (!clk) in clk_set_duty_cycle()
3189 return -EINVAL; in clk_set_duty_cycle()
3196 if (clk->exclusive_count) in clk_set_duty_cycle()
3197 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3199 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3201 if (clk->exclusive_count) in clk_set_duty_cycle()
3202 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3213 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3220 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
3228 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
3229 * @clk: clock signal source
3235 int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale) in clk_get_scaled_duty_cycle() argument
3237 if (!clk) in clk_get_scaled_duty_cycle()
3240 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3245 * clk_is_match - check if two clk's point to the same hardware clock
3246 * @p: clk compared against q
3247 * @q: clk compared against p
3249 * Returns true if the two struct clk pointers both point to the same hardware
3250 * clock node. Put differently, returns true if struct clk *p and struct clk *q
3255 bool clk_is_match(const struct clk *p, const struct clk *q) in clk_is_match()
3257 /* trivial case: identical struct clk's or both NULL */ in clk_is_match()
3261 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
3263 if (p->core == q->core) in clk_is_match()
3289 struct clk *clk_user; in clk_summary_show_one()
3292 seq_printf(s, "%*s%-*s %-7d %-8d %-8d %-11lu %-10lu ", in clk_summary_show_one()
3294 35 - level * 3, c->name, in clk_summary_show_one()
3295 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
3301 seq_printf(s, "%-5d", phase); in clk_summary_show_one()
3303 seq_puts(s, "-----"); in clk_summary_show_one()
3305 seq_printf(s, " %-6d", clk_core_get_scaled_duty_cycle(c, 100000)); in clk_summary_show_one()
3307 if (c->ops->is_enabled) in clk_summary_show_one()
3309 else if (!c->ops->enable) in clk_summary_show_one()
3314 hlist_for_each_entry(clk_user, &c->clks, clks_node) { in clk_summary_show_one()
3315 seq_printf(s, "%*s%-*s %-25s\n", in clk_summary_show_one()
3318 clk_user->dev_id ? clk_user->dev_id : "deviceless", in clk_summary_show_one()
3319 clk_user->con_id ? clk_user->con_id : "no_connection_id"); in clk_summary_show_one()
3333 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
3340 struct hlist_head **lists = s->private; in clk_summary_show()
3345 …s(s, "--------------------------------------------------------------------------------------------… in clk_summary_show()
3372 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
3373 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
3374 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
3375 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
3393 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3405 struct hlist_head **lists = s->private; in clk_dump_show()
3475 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3477 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3486 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3518 *val = core->phase; in clk_phase_get()
3546 struct clk_core *core = s->private; in clk_flags_show()
3547 unsigned long flags = core->flags; in clk_flags_show()
3568 struct clk_core *parent; in possible_parent_show() local
3572 * Go through the following options to fetch a parent's name. in possible_parent_show()
3574 * 1. Fetch the registered parent clock and use its name in possible_parent_show()
3577 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3579 * This may still fail in some cases, such as when the parent is in possible_parent_show()
3583 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3584 if (parent) { in possible_parent_show()
3585 seq_puts(s, parent->name); in possible_parent_show()
3586 } else if (core->parents[i].name) { in possible_parent_show()
3587 seq_puts(s, core->parents[i].name); in possible_parent_show()
3588 } else if (core->parents[i].fw_name) { in possible_parent_show()
3589 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3591 if (core->parents[i].index >= 0) in possible_parent_show()
3592 name = of_clk_get_parent_name(core->of_node, core->parents[i].index); in possible_parent_show()
3604 struct clk_core *core = s->private; in possible_parents_show()
3607 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3618 struct clk_core *core = s->private; in current_parent_show()
3620 if (core->parent) in current_parent_show()
3621 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3631 struct seq_file *s = file->private_data; in current_parent_write()
3632 struct clk_core *core = s->private; in current_parent_write()
3633 struct clk_core *parent; in current_parent_write() local
3641 parent = clk_core_get_parent_by_index(core, idx); in current_parent_write()
3642 if (!parent) in current_parent_write()
3643 return -ENOENT; in current_parent_write()
3646 err = clk_core_set_parent_nolock(core, parent); in current_parent_write()
3665 struct clk_core *core = s->private; in clk_duty_cycle_show()
3666 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3668 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3676 struct clk_core *core = s->private; in clk_min_rate_show()
3690 struct clk_core *core = s->private; in clk_max_rate_show()
3709 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3710 core->dentry = root; in clk_debug_create_one()
3716 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3720 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3721 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3722 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3723 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3730 if (core->num_parents > 1) in clk_debug_create_one()
3735 if (core->num_parents > 0) in clk_debug_create_one()
3739 if (core->num_parents > 1) in clk_debug_create_one()
3743 if (core->ops->debug_init) in clk_debug_create_one()
3744 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3748 * clk_debug_register - add a clk node to the debugfs clk directory
3749 * @core: the clk being added to the debugfs clk directory
3751 * Dynamically adds a clk to the debugfs clk directory if debugfs has been
3752 * initialized. Otherwise it bails out early since the debugfs clk directory
3758 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3765 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3766 * @core: the clk being removed from the debugfs clk directory
3768 * Dynamically removes a clk and all its child nodes from the
3769 * debugfs clk directory if clk->dentry points to debugfs created by
3775 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3776 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3777 core->dentry = NULL; in clk_debug_unregister()
3782 * clk_debug_init - lazily populate the debugfs clk directory
3786 * populates the debugfs clk directory once at boot-time when we know that
3787 * debugfs is setup. It should only be called once at boot-time, all other clks
3799 pr_warn("** WRITEABLE clk DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n"); in clk_debug_init()
3801 pr_warn("** This means that this kernel is built to expose clk operations **\n"); in clk_debug_init()
3802 pr_warn("** such as parent or rate setting, enabling, disabling, etc. **\n"); in clk_debug_init()
3812 rootdir = debugfs_create_dir("clk", NULL); in clk_debug_init()
3847 * parent. in clk_core_reparent_orphans_nolock()
3850 struct clk_core *parent = __clk_init_parent(orphan); in clk_core_reparent_orphans_nolock() local
3856 * are enabled during init but might not have a parent yet. in clk_core_reparent_orphans_nolock()
3858 if (parent) { in clk_core_reparent_orphans_nolock()
3859 /* update the clk tree topology */ in clk_core_reparent_orphans_nolock()
3860 __clk_set_parent_before(orphan, parent); in clk_core_reparent_orphans_nolock()
3861 __clk_set_parent_after(orphan, parent, NULL); in clk_core_reparent_orphans_nolock()
3873 * 'req_rate' is set to something non-zero so that in clk_core_reparent_orphans_nolock()
3876 orphan->req_rate = orphan->rate; in clk_core_reparent_orphans_nolock()
3882 * __clk_core_init - initialize the data structures in a struct clk_core
3886 * parent and rate and sets them both.
3891 struct clk_core *parent; in __clk_core_init() local
3898 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3899 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3900 * being NULL as the clk not being registered yet. This is crucial so in __clk_core_init()
3901 * that clks aren't parented until their parent is fully registered. in __clk_core_init()
3903 core->hw->core = core; in __clk_core_init()
3910 if (clk_core_lookup(core->name)) { in __clk_core_init()
3911 pr_debug("%s: clk %s already initialized\n", in __clk_core_init()
3912 __func__, core->name); in __clk_core_init()
3913 ret = -EEXIST; in __clk_core_init()
3917 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3918 if (core->ops->set_rate && in __clk_core_init()
3919 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3920 core->ops->recalc_rate)) { in __clk_core_init()
3922 __func__, core->name); in __clk_core_init()
3923 ret = -EINVAL; in __clk_core_init()
3927 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3929 __func__, core->name); in __clk_core_init()
3930 ret = -EINVAL; in __clk_core_init()
3934 if (core->ops->set_parent && !core->ops->determine_rate) { in __clk_core_init()
3936 __func__, core->name); in __clk_core_init()
3937 ret = -EINVAL; in __clk_core_init()
3941 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3943 __func__, core->name); in __clk_core_init()
3944 ret = -EINVAL; in __clk_core_init()
3948 if (core->ops->set_rate_and_parent && in __clk_core_init()
3949 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3951 __func__, core->name); in __clk_core_init()
3952 ret = -EINVAL; in __clk_core_init()
3957 * optional platform-specific magic in __clk_core_init()
3965 * such as rate, parent, etc ... in __clk_core_init()
3970 if (core->ops->init) { in __clk_core_init()
3971 ret = core->ops->init(core->hw); in __clk_core_init()
3976 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3979 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3980 * parent has not yet been clk_core_init'd then place clk in the orphan in __clk_core_init()
3981 * list. If clk doesn't have any parents then place it in the root in __clk_core_init()
3982 * clk list. in __clk_core_init()
3984 * Every time a new clk is clk_init'd then we walk the list of orphan in __clk_core_init()
3985 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
3988 if (parent) { in __clk_core_init()
3989 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3990 core->orphan = parent->orphan; in __clk_core_init()
3991 } else if (!core->num_parents) { in __clk_core_init()
3992 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3993 core->orphan = false; in __clk_core_init()
3995 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3996 core->orphan = true; in __clk_core_init()
3998 hash_add(clk_hashtable, &core->hashtable_node, in __clk_core_init()
3999 full_name_hash(NULL, core->name, strlen(core->name))); in __clk_core_init()
4002 * Set clk's accuracy. The preferred method is to use in __clk_core_init()
4004 * fallback is to use the parent's accuracy. If a clock doesn't have a in __clk_core_init()
4005 * parent (or is orphaned) then accuracy is set to zero (perfect in __clk_core_init()
4008 if (core->ops->recalc_accuracy) in __clk_core_init()
4009 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
4010 clk_core_get_accuracy_no_lock(parent)); in __clk_core_init()
4011 else if (parent) in __clk_core_init()
4012 core->accuracy = parent->accuracy; in __clk_core_init()
4014 core->accuracy = 0; in __clk_core_init()
4017 * Set clk's phase by clk_core_get_phase() caching the phase. in __clk_core_init()
4018 * Since a phase is by definition relative to its parent, just in __clk_core_init()
4024 pr_warn("%s: Failed to get phase for clk '%s'\n", __func__, in __clk_core_init()
4025 core->name); in __clk_core_init()
4030 * Set clk's duty cycle. in __clk_core_init()
4035 * Set clk's rate. The preferred method is to use .recalc_rate. For in __clk_core_init()
4037 * parent's rate. If a clock doesn't have a parent (or is orphaned) in __clk_core_init()
4040 if (core->ops->recalc_rate) in __clk_core_init()
4041 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
4042 clk_core_get_rate_nolock(parent)); in __clk_core_init()
4043 else if (parent) in __clk_core_init()
4044 rate = parent->rate; in __clk_core_init()
4047 core->rate = core->req_rate = rate; in __clk_core_init()
4054 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
4057 pr_warn("%s: critical clk '%s' failed to prepare\n", in __clk_core_init()
4058 __func__, core->name); in __clk_core_init()
4064 pr_warn("%s: critical clk '%s' failed to enable\n", in __clk_core_init()
4065 __func__, core->name); in __clk_core_init()
4076 hash_del(&core->hashtable_node); in __clk_core_init()
4077 hlist_del_init(&core->child_node); in __clk_core_init()
4078 core->hw->core = NULL; in __clk_core_init()
4090 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
4091 * @core: clk to add consumer to
4092 * @clk: consumer to link to a clk
4094 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
4097 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
4102 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
4103 * @clk: consumer to unlink
4105 static void clk_core_unlink_consumer(struct clk *clk) in clk_core_unlink_consumer() argument
4108 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
4112 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
4113 * @core: clk to allocate a consumer for
4117 * Returns: clk consumer left unlinked from the consumer list
4119 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk()
4122 struct clk *clk; in alloc_clk() local
4124 clk = kzalloc(sizeof(*clk), GFP_KERNEL); in alloc_clk()
4125 if (!clk) in alloc_clk()
4126 return ERR_PTR(-ENOMEM); in alloc_clk()
4128 clk->core = core; in alloc_clk()
4129 clk->dev_id = dev_id; in alloc_clk()
4130 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
4131 clk->max_rate = ULONG_MAX; in alloc_clk()
4133 return clk; in alloc_clk()
4137 * free_clk - Free a clk consumer
4138 * @clk: clk consumer to free
4140 * Note, this assumes the clk has been unlinked from the clk_core consumer
4143 static void free_clk(struct clk *clk) in free_clk() argument
4145 kfree_const(clk->con_id); in free_clk()
4146 kfree(clk); in free_clk()
4150 * clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given
4152 * @dev: clk consumer device
4153 * @hw: clk_hw associated with the clk being consumed
4157 * This is the main function used to create a clk pointer for use by clk
4159 * used by the framework and clk provider respectively.
4161 struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, in clk_hw_create_clk()
4164 struct clk *clk; in clk_hw_create_clk() local
4171 core = hw->core; in clk_hw_create_clk()
4172 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
4173 if (IS_ERR(clk)) in clk_hw_create_clk()
4174 return clk; in clk_hw_create_clk()
4175 clk->dev = dev; in clk_hw_create_clk()
4177 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
4178 free_clk(clk); in clk_hw_create_clk()
4179 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
4182 kref_get(&core->ref); in clk_hw_create_clk()
4183 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
4185 return clk; in clk_hw_create_clk()
4189 * clk_hw_get_clk - get clk consumer given an clk_hw
4190 * @hw: clk_hw associated with the clk being consumed
4193 * Returns: new clk consumer
4195 * to get a consumer clk and act on the clock element
4198 struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id) in clk_hw_get_clk()
4200 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4213 return -EINVAL; in clk_cpy_name()
4219 return -ENOMEM; in clk_cpy_name()
4227 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
4228 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
4229 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
4230 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
4232 struct clk_parent_map *parents, *parent; in clk_core_populate_parent_map() local
4238 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
4242 core->parents = parents; in clk_core_populate_parent_map()
4244 return -ENOMEM; in clk_core_populate_parent_map()
4247 for (i = 0, parent = parents; i < num_parents; i++, parent++) { in clk_core_populate_parent_map()
4248 parent->index = -1; in clk_core_populate_parent_map()
4253 __func__, core->name); in clk_core_populate_parent_map()
4254 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
4257 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
4258 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
4259 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
4262 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
4266 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
4268 ret = -EINVAL; in clk_core_populate_parent_map()
4276 } while (--i >= 0); in clk_core_populate_parent_map()
4288 int i = core->num_parents; in clk_core_free_parent_map()
4290 if (!core->num_parents) in clk_core_free_parent_map()
4293 while (--i >= 0) { in clk_core_free_parent_map()
4294 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4295 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4298 kfree(core->parents); in clk_core_free_parent_map()
4306 if (core->rpm_enabled) { in __clk_release()
4308 hlist_del(&core->rpm_node); in __clk_release()
4313 kfree_const(core->name); in __clk_release()
4317 static struct clk *
4322 const struct clk_init_data *init = hw->init; in __clk_register()
4327 * we catch use of hw->init early on in the core. in __clk_register()
4329 hw->init = NULL; in __clk_register()
4333 ret = -ENOMEM; in __clk_register()
4337 kref_init(&core->ref); in __clk_register()
4339 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4340 if (!core->name) { in __clk_register()
4341 ret = -ENOMEM; in __clk_register()
4345 if (WARN_ON(!init->ops)) { in __clk_register()
4346 ret = -EINVAL; in __clk_register()
4349 core->ops = init->ops; in __clk_register()
4351 core->dev = dev; in __clk_register()
4353 core->of_node = np; in __clk_register()
4354 if (dev && dev->driver) in __clk_register()
4355 core->owner = dev->driver->owner; in __clk_register()
4356 core->hw = hw; in __clk_register()
4357 core->flags = init->flags; in __clk_register()
4358 core->num_parents = init->num_parents; in __clk_register()
4359 core->min_rate = 0; in __clk_register()
4360 core->max_rate = ULONG_MAX; in __clk_register()
4366 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4372 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4373 if (IS_ERR(hw->clk)) { in __clk_register()
4374 ret = PTR_ERR(hw->clk); in __clk_register()
4378 clk_core_link_consumer(core, hw->clk); in __clk_register()
4382 return hw->clk; in __clk_register()
4385 clk_core_unlink_consumer(hw->clk); in __clk_register()
4388 free_clk(hw->clk); in __clk_register()
4389 hw->clk = NULL; in __clk_register()
4395 kref_put(&core->ref, __clk_release); in __clk_register()
4398 dev_err_probe(dev, ret, "failed to register clk '%s' (%pS)\n", in __clk_register()
4399 init->name, hw); in __clk_register()
4401 pr_err("%pOF: error %pe: failed to register clk '%s' (%pS)\n", in __clk_register()
4402 np, ERR_PTR(ret), init->name, hw); in __clk_register()
4408 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
4412 * @dev->parent if dev doesn't have a device node, or NULL if neither
4413 * @dev or @dev->parent have a device node.
4424 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
4430 * clk_register - allocate a new clock, register it and return an opaque cookie
4432 * @hw: link to hardware-specific clock data
4437 * Returns: a pointer to the newly allocated struct clk which
4442 struct clk *clk_register(struct device *dev, struct clk_hw *hw) in clk_register()
4449 * clk_hw_register - register a clk_hw and return an error code
4451 * @hw: link to hardware-specific clock data
4466 * of_clk_hw_register - register a clk_hw and return an error code
4468 * @hw: link to hardware-specific clock data
4485 * consumer calls clk_put() and the struct clk object is freed.
4489 return -ENXIO; in clk_nodrv_prepare_enable()
4500 return -ENXIO; in clk_nodrv_set_rate()
4505 return -ENXIO; in clk_nodrv_set_parent()
4511 return -ENXIO; in clk_nodrv_determine_rate()
4530 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
4531 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4532 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4534 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
4538 /* Remove this clk from all parent caches */
4553 * clk_unregister - unregister a currently registered clock
4554 * @clk: clock to unregister
4556 void clk_unregister(struct clk *clk) in clk_unregister() argument
4561 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in clk_unregister()
4564 clk_debug_unregister(clk->core); in clk_unregister()
4568 ops = clk->core->ops; in clk_unregister()
4571 clk->core->name); in clk_unregister()
4580 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4583 if (ops->terminate) in clk_unregister()
4584 ops->terminate(clk->core->hw); in clk_unregister()
4586 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4591 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4596 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4598 hash_del(&clk->core->hashtable_node); in clk_unregister()
4599 hlist_del_init(&clk->core->child_node); in clk_unregister()
4601 if (clk->core->prepare_count) in clk_unregister()
4603 __func__, clk->core->name); in clk_unregister()
4605 if (clk->core->protect_count) in clk_unregister()
4607 __func__, clk->core->name); in clk_unregister()
4610 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4611 free_clk(clk); in clk_unregister()
4616 * clk_hw_unregister - unregister a currently registered clk_hw
4617 * @hw: hardware-specific clock data to unregister
4621 clk_unregister(hw->clk); in clk_hw_unregister()
4627 clk_unregister(*(struct clk **)res); in devm_clk_unregister_cb()
4636 * devm_clk_register - resource managed clk_register()
4638 * @hw: link to hardware-specific clock data
4645 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw) in devm_clk_register()
4647 struct clk *clk; in devm_clk_register() local
4648 struct clk **clkp; in devm_clk_register()
4652 return ERR_PTR(-ENOMEM); in devm_clk_register()
4654 clk = clk_register(dev, hw); in devm_clk_register()
4655 if (!IS_ERR(clk)) { in devm_clk_register()
4656 *clkp = clk; in devm_clk_register()
4662 return clk; in devm_clk_register()
4667 * devm_clk_hw_register - resource managed clk_hw_register()
4669 * @hw: link to hardware-specific clock data
4682 return -ENOMEM; in devm_clk_hw_register()
4698 clk_put(*(struct clk **)res); in devm_clk_release()
4702 * devm_clk_hw_get_clk - resource managed clk_hw_get_clk()
4704 * @hw: clk_hw associated with the clk being consumed
4711 struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw, in devm_clk_hw_get_clk()
4714 struct clk *clk; in devm_clk_hw_get_clk() local
4715 struct clk **clkp; in devm_clk_hw_get_clk()
4721 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4725 return ERR_PTR(-ENOMEM); in devm_clk_hw_get_clk()
4727 clk = clk_hw_get_clk(hw, con_id); in devm_clk_hw_get_clk()
4728 if (!IS_ERR(clk)) { in devm_clk_hw_get_clk()
4729 *clkp = clk; in devm_clk_hw_get_clk()
4735 return clk; in devm_clk_hw_get_clk()
4743 void __clk_put(struct clk *clk) in __clk_put() argument
4747 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in __clk_put()
4757 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4759 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4760 clk_core_rate_unprotect(clk->core); in __clk_put()
4761 clk->exclusive_count = 0; in __clk_put()
4764 clk_core_unlink_consumer(clk); in __clk_put()
4767 if (clk->min_rate > 0 || clk->max_rate < ULONG_MAX) in __clk_put()
4768 clk_set_rate_range_nolock(clk, 0, ULONG_MAX); in __clk_put()
4772 owner = clk->core->owner; in __clk_put()
4773 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4775 free_clk(clk); in __clk_put()
4778 /*** clk rate change notifiers ***/
4781 * clk_notifier_register - add a clk rate change notifier
4782 * @clk: struct clk * to watch
4785 * Request notification when clk's rate changes. This uses an SRCU
4788 * re-enter into the clk framework by calling any top-level clk APIs;
4795 * clk_notifier_register() must be called from non-atomic context.
4796 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4800 int clk_notifier_register(struct clk *clk, struct notifier_block *nb) in clk_notifier_register() argument
4803 int ret = -ENOMEM; in clk_notifier_register()
4805 if (!clk || !nb) in clk_notifier_register()
4806 return -EINVAL; in clk_notifier_register()
4810 /* search the list of notifiers for this clk */ in clk_notifier_register()
4812 if (cn->clk == clk) in clk_notifier_register()
4815 /* if clk wasn't in the notifier list, allocate new clk_notifier */ in clk_notifier_register()
4820 cn->clk = clk; in clk_notifier_register()
4821 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4823 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4826 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4828 clk->core->notifier_count++; in clk_notifier_register()
4838 * clk_notifier_unregister - remove a clk rate change notifier
4839 * @clk: struct clk *
4842 * Request no further notification for changes to 'clk' and frees memory
4845 * Returns -EINVAL if called with null arguments; otherwise, passes
4848 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb) in clk_notifier_unregister() argument
4851 int ret = -ENOENT; in clk_notifier_unregister()
4853 if (!clk || !nb) in clk_notifier_unregister()
4854 return -EINVAL; in clk_notifier_unregister()
4859 if (cn->clk == clk) { in clk_notifier_unregister()
4860 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4862 clk->core->notifier_count--; in clk_notifier_unregister()
4865 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4866 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4867 list_del(&cn->node); in clk_notifier_unregister()
4881 struct clk *clk; member
4889 clk_notifier_unregister(devres->clk, devres->nb); in devm_clk_notifier_release()
4892 int devm_clk_notifier_register(struct device *dev, struct clk *clk, in devm_clk_notifier_register() argument
4902 return -ENOMEM; in devm_clk_notifier_register()
4904 ret = clk_notifier_register(clk, nb); in devm_clk_notifier_register()
4906 devres->clk = clk; in devm_clk_notifier_register()
4907 devres->nb = nb; in devm_clk_notifier_register()
4926 * struct of_clk_provider - Clock provider registration structure
4929 * @get: Get clock callback. Returns NULL or a struct clk for the
4939 struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
4951 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec, in of_clk_src_simple_get()
4964 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) in of_clk_src_onecell_get()
4967 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4969 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4971 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4974 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4982 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4984 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4986 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4989 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4994 * of_clk_add_provider() - Register a clock provider for a node
5002 struct clk *(*clk_src_get)(struct of_phandle_args *clkspec, in of_clk_add_provider()
5014 return -ENOMEM; in of_clk_add_provider()
5016 cp->node = of_node_get(np); in of_clk_add_provider()
5017 cp->data = data; in of_clk_add_provider()
5018 cp->get = clk_src_get; in of_clk_add_provider()
5021 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
5031 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_provider()
5038 * of_clk_add_hw_provider() - Register a clock provider for a node
5056 return -ENOMEM; in of_clk_add_hw_provider()
5058 cp->node = of_node_get(np); in of_clk_add_hw_provider()
5059 cp->data = data; in of_clk_add_hw_provider()
5060 cp->get_hw = get; in of_clk_add_hw_provider()
5063 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
5073 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_hw_provider()
5085 * We allow a child device to use its parent device as the clock provider node
5086 * for cases like MFD sub-devices where the child device driver wants to use
5087 * devm_*() APIs but not list the device in DT as a sub-node.
5093 np = dev->of_node; in get_clk_provider_node()
5094 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
5096 if (!of_property_present(np, "#clock-cells")) in get_clk_provider_node()
5097 if (of_property_present(parent_np, "#clock-cells")) in get_clk_provider_node()
5104 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
5110 * node or if the device node lacks of clock provider information (#clock-cells)
5111 * then the parent device's node is scanned for this information. If parent node
5112 * has the #clock-cells then it is used in registration. Provider is
5128 return -ENOMEM; in devm_of_clk_add_hw_provider()
5144 * of_clk_del_provider() - Remove a previously registered clock provider
5156 if (cp->node == np) { in of_clk_del_provider()
5157 list_del(&cp->link); in of_clk_del_provider()
5158 fwnode_dev_initialized(&np->fwnode, false); in of_clk_del_provider()
5159 of_node_put(cp->node); in of_clk_del_provider()
5169 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
5175 * Parses a device node's "clocks" and "clock-names" properties to find the
5178 * parsing error. The @index argument is ignored if @name is non-NULL.
5182 * phandle1: clock-controller@1 {
5183 * #clock-cells = <2>;
5186 * phandle2: clock-controller@2 {
5187 * #clock-cells = <1>;
5190 * clock-consumer@3 {
5192 * clock-names = "name1", "name2";
5195 * To get a device_node for `clock-controller@2' node you may call this
5198 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
5199 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
5200 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
5202 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
5203 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
5204 * the "clock-names" property of @np.
5209 int ret = -ENOENT; in of_parse_clkspec()
5215 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
5217 * return -EINVAL. in of_parse_clkspec()
5220 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
5221 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
5229 * No matching clock found on this node. If the parent node in of_parse_clkspec()
5230 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
5233 np = np->parent; in of_parse_clkspec()
5234 if (np && !of_property_present(np, "clock-ranges")) in of_parse_clkspec()
5246 struct clk *clk; in __of_clk_get_hw_from_provider() local
5248 if (provider->get_hw) in __of_clk_get_hw_from_provider()
5249 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5251 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5252 if (IS_ERR(clk)) in __of_clk_get_hw_from_provider()
5253 return ERR_CAST(clk); in __of_clk_get_hw_from_provider()
5254 return __clk_get_hw(clk); in __of_clk_get_hw_from_provider()
5261 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
5264 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
5267 if (!of_device_is_available(clkspec->np)) in of_clk_get_hw_from_clkspec()
5268 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
5272 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
5284 * of_clk_get_from_provider() - Lookup a clock from a clock provider
5287 * This function looks up a struct clk from the registered list of clock
5291 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) in of_clk_get_from_provider()
5316 static struct clk *__of_clk_get(struct device_node *np, in __of_clk_get()
5325 struct clk *of_clk_get(struct device_node *np, int index) in of_clk_get()
5327 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
5332 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
5336 * This function parses the clocks and clock-names properties,
5337 * and uses them to look up the struct clk from the registered list of clock
5340 struct clk *of_clk_get_by_name(struct device_node *np, const char *name) in of_clk_get_by_name()
5343 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
5345 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
5350 * of_clk_get_parent_count() - Count the number of clocks a device node has
5359 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
5375 struct clk *clk; in of_clk_get_parent_name() local
5377 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
5386 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
5388 of_property_for_each_u32(clkspec.np, "clock-indices", pv) { in of_clk_get_parent_name()
5396 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
5397 if (of_property_present(clkspec.np, "clock-indices") && !found) { in of_clk_get_parent_name()
5402 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
5409 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
5411 clk = of_clk_get_from_provider(&clkspec); in of_clk_get_parent_name()
5412 if (IS_ERR(clk)) { in of_clk_get_parent_name()
5414 clk_name = clkspec.np->name; in of_clk_get_parent_name()
5418 clk_name = __clk_get_name(clk); in of_clk_get_parent_name()
5419 clk_put(clk); in of_clk_get_parent_name()
5430 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
5457 * This function looks for a parent clock. If there is one, then it
5458 * checks that the provider for this parent clock was initialized, in
5459 * this case the parent clock will be ready.
5466 struct clk *clk = of_clk_get(np, i); in parent_ready() local
5468 /* this parent is ready we can check the next one */ in parent_ready()
5469 if (!IS_ERR(clk)) { in parent_ready()
5470 clk_put(clk); in parent_ready()
5475 /* at least one parent is not ready, we exit now */ in parent_ready()
5476 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
5482 * no more parent. As we didn't exit yet, then the in parent_ready()
5483 * previous parent are ready. If there is no clock in parent_ready()
5484 * parent, no need to wait for them, then we can in parent_ready()
5492 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
5495 * @flags: pointer to top-level framework flags
5497 * Detects if the clock-critical property exists and, if so, sets the
5501 * bindings, such as the one-clock-per-node style that are outdated.
5515 return -EINVAL; in of_clk_detect_critical()
5517 of_property_for_each_u32(np, "clock-critical", idx) in of_clk_detect_critical()
5525 * of_clk_init() - Scan and init clock providers from the DT
5546 struct clock_provider *parent; in of_clk_init() local
5551 parent = kzalloc(sizeof(*parent), GFP_KERNEL); in of_clk_init()
5552 if (!parent) { in of_clk_init()
5555 list_del(&clk_provider->node); in of_clk_init()
5556 of_node_put(clk_provider->np); in of_clk_init()
5563 parent->clk_init_cb = match->data; in of_clk_init()
5564 parent->np = of_node_get(np); in of_clk_init()
5565 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5572 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5575 of_node_set_flag(clk_provider->np, in of_clk_init()
5578 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5579 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5581 list_del(&clk_provider->node); in of_clk_init()
5582 of_node_put(clk_provider->np); in of_clk_init()
5592 * in case the clock parent was not mandatory in of_clk_init()