• Home
  • Raw
  • Download

Lines Matching +full:clk +full:- +full:phase +full:-

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"
81 int phase; member
95 #include <trace/events/clk.h>
97 struct clk { struct
113 if (!core->rpm_enabled) in clk_pm_runtime_get()
116 ret = pm_runtime_get_sync(core->dev); in clk_pm_runtime_get()
118 pm_runtime_put_noidle(core->dev); in clk_pm_runtime_get()
126 if (!core->rpm_enabled) in clk_pm_runtime_put()
129 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
153 if (--prepare_refcnt) in clk_prepare_unlock()
193 if (--enable_refcnt) { in clk_enable_unlock()
203 return core->protect_count; in clk_core_rate_is_protected()
214 if (!core->ops->is_prepared) in clk_core_is_prepared()
215 return core->prepare_count; in clk_core_is_prepared()
218 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
233 if (!core->ops->is_enabled) in clk_core_is_enabled()
234 return core->enable_count; in clk_core_is_enabled()
246 if (core->rpm_enabled) { in clk_core_is_enabled()
247 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
248 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
254 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
256 if (core->rpm_enabled) in clk_core_is_enabled()
257 pm_runtime_put(core->dev); in clk_core_is_enabled()
264 const char *__clk_get_name(const struct clk *clk) in __clk_get_name() argument
266 return !clk ? NULL : clk->core->name; in __clk_get_name()
272 return hw->core->name; in clk_hw_get_name()
276 struct clk_hw *__clk_get_hw(struct clk *clk) in __clk_get_hw() argument
278 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
284 return hw->core->num_parents; in clk_hw_get_num_parents()
290 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
300 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
303 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
320 /* search the 'proper' clk tree first */ in clk_core_lookup()
347 return -ENOENT; in of_parse_clkspec()
352 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
357 * clk_core_get - Find the clk_core parent of a clk
358 * @core: clk to find parent of
361 * This is the preferred method for clk providers to find the parent of a
362 * clk when that parent is external to the clk controller. The parent_names
364 * node's 'clock-names' property or as the 'con_id' matching the device's
365 * dev_name() in a clk_lookup. This allows clk providers to use their own
369 * clock-controller@c001 that has a clk_init_data::parent_data array
371 * clock-controller@f00abcd without needing to get the globally unique name of
372 * the xtal clk.
374 * parent: clock-controller@f00abcd {
376 * #clock-cells = <0>;
379 * clock-controller@c001 {
382 * clock-names = "xtal";
383 * #clock-cells = <1>;
386 * Returns: -ENOENT when the provider can't be found or the clk doesn't
388 * in a clkdev lookup. NULL when the provider knows about the clk but it
390 * A valid clk_core pointer when the clk can be found in the provider.
394 const char *name = core->parents[p_index].fw_name; in clk_core_get()
395 int index = core->parents[p_index].index; in clk_core_get()
396 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
397 struct device *dev = core->dev; in clk_core_get()
399 struct device_node *np = core->of_node; in clk_core_get()
417 return hw->core; in clk_core_get()
422 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
423 struct clk_core *parent = ERR_PTR(-ENOENT); in clk_core_fill_parent_index()
425 if (entry->hw) { in clk_core_fill_parent_index()
426 parent = entry->hw->core; in clk_core_fill_parent_index()
433 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
436 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
437 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
442 entry->core = parent; in clk_core_fill_parent_index()
448 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
451 if (!core->parents[index].core) in clk_core_get_parent_by_index()
454 return core->parents[index].core; in clk_core_get_parent_by_index()
462 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
464 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
468 unsigned int __clk_get_enable_count(struct clk *clk) in __clk_get_enable_count() argument
470 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
478 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
479 return core->rate; in clk_core_get_rate_nolock()
482 * Clk must have a parent because num_parents > 0 but the parent isn't in clk_core_get_rate_nolock()
483 * known yet. Best to return 0 as the rate of this clk until we can in clk_core_get_rate_nolock()
491 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
500 return core->accuracy; in clk_core_get_accuracy_no_lock()
505 return hw->core->flags; in clk_hw_get_flags()
511 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
517 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
523 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
527 bool __clk_is_enabled(struct clk *clk) in __clk_is_enabled() argument
529 if (!clk) in __clk_is_enabled()
532 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
540 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
549 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags()
555 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
556 parent = core->parent; in clk_mux_determine_rate_flags()
557 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
558 ret = __clk_determine_rate(parent ? parent->hw : NULL, in clk_mux_determine_rate_flags()
574 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
580 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
582 ret = __clk_determine_rate(parent->hw, &parent_req); in clk_mux_determine_rate_flags()
589 if (mux_is_better_rate(req->rate, parent_req.rate, in clk_mux_determine_rate_flags()
597 return -EINVAL; in clk_mux_determine_rate_flags()
601 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
602 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
603 req->rate = best; in clk_mux_determine_rate_flags()
609 struct clk *__clk_lookup(const char *name) in __clk_lookup()
613 return !core ? NULL : core->hw->clk; in __clk_lookup()
620 struct clk *clk_user; in clk_core_get_boundaries()
624 *min_rate = core->min_rate; in clk_core_get_boundaries()
625 *max_rate = core->max_rate; in clk_core_get_boundaries()
627 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
628 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
630 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
631 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
638 struct clk *user; in clk_core_check_boundaries()
642 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
645 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
646 if (min_rate > user->max_rate || max_rate < user->min_rate) in clk_core_check_boundaries()
655 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
656 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
661 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
662 * @hw: mux type clk to determine rate on
669 * Returns: 0 on success, -EERROR value on error
685 /*** clk api ***/
694 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
695 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
698 if (--core->protect_count > 0) in clk_core_rate_unprotect()
701 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
711 return -EINVAL; in clk_core_rate_nuke_protect()
713 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
716 ret = core->protect_count; in clk_core_rate_nuke_protect()
717 core->protect_count = 1; in clk_core_rate_nuke_protect()
724 * clk_rate_exclusive_put - release exclusivity over clock rate control
725 * @clk: the clk over which the exclusivity is released
741 void clk_rate_exclusive_put(struct clk *clk) in clk_rate_exclusive_put() argument
743 if (!clk) in clk_rate_exclusive_put()
752 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
755 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
756 clk->exclusive_count--; in clk_rate_exclusive_put()
769 if (core->protect_count == 0) in clk_core_rate_protect()
770 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
772 core->protect_count++; in clk_core_rate_protect()
786 core->protect_count = count; in clk_core_rate_restore_protect()
790 * clk_rate_exclusive_get - get exclusivity over the clk rate control
791 * @clk: the clk over which the exclusity of rate control is requested
805 * Returns 0 on success, -EERROR otherwise
807 int clk_rate_exclusive_get(struct clk *clk) in clk_rate_exclusive_get() argument
809 if (!clk) in clk_rate_exclusive_get()
813 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
814 clk->exclusive_count++; in clk_rate_exclusive_get()
828 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
829 "%s already unprepared\n", core->name)) in clk_core_unprepare()
832 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
833 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
836 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
839 if (--core->prepare_count > 0) in clk_core_unprepare()
842 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
846 if (core->ops->unprepare) in clk_core_unprepare()
847 core->ops->unprepare(core->hw); in clk_core_unprepare()
850 clk_core_unprepare(core->parent); in clk_core_unprepare()
862 * clk_unprepare - undo preparation of a clock source
863 * @clk: the clk being unprepared
866 * simple case, clk_unprepare can be used instead of clk_disable to gate a clk
867 * if the operation may sleep. One example is a clk which is accessed over
868 * I2c. In the complex case a clk gate operation may require a fast and a slow
872 void clk_unprepare(struct clk *clk) in clk_unprepare() argument
874 if (IS_ERR_OR_NULL(clk)) in clk_unprepare()
877 clk_core_unprepare_lock(clk->core); in clk_unprepare()
890 if (core->prepare_count == 0) { in clk_core_prepare()
895 ret = clk_core_prepare(core->parent); in clk_core_prepare()
901 if (core->ops->prepare) in clk_core_prepare()
902 ret = core->ops->prepare(core->hw); in clk_core_prepare()
910 core->prepare_count++; in clk_core_prepare()
919 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
924 clk_core_unprepare(core->parent); in clk_core_prepare()
942 * clk_prepare - prepare a clock source
943 * @clk: the clk being prepared
946 * case, clk_prepare can be used instead of clk_enable to ungate a clk if the
947 * operation may sleep. One example is a clk which is accessed over I2c. In
948 * the complex case a clk ungate operation may require a fast and a slow part.
951 * Returns 0 on success, -EERROR otherwise.
953 int clk_prepare(struct clk *clk) in clk_prepare() argument
955 if (!clk) in clk_prepare()
958 return clk_core_prepare_lock(clk->core); in clk_prepare()
969 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
972 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
973 "Disabling critical %s\n", core->name)) in clk_core_disable()
976 if (--core->enable_count > 0) in clk_core_disable()
981 if (core->ops->disable) in clk_core_disable()
982 core->ops->disable(core->hw); in clk_core_disable()
986 clk_core_disable(core->parent); in clk_core_disable()
999 * clk_disable - gate a clock
1000 * @clk: the clk being gated
1004 * clk if the operation is fast and will never sleep. One example is a
1005 * SoC-internal clk which is controlled via simple register writes. In the
1006 * complex case a clk gate operation may require a fast and a slow part. It is
1010 void clk_disable(struct clk *clk) in clk_disable() argument
1012 if (IS_ERR_OR_NULL(clk)) in clk_disable()
1015 clk_core_disable_lock(clk->core); in clk_disable()
1028 if (WARN(core->prepare_count == 0, in clk_core_enable()
1029 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1030 return -ESHUTDOWN; in clk_core_enable()
1032 if (core->enable_count == 0) { in clk_core_enable()
1033 ret = clk_core_enable(core->parent); in clk_core_enable()
1040 if (core->ops->enable) in clk_core_enable()
1041 ret = core->ops->enable(core->hw); in clk_core_enable()
1046 clk_core_disable(core->parent); in clk_core_enable()
1051 core->enable_count++; in clk_core_enable()
1068 * clk_gate_restore_context - restore context for poweroff
1079 struct clk_core *core = hw->core; in clk_gate_restore_context()
1081 if (core->enable_count) in clk_gate_restore_context()
1082 core->ops->enable(hw); in clk_gate_restore_context()
1084 core->ops->disable(hw); in clk_gate_restore_context()
1093 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1099 if (core->ops && core->ops->save_context) in clk_core_save_context()
1100 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1109 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1110 core->ops->restore_context(core->hw); in clk_core_restore_context()
1112 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1117 * clk_save_context - save clock context for poweroff
1125 struct clk_core *clk; in clk_save_context() local
1128 hlist_for_each_entry(clk, &clk_root_list, child_node) { in clk_save_context()
1129 ret = clk_core_save_context(clk); in clk_save_context()
1134 hlist_for_each_entry(clk, &clk_orphan_list, child_node) { in clk_save_context()
1135 ret = clk_core_save_context(clk); in clk_save_context()
1145 * clk_restore_context - restore clock context after poweroff
1163 * clk_enable - ungate a clock
1164 * @clk: the clk being ungated
1167 * simple case, clk_enable can be used instead of clk_prepare to ungate a clk
1168 * if the operation will never sleep. One example is a SoC-internal clk which
1169 * is controlled via simple register writes. In the complex case a clk ungate
1172 * must be called before clk_enable. Returns 0 on success, -EERROR
1175 int clk_enable(struct clk *clk) in clk_enable() argument
1177 if (!clk) in clk_enable()
1180 return clk_core_enable_lock(clk->core); in clk_enable()
1211 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1214 if (core->prepare_count) in clk_unprepare_unused_subtree()
1217 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1225 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1226 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1227 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1228 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1242 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1245 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1246 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1253 if (core->enable_count) in clk_disable_unused_subtree()
1256 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1260 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1266 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1267 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1268 else if (core->ops->disable) in clk_disable_unused_subtree()
1269 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1277 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1278 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1294 pr_warn("clk: Not disabling unused clocks\n"); in clk_disable_unused()
1330 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1331 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1335 req->rate = core->rate; in clk_core_determine_round_nolock()
1336 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1337 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1338 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1339 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1340 &req->best_parent_rate); in clk_core_determine_round_nolock()
1344 req->rate = rate; in clk_core_determine_round_nolock()
1346 return -EINVAL; in clk_core_determine_round_nolock()
1360 parent = core->parent; in clk_core_init_rate_req()
1362 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1363 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1365 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1366 req->best_parent_rate = 0; in clk_core_init_rate_req()
1372 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1381 req->rate = 0; in clk_core_round_rate_nolock()
1389 else if (core->flags & CLK_SET_RATE_PARENT) in clk_core_round_rate_nolock()
1390 return clk_core_round_rate_nolock(core->parent, req); in clk_core_round_rate_nolock()
1392 req->rate = core->rate; in clk_core_round_rate_nolock()
1397 * __clk_determine_rate - get the closest rate actually supported by a clock
1406 req->rate = 0; in __clk_determine_rate()
1410 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1415 * clk_hw_round_rate() - round the given rate for a hw clk
1416 * @hw: the hw clk for which we are rounding a rate
1419 * Takes in a rate as input and rounds it to a rate that the clk can actually
1423 * For clk providers to call from within clk_ops such as .round_rate,
1426 * Return: returns rounded rate of hw clk if clk supports round_rate operation
1434 clk_core_get_boundaries(hw->core, &req.min_rate, &req.max_rate); in clk_hw_round_rate()
1437 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1446 * clk_round_rate - round the given rate for a clk
1447 * @clk: the clk for which we are rounding a rate
1450 * Takes in a rate as input and rounds it to a rate that the clk can actually
1451 * use which is then returned. If clk doesn't support round_rate operation
1454 long clk_round_rate(struct clk *clk, unsigned long rate) in clk_round_rate() argument
1459 if (!clk) in clk_round_rate()
1464 if (clk->exclusive_count) in clk_round_rate()
1465 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1467 clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate); in clk_round_rate()
1470 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1472 if (clk->exclusive_count) in clk_round_rate()
1473 clk_core_rate_protect(clk->core); in clk_round_rate()
1485 * __clk_notify - call clk notifier chain
1486 * @core: clk that is changing rate
1487 * @msg: clk notifier type (see include/linux/clk.h)
1488 * @old_rate: old clk rate
1489 * @new_rate: new clk rate
1491 * Triggers a notifier call chain on the clk rate-change notification
1492 * for 'clk'. Passes a pointer to the struct clk and the previous
1509 if (cn->clk->core == core) { in __clk_notify()
1510 cnd.clk = cn->clk; in __clk_notify()
1511 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1523 * @core: first clk in the subtree
1525 * Walks the subtree of clks starting with clk and recalculates accuracies as
1526 * it goes. Note that if a clk does not implement the .recalc_accuracy
1537 if (core->parent) in __clk_recalc_accuracies()
1538 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1540 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1541 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1544 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1546 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1552 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1559 * clk_get_accuracy - return the accuracy of clk
1560 * @clk: the clk whose accuracy is being returned
1562 * Simply returns the cached accuracy of the clk, unless
1565 * If clk is NULL then returns 0.
1567 long clk_get_accuracy(struct clk *clk) in clk_get_accuracy() argument
1571 if (!clk) in clk_get_accuracy()
1575 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1587 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1588 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1596 * @core: first clk in the subtree
1597 * @msg: notification type (see include/linux/clk.h)
1599 * Walks the subtree of clks starting with clk and recalculates rates as it
1600 * goes. Note that if a clk does not implement the .recalc_rate callback then
1614 old_rate = core->rate; in __clk_recalc_rates()
1616 if (core->parent) in __clk_recalc_rates()
1617 parent_rate = core->parent->rate; in __clk_recalc_rates()
1619 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1625 if (core->notifier_count && msg) in __clk_recalc_rates()
1626 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1628 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1634 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1641 * clk_get_rate - return the rate of clk
1642 * @clk: the clk whose rate is being returned
1644 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1646 * If clk is NULL then returns 0.
1648 unsigned long clk_get_rate(struct clk *clk) in clk_get_rate() argument
1652 if (!clk) in clk_get_rate()
1656 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1669 return -EINVAL; in clk_fetch_parent_index()
1671 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1673 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1677 if (core->parents[i].core) in clk_fetch_parent_index()
1681 if (core->parents[i].hw) { in clk_fetch_parent_index()
1682 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1694 if (core->parents[i].name && in clk_fetch_parent_index()
1695 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1699 if (i == core->num_parents) in clk_fetch_parent_index()
1700 return -EINVAL; in clk_fetch_parent_index()
1702 core->parents[i].core = parent; in clk_fetch_parent_index()
1707 * clk_hw_get_parent_index - return the index of the parent clock
1708 * @hw: clk_hw associated with the clk being consumed
1710 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
1718 return -EINVAL; in clk_hw_get_parent_index()
1720 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
1731 core->orphan = is_orphan; in clk_core_update_orphan_status()
1733 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1739 bool was_orphan = core->orphan; in clk_reparent()
1741 hlist_del(&core->child_node); in clk_reparent()
1744 bool becomes_orphan = new_parent->orphan; in clk_reparent()
1747 if (new_parent->new_child == core) in clk_reparent()
1748 new_parent->new_child = NULL; in clk_reparent()
1750 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1755 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1760 core->parent = new_parent; in clk_reparent()
1767 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1790 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
1796 if (core->prepare_count) { in __clk_set_parent_before()
1801 /* update the clk tree topology */ in __clk_set_parent_before()
1817 if (core->prepare_count) { in __clk_set_parent_after()
1822 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
1823 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
1841 if (parent && core->ops->set_parent) in __clk_set_parent()
1842 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
1862 * @core: first clk in the subtree
1863 * @parent_rate: the "future" rate of clk's parent
1865 * Walks the subtree of clks starting with clk, speculating rates as it
1869 * pre-rate change notifications and returns early if no clks in the
1870 * subtree have subscribed to the notifications. Note that if a clk does not
1886 if (core->notifier_count) in __clk_speculate_rates()
1887 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
1890 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
1891 __func__, core->name, ret); in __clk_speculate_rates()
1895 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
1910 core->new_rate = new_rate; in clk_calc_subtree()
1911 core->new_parent = new_parent; in clk_calc_subtree()
1912 core->new_parent_index = p_index; in clk_calc_subtree()
1913 /* include clk in new parent's PRE_RATE_CHANGE notifications */ in clk_calc_subtree()
1914 core->new_child = NULL; in clk_calc_subtree()
1915 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
1916 new_parent->new_child = core; in clk_calc_subtree()
1918 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
1919 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
1920 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
1945 parent = old_parent = core->parent; in clk_calc_new_rates()
1947 best_parent_rate = parent->rate; in clk_calc_new_rates()
1951 /* find the closest rate and parent clk/rate */ in clk_calc_new_rates()
1967 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
1971 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
1972 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
1973 core->new_rate = core->rate; in clk_calc_new_rates()
1976 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
1978 new_rate = parent->new_rate; in clk_calc_new_rates()
1984 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
1986 __func__, core->name); in clk_calc_new_rates()
1991 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
1994 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_calc_new_rates()
1995 __func__, parent->name, core->name); in clk_calc_new_rates()
2000 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2001 best_parent_rate != parent->rate) in clk_calc_new_rates()
2021 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2024 if (core->notifier_count) { in clk_propagate_rate_change()
2025 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2030 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2032 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2039 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2040 if (core->new_child) { in clk_propagate_rate_change()
2041 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2063 old_rate = core->rate; in clk_change_rate()
2065 if (core->new_parent) { in clk_change_rate()
2066 parent = core->new_parent; in clk_change_rate()
2067 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2068 } else if (core->parent) { in clk_change_rate()
2069 parent = core->parent; in clk_change_rate()
2070 best_parent_rate = core->parent->rate; in clk_change_rate()
2076 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2085 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2086 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2087 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2089 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2091 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2093 core->new_parent_index); in clk_change_rate()
2094 } else if (core->ops->set_parent) { in clk_change_rate()
2095 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2098 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2099 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2102 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2105 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2107 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2108 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2110 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2112 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2114 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2123 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2126 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2127 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2129 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2130 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2136 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2138 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2143 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2144 if (core->new_child) in clk_change_rate()
2145 clk_change_rate(core->new_child); in clk_change_rate()
2195 return -EBUSY; in clk_core_set_rate_nolock()
2200 return -EINVAL; in clk_core_set_rate_nolock()
2210 fail_clk->name); in clk_core_set_rate_nolock()
2212 ret = -EBUSY; in clk_core_set_rate_nolock()
2219 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2227 * clk_set_rate - specify a new rate for clk
2228 * @clk: the clk whose rate is being changed
2229 * @rate: the new rate for clk
2231 * In the simplest case clk_set_rate will only adjust the rate of clk.
2234 * propagate up to clk's parent; whether or not this happens depends on the
2235 * outcome of clk's .round_rate implementation. If *parent_rate is unchanged
2237 * *parent_rate comes back with a new rate for clk's parent then we propagate
2238 * up to clk's parent and set its rate. Upward propagation will continue
2239 * until either a clk does not support the CLK_SET_RATE_PARENT flag or
2240 * .round_rate stops requesting changes to clk's parent_rate.
2245 * Returns 0 on success, -EERROR otherwise.
2247 int clk_set_rate(struct clk *clk, unsigned long rate) in clk_set_rate() argument
2251 if (!clk) in clk_set_rate()
2257 if (clk->exclusive_count) in clk_set_rate()
2258 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2260 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2262 if (clk->exclusive_count) in clk_set_rate()
2263 clk_core_rate_protect(clk->core); in clk_set_rate()
2272 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2273 * @clk: the clk whose rate is being changed
2274 * @rate: the new rate for clk
2288 * Returns 0 on success, -EERROR otherwise.
2290 int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) in clk_set_rate_exclusive() argument
2294 if (!clk) in clk_set_rate_exclusive()
2306 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2308 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2309 clk->exclusive_count++; in clk_set_rate_exclusive()
2319 * clk_set_rate_range - set a rate range for a clock source
2320 * @clk: clock source
2326 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) in clk_set_rate_range() argument
2331 if (!clk) in clk_set_rate_range()
2335 pr_err("%s: clk %s dev %s con %s: invalid range [%lu, %lu]\n", in clk_set_rate_range()
2336 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range()
2338 return -EINVAL; in clk_set_rate_range()
2343 if (clk->exclusive_count) in clk_set_rate_range()
2344 clk_core_rate_unprotect(clk->core); in clk_set_rate_range()
2347 old_min = clk->min_rate; in clk_set_rate_range()
2348 old_max = clk->max_rate; in clk_set_rate_range()
2349 clk->min_rate = min; in clk_set_rate_range()
2350 clk->max_rate = max; in clk_set_rate_range()
2352 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range()
2353 ret = -EINVAL; in clk_set_rate_range()
2357 rate = clk_core_get_rate_nolock(clk->core); in clk_set_rate_range()
2366 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range()
2368 * - the determine_rate() callback does not really check for in clk_set_rate_range()
2377 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range()
2380 clk->min_rate = old_min; in clk_set_rate_range()
2381 clk->max_rate = old_max; in clk_set_rate_range()
2386 if (clk->exclusive_count) in clk_set_rate_range()
2387 clk_core_rate_protect(clk->core); in clk_set_rate_range()
2396 * clk_set_min_rate - set a minimum clock rate for a clock source
2397 * @clk: clock source
2402 int clk_set_min_rate(struct clk *clk, unsigned long rate) in clk_set_min_rate() argument
2404 if (!clk) in clk_set_min_rate()
2407 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2412 * clk_set_max_rate - set a maximum clock rate for a clock source
2413 * @clk: clock source
2418 int clk_set_max_rate(struct clk *clk, unsigned long rate) in clk_set_max_rate() argument
2420 if (!clk) in clk_set_max_rate()
2423 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2428 * clk_get_parent - return the parent of a clk
2429 * @clk: the clk whose parent gets returned
2431 * Simply returns clk->parent. Returns NULL if clk is NULL.
2433 struct clk *clk_get_parent(struct clk *clk) in clk_get_parent() argument
2435 struct clk *parent; in clk_get_parent()
2437 if (!clk) in clk_get_parent()
2441 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2442 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2453 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2454 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2472 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2476 * clk_has_parent - check if a clock is a possible parent for another
2477 * @clk: clock source
2483 * Returns true if @parent is a possible parent for @clk, false otherwise.
2485 bool clk_has_parent(struct clk *clk, struct clk *parent) in clk_has_parent() argument
2491 if (!clk || !parent) in clk_has_parent()
2494 core = clk->core; in clk_has_parent()
2495 parent_core = parent->core; in clk_has_parent()
2498 if (core->parent == parent_core) in clk_has_parent()
2501 for (i = 0; i < core->num_parents; i++) in clk_has_parent()
2502 if (!strcmp(core->parents[i].name, parent_core->name)) in clk_has_parent()
2521 if (core->parent == parent) in clk_core_set_parent_nolock()
2524 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2525 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2526 return -EPERM; in clk_core_set_parent_nolock()
2528 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2529 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2530 return -EBUSY; in clk_core_set_parent_nolock()
2533 return -EBUSY; in clk_core_set_parent_nolock()
2539 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_core_set_parent_nolock()
2540 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2543 p_rate = parent->rate; in clk_core_set_parent_nolock()
2557 /* do the re-parent */ in clk_core_set_parent_nolock()
2576 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2581 * clk_set_parent - switch the parent of a mux clk
2582 * @clk: the mux clk whose input we are switching
2583 * @parent: the new input to clk
2585 * Re-parent clk to use parent as its new input source. If clk is in
2586 * prepared state, the clk will get enabled for the duration of this call. If
2587 * that's not acceptable for a specific clk (Eg: the consumer can't handle
2589 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
2591 * After successfully changing clk's parent clk_set_parent will update the
2592 * clk topology, sysfs topology and propagate rate recalculation via
2595 * Returns 0 on success, -EERROR otherwise.
2597 int clk_set_parent(struct clk *clk, struct clk *parent) in clk_set_parent() argument
2601 if (!clk) in clk_set_parent()
2606 if (clk->exclusive_count) in clk_set_parent()
2607 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2609 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2610 parent ? parent->core : NULL); in clk_set_parent()
2612 if (clk->exclusive_count) in clk_set_parent()
2613 clk_core_rate_protect(clk->core); in clk_set_parent()
2623 int ret = -EINVAL; in clk_core_set_phase_nolock()
2631 return -EBUSY; in clk_core_set_phase_nolock()
2635 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2636 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2638 core->phase = degrees; in clk_core_set_phase_nolock()
2647 * clk_set_phase - adjust the phase shift of a clock signal
2648 * @clk: clock signal source
2651 * Shifts the phase of a clock signal by the specified
2652 * degrees. Returns 0 on success, -EERROR otherwise.
2655 * signal that we adjust the clock signal phase against. For example
2656 * phase locked-loop clock signal generators we may shift phase with
2658 * clock phase may be shifted with respect to some other, unspecified
2661 * Additionally the concept of phase shift does not propagate through
2663 * clock accuracy. A parent clock phase attribute does not have an
2664 * impact on the phase attribute of a child clock.
2666 int clk_set_phase(struct clk *clk, int degrees) in clk_set_phase() argument
2670 if (!clk) in clk_set_phase()
2680 if (clk->exclusive_count) in clk_set_phase()
2681 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2683 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2685 if (clk->exclusive_count) in clk_set_phase()
2686 clk_core_rate_protect(clk->core); in clk_set_phase()
2699 if (!core->ops->get_phase) in clk_core_get_phase()
2702 /* Always try to update cached phase if possible */ in clk_core_get_phase()
2703 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
2705 core->phase = ret; in clk_core_get_phase()
2711 * clk_get_phase - return the phase shift of a clock signal
2712 * @clk: clock signal source
2714 * Returns the phase shift of a clock node in degrees, otherwise returns
2715 * -EERROR.
2717 int clk_get_phase(struct clk *clk) in clk_get_phase() argument
2721 if (!clk) in clk_get_phase()
2725 ret = clk_core_get_phase(clk->core); in clk_get_phase()
2735 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2736 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2743 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2746 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2749 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2754 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
2755 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
2770 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2771 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2772 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2773 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2792 return -EBUSY; in clk_core_set_duty_cycle_nolock()
2796 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
2799 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
2801 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
2813 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
2814 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
2815 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
2816 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
2823 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
2824 * @clk: clock signal source
2833 int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den) in clk_set_duty_cycle() argument
2838 if (!clk) in clk_set_duty_cycle()
2843 return -EINVAL; in clk_set_duty_cycle()
2850 if (clk->exclusive_count) in clk_set_duty_cycle()
2851 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
2853 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
2855 if (clk->exclusive_count) in clk_set_duty_cycle()
2856 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
2867 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
2874 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
2882 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
2883 * @clk: clock signal source
2889 int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale) in clk_get_scaled_duty_cycle() argument
2891 if (!clk) in clk_get_scaled_duty_cycle()
2894 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
2899 * clk_is_match - check if two clk's point to the same hardware clock
2900 * @p: clk compared against q
2901 * @q: clk compared against p
2903 * Returns true if the two struct clk pointers both point to the same hardware
2904 * clock node. Put differently, returns true if struct clk *p and struct clk *q
2909 bool clk_is_match(const struct clk *p, const struct clk *q) in clk_is_match()
2911 /* trivial case: identical struct clk's or both NULL */ in clk_is_match()
2915 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
2917 if (p->core == q->core) in clk_is_match()
2942 int phase; in clk_summary_show_one() local
2944 seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu ", in clk_summary_show_one()
2946 30 - level * 3, c->name, in clk_summary_show_one()
2947 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
2951 phase = clk_core_get_phase(c); in clk_summary_show_one()
2952 if (phase >= 0) in clk_summary_show_one()
2953 seq_printf(s, "%5d", phase); in clk_summary_show_one()
2955 seq_puts(s, "-----"); in clk_summary_show_one()
2967 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
2974 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_summary_show()
2977 …" clock count count count rate accuracy phase cycle\n"); in clk_summary_show()
2978 …seq_puts(s, "-------------------------------------------------------------------------------------… in clk_summary_show()
2994 int phase; in clk_dump_one() local
3000 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
3001 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
3002 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
3003 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
3008 phase = clk_core_get_phase(c); in clk_dump_one()
3009 if (phase >= 0) in clk_dump_one()
3010 seq_printf(s, "\"phase\": %d,", phase); in clk_dump_one()
3021 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3033 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_dump_show()
3081 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3083 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3092 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3108 *val = core->rate; in clk_rate_get()
3136 struct clk_core *core = s->private; in clk_flags_show()
3137 unsigned long flags = core->flags; in clk_flags_show()
3166 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3174 seq_puts(s, parent->name); in possible_parent_show()
3175 else if (core->parents[i].name) in possible_parent_show()
3176 seq_puts(s, core->parents[i].name); in possible_parent_show()
3177 else if (core->parents[i].fw_name) in possible_parent_show()
3178 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3179 else if (core->parents[i].index >= 0) in possible_parent_show()
3181 of_clk_get_parent_name(core->of_node, in possible_parent_show()
3182 core->parents[i].index)); in possible_parent_show()
3191 struct clk_core *core = s->private; in possible_parents_show()
3194 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3205 struct clk_core *core = s->private; in current_parent_show()
3207 if (core->parent) in current_parent_show()
3208 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3216 struct clk_core *core = s->private; in clk_duty_cycle_show()
3217 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3219 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3227 struct clk_core *core = s->private; in clk_min_rate_show()
3241 struct clk_core *core = s->private; in clk_max_rate_show()
3260 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3261 core->dentry = root; in clk_debug_create_one()
3267 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3268 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3270 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3271 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3272 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3273 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3281 if (core->num_parents > 0) in clk_debug_create_one()
3285 if (core->num_parents > 1) in clk_debug_create_one()
3289 if (core->ops->debug_init) in clk_debug_create_one()
3290 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3294 * clk_debug_register - add a clk node to the debugfs clk directory
3295 * @core: the clk being added to the debugfs clk directory
3297 * Dynamically adds a clk to the debugfs clk directory if debugfs has been
3298 * initialized. Otherwise it bails out early since the debugfs clk directory
3304 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3311 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3312 * @core: the clk being removed from the debugfs clk directory
3314 * Dynamically removes a clk and all its child nodes from the
3315 * debugfs clk directory if clk->dentry points to debugfs created by
3321 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3322 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3323 core->dentry = NULL; in clk_debug_unregister()
3328 * clk_debug_init - lazily populate the debugfs clk directory
3332 * populates the debugfs clk directory once at boot-time when we know that
3333 * debugfs is setup. It should only be called once at boot-time, all other clks
3345 pr_warn("** WRITEABLE clk DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n"); in clk_debug_init()
3347 pr_warn("** This means that this kernel is built to expose clk operations **\n"); in clk_debug_init()
3358 rootdir = debugfs_create_dir("clk", NULL); in clk_debug_init()
3405 /* update the clk tree topology */ in clk_core_reparent_orphans_nolock()
3419 * 'req_rate' is set to something non-zero so that in clk_core_reparent_orphans_nolock()
3422 orphan->req_rate = orphan->rate; in clk_core_reparent_orphans_nolock()
3428 * __clk_core_init - initialize the data structures in a struct clk_core
3439 int phase; in __clk_core_init() local
3442 return -EINVAL; in __clk_core_init()
3447 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3448 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3449 * being NULL as the clk not being registered yet. This is crucial so in __clk_core_init()
3452 core->hw->core = core; in __clk_core_init()
3459 if (clk_core_lookup(core->name)) { in __clk_core_init()
3460 pr_debug("%s: clk %s already initialized\n", in __clk_core_init()
3461 __func__, core->name); in __clk_core_init()
3462 ret = -EEXIST; in __clk_core_init()
3466 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3467 if (core->ops->set_rate && in __clk_core_init()
3468 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3469 core->ops->recalc_rate)) { in __clk_core_init()
3471 __func__, core->name); in __clk_core_init()
3472 ret = -EINVAL; in __clk_core_init()
3476 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3478 __func__, core->name); in __clk_core_init()
3479 ret = -EINVAL; in __clk_core_init()
3483 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3485 __func__, core->name); in __clk_core_init()
3486 ret = -EINVAL; in __clk_core_init()
3490 if (core->ops->set_rate_and_parent && in __clk_core_init()
3491 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3493 __func__, core->name); in __clk_core_init()
3494 ret = -EINVAL; in __clk_core_init()
3499 * optional platform-specific magic in __clk_core_init()
3512 if (core->ops->init) { in __clk_core_init()
3513 ret = core->ops->init(core->hw); in __clk_core_init()
3518 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3521 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3522 * parent has not yet been clk_core_init'd then place clk in the orphan in __clk_core_init()
3523 * list. If clk doesn't have any parents then place it in the root in __clk_core_init()
3524 * clk list. in __clk_core_init()
3526 * Every time a new clk is clk_init'd then we walk the list of orphan in __clk_core_init()
3527 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
3531 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3532 core->orphan = parent->orphan; in __clk_core_init()
3533 } else if (!core->num_parents) { in __clk_core_init()
3534 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3535 core->orphan = false; in __clk_core_init()
3537 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3538 core->orphan = true; in __clk_core_init()
3542 * Set clk's accuracy. The preferred method is to use in __clk_core_init()
3548 if (core->ops->recalc_accuracy) in __clk_core_init()
3549 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3552 core->accuracy = parent->accuracy; in __clk_core_init()
3554 core->accuracy = 0; in __clk_core_init()
3557 * Set clk's phase by clk_core_get_phase() caching the phase. in __clk_core_init()
3558 * Since a phase is by definition relative to its parent, just in __clk_core_init()
3559 * query the current clock phase, or just assume it's in phase. in __clk_core_init()
3561 phase = clk_core_get_phase(core); in __clk_core_init()
3562 if (phase < 0) { in __clk_core_init()
3563 ret = phase; in __clk_core_init()
3564 pr_warn("%s: Failed to get phase for clk '%s'\n", __func__, in __clk_core_init()
3565 core->name); in __clk_core_init()
3570 * Set clk's duty cycle. in __clk_core_init()
3575 * Set clk's rate. The preferred method is to use .recalc_rate. For in __clk_core_init()
3580 if (core->ops->recalc_rate) in __clk_core_init()
3581 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3584 rate = parent->rate; in __clk_core_init()
3587 core->rate = core->req_rate = rate; in __clk_core_init()
3594 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3599 pr_warn("%s: critical clk '%s' failed to prepare\n", in __clk_core_init()
3600 __func__, core->name); in __clk_core_init()
3608 pr_warn("%s: critical clk '%s' failed to enable\n", in __clk_core_init()
3609 __func__, core->name); in __clk_core_init()
3618 kref_init(&core->ref); in __clk_core_init()
3623 hlist_del_init(&core->child_node); in __clk_core_init()
3624 core->hw->core = NULL; in __clk_core_init()
3636 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
3637 * @core: clk to add consumer to
3638 * @clk: consumer to link to a clk
3640 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
3643 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3648 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
3649 * @clk: consumer to unlink
3651 static void clk_core_unlink_consumer(struct clk *clk) in clk_core_unlink_consumer() argument
3654 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
3658 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
3659 * @core: clk to allocate a consumer for
3663 * Returns: clk consumer left unlinked from the consumer list
3665 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk()
3668 struct clk *clk; in alloc_clk() local
3670 clk = kzalloc(sizeof(*clk), GFP_KERNEL); in alloc_clk()
3671 if (!clk) in alloc_clk()
3672 return ERR_PTR(-ENOMEM); in alloc_clk()
3674 clk->core = core; in alloc_clk()
3675 clk->dev_id = dev_id; in alloc_clk()
3676 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
3677 clk->max_rate = ULONG_MAX; in alloc_clk()
3679 return clk; in alloc_clk()
3683 * free_clk - Free a clk consumer
3684 * @clk: clk consumer to free
3686 * Note, this assumes the clk has been unlinked from the clk_core consumer
3689 static void free_clk(struct clk *clk) in free_clk() argument
3691 kfree_const(clk->con_id); in free_clk()
3692 kfree(clk); in free_clk()
3696 * clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given
3698 * @dev: clk consumer device
3699 * @hw: clk_hw associated with the clk being consumed
3703 * This is the main function used to create a clk pointer for use by clk
3705 * used by the framework and clk provider respectively.
3707 struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, in clk_hw_create_clk()
3710 struct clk *clk; in clk_hw_create_clk() local
3717 core = hw->core; in clk_hw_create_clk()
3718 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
3719 if (IS_ERR(clk)) in clk_hw_create_clk()
3720 return clk; in clk_hw_create_clk()
3721 clk->dev = dev; in clk_hw_create_clk()
3723 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
3724 free_clk(clk); in clk_hw_create_clk()
3725 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
3728 kref_get(&core->ref); in clk_hw_create_clk()
3729 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
3731 return clk; in clk_hw_create_clk()
3740 return -EINVAL; in clk_cpy_name()
3746 return -ENOMEM; in clk_cpy_name()
3754 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
3755 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
3756 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
3757 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
3765 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
3769 core->parents = parents; in clk_core_populate_parent_map()
3771 return -ENOMEM; in clk_core_populate_parent_map()
3775 parent->index = -1; in clk_core_populate_parent_map()
3780 __func__, core->name); in clk_core_populate_parent_map()
3781 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
3784 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
3785 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
3786 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
3789 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
3793 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
3795 ret = -EINVAL; in clk_core_populate_parent_map()
3803 } while (--i >= 0); in clk_core_populate_parent_map()
3815 int i = core->num_parents; in clk_core_free_parent_map()
3817 if (!core->num_parents) in clk_core_free_parent_map()
3820 while (--i >= 0) { in clk_core_free_parent_map()
3821 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
3822 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
3825 kfree(core->parents); in clk_core_free_parent_map()
3828 static struct clk *
3833 const struct clk_init_data *init = hw->init; in __clk_register()
3838 * we catch use of hw->init early on in the core. in __clk_register()
3840 hw->init = NULL; in __clk_register()
3844 ret = -ENOMEM; in __clk_register()
3848 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
3849 if (!core->name) { in __clk_register()
3850 ret = -ENOMEM; in __clk_register()
3854 if (WARN_ON(!init->ops)) { in __clk_register()
3855 ret = -EINVAL; in __clk_register()
3858 core->ops = init->ops; in __clk_register()
3861 core->rpm_enabled = true; in __clk_register()
3862 core->dev = dev; in __clk_register()
3863 core->of_node = np; in __clk_register()
3864 if (dev && dev->driver) in __clk_register()
3865 core->owner = dev->driver->owner; in __clk_register()
3866 core->hw = hw; in __clk_register()
3867 core->flags = init->flags; in __clk_register()
3868 core->num_parents = init->num_parents; in __clk_register()
3869 core->min_rate = 0; in __clk_register()
3870 core->max_rate = ULONG_MAX; in __clk_register()
3876 INIT_HLIST_HEAD(&core->clks); in __clk_register()
3882 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
3883 if (IS_ERR(hw->clk)) { in __clk_register()
3884 ret = PTR_ERR(hw->clk); in __clk_register()
3888 clk_core_link_consumer(core, hw->clk); in __clk_register()
3892 return hw->clk; in __clk_register()
3895 clk_core_unlink_consumer(hw->clk); in __clk_register()
3898 free_clk(hw->clk); in __clk_register()
3899 hw->clk = NULL; in __clk_register()
3905 kfree_const(core->name); in __clk_register()
3913 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
3917 * @dev->parent if dev doesn't have a device node, or NULL if neither
3918 * @dev or @dev->parent have a device node.
3929 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
3935 * clk_register - allocate a new clock, register it and return an opaque cookie
3937 * @hw: link to hardware-specific clock data
3942 * Returns: a pointer to the newly allocated struct clk which
3947 struct clk *clk_register(struct device *dev, struct clk_hw *hw) in clk_register()
3954 * clk_hw_register - register a clk_hw and return an error code
3956 * @hw: link to hardware-specific clock data
3971 * of_clk_hw_register - register a clk_hw and return an error code
3973 * @hw: link to hardware-specific clock data
3995 kfree_const(core->name); in __clk_release()
4002 * consumer calls clk_put() and the struct clk object is freed.
4006 return -ENXIO; in clk_nodrv_prepare_enable()
4017 return -ENXIO; in clk_nodrv_set_rate()
4022 return -ENXIO; in clk_nodrv_set_parent()
4040 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
4041 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4042 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4044 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
4048 /* Remove this clk from all parent caches */
4063 * clk_unregister - unregister a currently registered clock
4064 * @clk: clock to unregister
4066 void clk_unregister(struct clk *clk) in clk_unregister() argument
4071 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in clk_unregister()
4074 clk_debug_unregister(clk->core); in clk_unregister()
4078 ops = clk->core->ops; in clk_unregister()
4081 clk->core->name); in clk_unregister()
4089 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4092 if (ops->terminate) in clk_unregister()
4093 ops->terminate(clk->core->hw); in clk_unregister()
4095 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4100 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4105 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4107 hlist_del_init(&clk->core->child_node); in clk_unregister()
4109 if (clk->core->prepare_count) in clk_unregister()
4111 __func__, clk->core->name); in clk_unregister()
4113 if (clk->core->protect_count) in clk_unregister()
4115 __func__, clk->core->name); in clk_unregister()
4117 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4118 free_clk(clk); in clk_unregister()
4125 * clk_hw_unregister - unregister a currently registered clk_hw
4126 * @hw: hardware-specific clock data to unregister
4130 clk_unregister(hw->clk); in clk_hw_unregister()
4136 clk_unregister(*(struct clk **)res); in devm_clk_release()
4145 * devm_clk_register - resource managed clk_register()
4147 * @hw: link to hardware-specific clock data
4154 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw) in devm_clk_register()
4156 struct clk *clk; in devm_clk_register() local
4157 struct clk **clkp; in devm_clk_register()
4161 return ERR_PTR(-ENOMEM); in devm_clk_register()
4163 clk = clk_register(dev, hw); in devm_clk_register()
4164 if (!IS_ERR(clk)) { in devm_clk_register()
4165 *clkp = clk; in devm_clk_register()
4171 return clk; in devm_clk_register()
4176 * devm_clk_hw_register - resource managed clk_hw_register()
4178 * @hw: link to hardware-specific clock data
4191 return -ENOMEM; in devm_clk_hw_register()
4207 struct clk *c = res; in devm_clk_match()
4223 * devm_clk_unregister - resource managed clk_unregister()
4225 * @clk: clock to unregister
4231 void devm_clk_unregister(struct device *dev, struct clk *clk) in devm_clk_unregister() argument
4233 WARN_ON(devres_release(dev, devm_clk_release, devm_clk_match, clk)); in devm_clk_unregister()
4238 * devm_clk_hw_unregister - resource managed clk_hw_unregister()
4239 * @dev: device that is unregistering the hardware-specific clock data
4240 * @hw: link to hardware-specific clock data
4257 void __clk_put(struct clk *clk) in __clk_put() argument
4261 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in __clk_put()
4271 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4273 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4274 clk_core_rate_unprotect(clk->core); in __clk_put()
4275 clk->exclusive_count = 0; in __clk_put()
4278 hlist_del(&clk->clks_node); in __clk_put()
4279 if (clk->min_rate > clk->core->req_rate || in __clk_put()
4280 clk->max_rate < clk->core->req_rate) in __clk_put()
4281 clk_core_set_rate_nolock(clk->core, clk->core->req_rate); in __clk_put()
4283 owner = clk->core->owner; in __clk_put()
4284 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4290 free_clk(clk); in __clk_put()
4293 /*** clk rate change notifiers ***/
4296 * clk_notifier_register - add a clk rate change notifier
4297 * @clk: struct clk * to watch
4300 * Request notification when clk's rate changes. This uses an SRCU
4303 * re-enter into the clk framework by calling any top-level clk APIs;
4310 * clk_notifier_register() must be called from non-atomic context.
4311 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4315 int clk_notifier_register(struct clk *clk, struct notifier_block *nb) in clk_notifier_register() argument
4318 int ret = -ENOMEM; in clk_notifier_register()
4320 if (!clk || !nb) in clk_notifier_register()
4321 return -EINVAL; in clk_notifier_register()
4325 /* search the list of notifiers for this clk */ in clk_notifier_register()
4327 if (cn->clk == clk) in clk_notifier_register()
4330 /* if clk wasn't in the notifier list, allocate new clk_notifier */ in clk_notifier_register()
4335 cn->clk = clk; in clk_notifier_register()
4336 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4338 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4341 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4343 clk->core->notifier_count++; in clk_notifier_register()
4353 * clk_notifier_unregister - remove a clk rate change notifier
4354 * @clk: struct clk *
4357 * Request no further notification for changes to 'clk' and frees memory
4360 * Returns -EINVAL if called with null arguments; otherwise, passes
4363 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb) in clk_notifier_unregister() argument
4366 int ret = -ENOENT; in clk_notifier_unregister()
4368 if (!clk || !nb) in clk_notifier_unregister()
4369 return -EINVAL; in clk_notifier_unregister()
4374 if (cn->clk == clk) { in clk_notifier_unregister()
4375 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4377 clk->core->notifier_count--; in clk_notifier_unregister()
4380 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4381 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4382 list_del(&cn->node); in clk_notifier_unregister()
4404 * struct of_clk_provider - Clock provider registration structure
4407 * @get: Get clock callback. Returns NULL or a struct clk for the
4417 struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
4429 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec, in of_clk_src_simple_get()
4442 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) in of_clk_src_onecell_get()
4445 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4447 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4449 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4452 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4460 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4462 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4464 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4467 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4472 * of_clk_add_provider() - Register a clock provider for a node
4480 struct clk *(*clk_src_get)(struct of_phandle_args *clkspec, in of_clk_add_provider()
4489 return -ENOMEM; in of_clk_add_provider()
4491 cp->node = of_node_get(np); in of_clk_add_provider()
4492 cp->data = data; in of_clk_add_provider()
4493 cp->get = clk_src_get; in of_clk_add_provider()
4496 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
4511 * of_clk_add_hw_provider() - Register a clock provider for a node
4526 return -ENOMEM; in of_clk_add_hw_provider()
4528 cp->node = of_node_get(np); in of_clk_add_hw_provider()
4529 cp->data = data; in of_clk_add_hw_provider()
4530 cp->get_hw = get; in of_clk_add_hw_provider()
4533 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
4554 * for cases like MFD sub-devices where the child device driver wants to use
4555 * devm_*() APIs but not list the device in DT as a sub-node.
4561 np = dev->of_node; in get_clk_provider_node()
4562 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
4564 if (!of_find_property(np, "#clock-cells", NULL)) in get_clk_provider_node()
4565 if (of_find_property(parent_np, "#clock-cells", NULL)) in get_clk_provider_node()
4572 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
4578 * node or if the device node lacks of clock provider information (#clock-cells)
4580 * has the #clock-cells then it is used in registration. Provider is
4596 return -ENOMEM; in devm_of_clk_add_hw_provider()
4612 * of_clk_del_provider() - Remove a previously registered clock provider
4621 if (cp->node == np) { in of_clk_del_provider()
4622 list_del(&cp->link); in of_clk_del_provider()
4623 of_node_put(cp->node); in of_clk_del_provider()
4643 * devm_of_clk_del_provider() - Remove clock provider registered using devm
4659 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
4665 * Parses a device node's "clocks" and "clock-names" properties to find the
4668 * parsing error. The @index argument is ignored if @name is non-NULL.
4672 * phandle1: clock-controller@1 {
4673 * #clock-cells = <2>;
4676 * phandle2: clock-controller@2 {
4677 * #clock-cells = <1>;
4680 * clock-consumer@3 {
4682 * clock-names = "name1", "name2";
4685 * To get a device_node for `clock-controller@2' node you may call this
4688 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
4689 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
4690 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
4692 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
4693 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
4694 * the "clock-names" property of @np.
4699 int ret = -ENOENT; in of_parse_clkspec()
4705 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
4707 * return -EINVAL. in of_parse_clkspec()
4710 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
4711 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
4720 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
4723 np = np->parent; in of_parse_clkspec()
4724 if (np && !of_get_property(np, "clock-ranges", NULL)) in of_parse_clkspec()
4736 struct clk *clk; in __of_clk_get_hw_from_provider() local
4738 if (provider->get_hw) in __of_clk_get_hw_from_provider()
4739 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
4741 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
4742 if (IS_ERR(clk)) in __of_clk_get_hw_from_provider()
4743 return ERR_CAST(clk); in __of_clk_get_hw_from_provider()
4744 return __clk_get_hw(clk); in __of_clk_get_hw_from_provider()
4751 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
4754 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
4758 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
4770 * of_clk_get_from_provider() - Lookup a clock from a clock provider
4773 * This function looks up a struct clk from the registered list of clock
4777 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) in of_clk_get_from_provider()
4802 static struct clk *__of_clk_get(struct device_node *np, in __of_clk_get()
4811 struct clk *of_clk_get(struct device_node *np, int index) in of_clk_get()
4813 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
4818 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
4822 * This function parses the clocks and clock-names properties,
4823 * and uses them to look up the struct clk from the registered list of clock
4826 struct clk *of_clk_get_by_name(struct device_node *np, const char *name) in of_clk_get_by_name()
4829 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
4831 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
4836 * of_clk_get_parent_count() - Count the number of clocks a device node has
4845 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
4862 struct clk *clk; in of_clk_get_parent_name() local
4864 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
4873 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
4875 of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) { in of_clk_get_parent_name()
4882 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
4886 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
4893 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
4895 clk = of_clk_get_from_provider(&clkspec); in of_clk_get_parent_name()
4896 if (IS_ERR(clk)) { in of_clk_get_parent_name()
4898 clk_name = clkspec.np->name; in of_clk_get_parent_name()
4902 clk_name = __clk_get_name(clk); in of_clk_get_parent_name()
4903 clk_put(clk); in of_clk_get_parent_name()
4914 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
4950 struct clk *clk = of_clk_get(np, i); in parent_ready() local
4953 if (!IS_ERR(clk)) { in parent_ready()
4954 clk_put(clk); in parent_ready()
4960 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
4976 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
4979 * @flags: pointer to top-level framework flags
4981 * Detects if the clock-critical property exists and, if so, sets the
4985 * bindings, such as the one-clock-per-node style that are outdated.
5001 return -EINVAL; in of_clk_detect_critical()
5003 of_property_for_each_u32(np, "clock-critical", prop, cur, idx) in of_clk_detect_critical()
5011 * of_clk_init() - Scan and init clock providers from the DT
5041 list_del(&clk_provider->node); in of_clk_init()
5042 of_node_put(clk_provider->np); in of_clk_init()
5049 parent->clk_init_cb = match->data; in of_clk_init()
5050 parent->np = of_node_get(np); in of_clk_init()
5051 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5058 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5061 of_node_set_flag(clk_provider->np, in of_clk_init()
5064 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5065 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5067 list_del(&clk_provider->node); in of_clk_init()
5068 of_node_put(clk_provider->np); in of_clk_init()