• Home
  • Raw
  • Download

Lines Matching +full:clock +full:- +full:accuracy

2  * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
3 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
9 * Standard functionality for the common clock API. See Documentation/driver-api/clk.rst
13 #include <linux/clk-provider.h>
14 #include <linux/clk/clk-conf.h>
79 unsigned long accuracy; member
111 if (!core->dev) in clk_pm_runtime_get()
114 ret = pm_runtime_get_sync(core->dev); in clk_pm_runtime_get()
116 pm_runtime_put_noidle(core->dev); in clk_pm_runtime_get()
124 if (!core->dev) in clk_pm_runtime_put()
127 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
151 if (--prepare_refcnt) in clk_prepare_unlock()
191 if (--enable_refcnt) { in clk_enable_unlock()
201 return core->protect_count; in clk_core_rate_is_protected()
212 if (!core->ops->is_prepared) in clk_core_is_prepared()
213 return core->prepare_count; in clk_core_is_prepared()
216 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
231 if (!core->ops->is_enabled) in clk_core_is_enabled()
232 return core->enable_count; in clk_core_is_enabled()
235 * Check if clock controller's device is runtime active before in clk_core_is_enabled()
236 * calling .is_enabled callback. If not, assume that clock is in clk_core_is_enabled()
244 if (core->dev) { in clk_core_is_enabled()
245 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
246 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
252 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
254 if (core->dev) in clk_core_is_enabled()
255 pm_runtime_put(core->dev); in clk_core_is_enabled()
264 return !clk ? NULL : clk->core->name; in __clk_get_name()
270 return hw->core->name; in clk_hw_get_name()
276 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
282 return hw->core->num_parents; in clk_hw_get_num_parents()
288 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
298 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
301 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
338 if (!core || index >= core->num_parents) in clk_core_get_parent_by_index()
341 if (!core->parents[index]) in clk_core_get_parent_by_index()
342 core->parents[index] = in clk_core_get_parent_by_index()
343 clk_core_lookup(core->parent_names[index]); in clk_core_get_parent_by_index()
345 return core->parents[index]; in clk_core_get_parent_by_index()
353 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
355 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
361 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
373 ret = core->rate; in clk_core_get_rate_nolock()
375 if (!core->num_parents) in clk_core_get_rate_nolock()
378 if (!core->parent) in clk_core_get_rate_nolock()
387 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
396 return core->accuracy; in __clk_get_accuracy()
401 return !clk ? 0 : clk->core->flags; in __clk_get_flags()
407 return hw->core->flags; in clk_hw_get_flags()
413 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
418 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
423 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
431 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
439 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
448 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags()
454 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
455 parent = core->parent; in clk_mux_determine_rate_flags()
456 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
457 ret = __clk_determine_rate(parent ? parent->hw : NULL, in clk_mux_determine_rate_flags()
473 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
479 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
481 ret = __clk_determine_rate(parent->hw, &parent_req); in clk_mux_determine_rate_flags()
488 if (mux_is_better_rate(req->rate, parent_req.rate, in clk_mux_determine_rate_flags()
496 return -EINVAL; in clk_mux_determine_rate_flags()
500 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
501 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
502 req->rate = best; in clk_mux_determine_rate_flags()
512 return !core ? NULL : core->hw->clk; in __clk_lookup()
521 *min_rate = core->min_rate; in clk_core_get_boundaries()
522 *max_rate = core->max_rate; in clk_core_get_boundaries()
524 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
525 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
527 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
528 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
534 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
535 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
542 * complex clock that may combine a mux with other operations.
567 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
568 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
571 if (--core->protect_count > 0) in clk_core_rate_unprotect()
574 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
584 return -EINVAL; in clk_core_rate_nuke_protect()
586 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
589 ret = core->protect_count; in clk_core_rate_nuke_protect()
590 core->protect_count = 1; in clk_core_rate_nuke_protect()
597 * clk_rate_exclusive_put - release exclusivity over clock rate control
600 * clk_rate_exclusive_put() completes a critical section during which a clock
602 * clock which could result in a rate change or rate glitch. Exclusive clocks
607 * If exlusivity is claimed more than once on clock, even by the same consumer,
625 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
628 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
629 clk->exclusive_count--; in clk_rate_exclusive_put()
642 if (core->protect_count == 0) in clk_core_rate_protect()
643 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
645 core->protect_count++; in clk_core_rate_protect()
659 core->protect_count = count; in clk_core_rate_restore_protect()
663 * clk_rate_exclusive_get - get exclusivity over the clk rate control
666 * clk_rate_exlusive_get() begins a critical section during which a clock
668 * clock which could result in a rate change or rate glitch. Exclusive clocks
673 * If exlusivity is claimed more than once on clock, even by the same consumer,
678 * Returns 0 on success, -EERROR otherwise
686 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
687 clk->exclusive_count++; in clk_rate_exclusive_get()
701 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
702 "%s already unprepared\n", core->name)) in clk_core_unprepare()
705 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
706 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
709 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
712 if (--core->prepare_count > 0) in clk_core_unprepare()
715 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
719 if (core->ops->unprepare) in clk_core_unprepare()
720 core->ops->unprepare(core->hw); in clk_core_unprepare()
725 clk_core_unprepare(core->parent); in clk_core_unprepare()
736 * clk_unprepare - undo preparation of a clock source
751 clk_core_unprepare_lock(clk->core); in clk_unprepare()
764 if (core->prepare_count == 0) { in clk_core_prepare()
769 ret = clk_core_prepare(core->parent); in clk_core_prepare()
775 if (core->ops->prepare) in clk_core_prepare()
776 ret = core->ops->prepare(core->hw); in clk_core_prepare()
784 core->prepare_count++; in clk_core_prepare()
787 * CLK_SET_RATE_GATE is a special case of clock protection in clk_core_prepare()
791 * the clock is prepared. in clk_core_prepare()
793 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
798 clk_core_unprepare(core->parent); in clk_core_prepare()
816 * clk_prepare - prepare a clock source
825 * Returns 0 on success, -EERROR otherwise.
832 return clk_core_prepare_lock(clk->core); in clk_prepare()
843 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
846 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
847 "Disabling critical %s\n", core->name)) in clk_core_disable()
850 if (--core->enable_count > 0) in clk_core_disable()
855 if (core->ops->disable) in clk_core_disable()
856 core->ops->disable(core->hw); in clk_core_disable()
860 clk_core_disable(core->parent); in clk_core_disable()
873 * clk_disable - gate a clock
879 * SoC-internal clk which is controlled via simple register writes. In the
889 clk_core_disable_lock(clk->core); in clk_disable()
902 if (WARN(core->prepare_count == 0, in clk_core_enable()
903 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
904 return -ESHUTDOWN; in clk_core_enable()
906 if (core->enable_count == 0) { in clk_core_enable()
907 ret = clk_core_enable(core->parent); in clk_core_enable()
914 if (core->ops->enable) in clk_core_enable()
915 ret = core->ops->enable(core->hw); in clk_core_enable()
920 clk_core_disable(core->parent); in clk_core_enable()
925 core->enable_count++; in clk_core_enable()
942 * clk_enable - ungate a clock
947 * if the operation will never sleep. One example is a SoC-internal clk which
951 * must be called before clk_enable. Returns 0 on success, -EERROR
959 return clk_core_enable_lock(clk->core); in clk_enable()
990 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
993 if (core->prepare_count) in clk_unprepare_unused_subtree()
996 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1004 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1005 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1006 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1007 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1021 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1024 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1025 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1032 if (core->enable_count) in clk_disable_unused_subtree()
1035 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1039 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1045 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1046 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1047 else if (core->ops->disable) in clk_disable_unused_subtree()
1048 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1056 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1057 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1109 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1110 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1114 req->rate = core->rate; in clk_core_determine_round_nolock()
1115 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1116 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1117 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1118 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1119 &req->best_parent_rate); in clk_core_determine_round_nolock()
1123 req->rate = rate; in clk_core_determine_round_nolock()
1125 return -EINVAL; in clk_core_determine_round_nolock()
1139 parent = core->parent; in clk_core_init_rate_req()
1141 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1142 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1144 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1145 req->best_parent_rate = 0; in clk_core_init_rate_req()
1151 if (core->ops->determine_rate || core->ops->round_rate) in clk_core_can_round()
1163 req->rate = 0; in clk_core_round_rate_nolock()
1171 else if (core->flags & CLK_SET_RATE_PARENT) in clk_core_round_rate_nolock()
1172 return clk_core_round_rate_nolock(core->parent, req); in clk_core_round_rate_nolock()
1174 req->rate = core->rate; in clk_core_round_rate_nolock()
1179 * __clk_determine_rate - get the closest rate actually supported by a clock
1180 * @hw: determine the rate of this clock
1188 req->rate = 0; in __clk_determine_rate()
1192 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1201 clk_core_get_boundaries(hw->core, &req.min_rate, &req.max_rate); in clk_hw_round_rate()
1204 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1213 * clk_round_rate - round the given rate for a clk
1231 if (clk->exclusive_count) in clk_round_rate()
1232 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1234 clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate); in clk_round_rate()
1237 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1239 if (clk->exclusive_count) in clk_round_rate()
1240 clk_core_rate_protect(clk->core); in clk_round_rate()
1252 * __clk_notify - call clk notifier chain
1258 * Triggers a notifier call chain on the clk rate-change notification
1261 * internal clock code only. Returns NOTIFY_DONE from the last driver
1276 if (cn->clk->core == core) { in __clk_notify()
1277 cnd.clk = cn->clk; in __clk_notify()
1278 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1294 * callback then it is assumed that the clock will take on the accuracy of its
1304 if (core->parent) in __clk_recalc_accuracies()
1305 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1307 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1308 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1311 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1313 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1319 unsigned long accuracy; in clk_core_get_accuracy() local
1322 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy()
1325 accuracy = __clk_get_accuracy(core); in clk_core_get_accuracy()
1328 return accuracy; in clk_core_get_accuracy()
1332 * clk_get_accuracy - return the accuracy of clk
1333 * @clk: the clk whose accuracy is being returned
1335 * Simply returns the cached accuracy of the clk, unless
1345 return clk_core_get_accuracy(clk->core); in clk_get_accuracy()
1354 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1355 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1368 * it is assumed that the clock will take on the rate of its parent.
1381 old_rate = core->rate; in __clk_recalc_rates()
1383 if (core->parent) in __clk_recalc_rates()
1384 parent_rate = core->parent->rate; in __clk_recalc_rates()
1386 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1392 if (core->notifier_count && msg) in __clk_recalc_rates()
1393 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1395 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1405 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate()
1415 * clk_get_rate - return the rate of clk
1427 return clk_core_get_rate(clk->core); in clk_get_rate()
1437 return -EINVAL; in clk_fetch_parent_index()
1439 for (i = 0; i < core->num_parents; i++) in clk_fetch_parent_index()
1443 return -EINVAL; in clk_fetch_parent_index()
1453 core->orphan = is_orphan; in clk_core_update_orphan_status()
1455 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1461 bool was_orphan = core->orphan; in clk_reparent()
1463 hlist_del(&core->child_node); in clk_reparent()
1466 bool becomes_orphan = new_parent->orphan; in clk_reparent()
1469 if (new_parent->new_child == core) in clk_reparent()
1470 new_parent->new_child = NULL; in clk_reparent()
1472 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1477 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1482 core->parent = new_parent; in clk_reparent()
1489 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1492 * 1. enable parents for CLK_OPS_PARENT_ENABLE clock in __clk_set_parent_before()
1497 * If the clock is not prepared, then a race with in __clk_set_parent_before()
1502 * If the clock is prepared, migrate the prepared state to the new in __clk_set_parent_before()
1504 * forcing the clock and the new parent on. This ensures that all in __clk_set_parent_before()
1512 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
1518 if (core->prepare_count) { in __clk_set_parent_before()
1539 if (core->prepare_count) { in __clk_set_parent_after()
1544 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
1545 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
1562 /* change clock input source */ in __clk_set_parent()
1563 if (parent && core->ops->set_parent) in __clk_set_parent()
1564 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
1591 * pre-rate change notifications and returns early if no clks in the
1593 * implement the .recalc_rate callback then it is assumed that the clock will
1608 if (core->notifier_count) in __clk_speculate_rates()
1609 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
1612 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
1613 __func__, core->name, ret); in __clk_speculate_rates()
1617 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
1632 core->new_rate = new_rate; in clk_calc_subtree()
1633 core->new_parent = new_parent; in clk_calc_subtree()
1634 core->new_parent_index = p_index; in clk_calc_subtree()
1636 core->new_child = NULL; in clk_calc_subtree()
1637 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
1638 new_parent->new_child = core; in clk_calc_subtree()
1640 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
1641 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
1642 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
1647 * calculate the new rates returning the topmost clock that has to be
1667 parent = old_parent = core->parent; in clk_calc_new_rates()
1669 best_parent_rate = parent->rate; in clk_calc_new_rates()
1689 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
1693 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
1694 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
1695 core->new_rate = core->rate; in clk_calc_new_rates()
1698 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
1700 new_rate = parent->new_rate; in clk_calc_new_rates()
1706 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
1708 __func__, core->name); in clk_calc_new_rates()
1713 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
1717 __func__, parent->name, core->name); in clk_calc_new_rates()
1722 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
1723 best_parent_rate != parent->rate) in clk_calc_new_rates()
1743 if (core->rate == core->new_rate) in clk_propagate_rate_change()
1746 if (core->notifier_count) { in clk_propagate_rate_change()
1747 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
1752 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
1753 /* Skip children who will be reparented to another clock */ in clk_propagate_rate_change()
1754 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
1761 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
1762 if (core->new_child) { in clk_propagate_rate_change()
1763 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
1785 old_rate = core->rate; in clk_change_rate()
1787 if (core->new_parent) { in clk_change_rate()
1788 parent = core->new_parent; in clk_change_rate()
1789 best_parent_rate = core->new_parent->rate; in clk_change_rate()
1790 } else if (core->parent) { in clk_change_rate()
1791 parent = core->parent; in clk_change_rate()
1792 best_parent_rate = core->parent->rate; in clk_change_rate()
1798 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
1807 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
1808 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
1809 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
1811 if (core->ops->set_rate_and_parent) { in clk_change_rate()
1813 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
1815 core->new_parent_index); in clk_change_rate()
1816 } else if (core->ops->set_parent) { in clk_change_rate()
1817 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
1820 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
1821 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
1824 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
1827 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
1829 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
1830 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
1832 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
1834 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
1836 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
1845 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
1848 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
1849 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
1851 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
1852 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
1856 * for certain clock types. in clk_change_rate()
1858 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
1859 /* Skip children who will be reparented to another clock */ in clk_change_rate()
1860 if (child->new_parent && child->new_parent != core) in clk_change_rate()
1865 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
1866 if (core->new_child) in clk_change_rate()
1867 clk_change_rate(core->new_child); in clk_change_rate()
1917 return -EBUSY; in clk_core_set_rate_nolock()
1919 /* calculate new rates and get the topmost changed clock */ in clk_core_set_rate_nolock()
1922 return -EINVAL; in clk_core_set_rate_nolock()
1932 fail_clk->name); in clk_core_set_rate_nolock()
1934 ret = -EBUSY; in clk_core_set_rate_nolock()
1941 core->req_rate = req_rate; in clk_core_set_rate_nolock()
1949 * clk_set_rate - specify a new rate for clk
1967 * Returns 0 on success, -EERROR otherwise.
1976 /* prevent racing with updates to the clock topology */ in clk_set_rate()
1979 if (clk->exclusive_count) in clk_set_rate()
1980 clk_core_rate_unprotect(clk->core); in clk_set_rate()
1982 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
1984 if (clk->exclusive_count) in clk_set_rate()
1985 clk_core_rate_protect(clk->core); in clk_set_rate()
1994 * clk_set_rate_exclusive - specify a new rate get exclusive control
2003 * same clock provider.
2010 * Returns 0 on success, -EERROR otherwise.
2019 /* prevent racing with updates to the clock topology */ in clk_set_rate_exclusive()
2025 * so before the consumer code path protect the clock provider in clk_set_rate_exclusive()
2028 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2030 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2031 clk->exclusive_count++; in clk_set_rate_exclusive()
2041 * clk_set_rate_range - set a rate range for a clock source
2042 * @clk: clock source
2043 * @min: desired minimum clock rate in Hz, inclusive
2044 * @max: desired maximum clock rate in Hz, inclusive
2058 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range()
2060 return -EINVAL; in clk_set_rate_range()
2065 if (clk->exclusive_count) in clk_set_rate_range()
2066 clk_core_rate_unprotect(clk->core); in clk_set_rate_range()
2069 old_min = clk->min_rate; in clk_set_rate_range()
2070 old_max = clk->max_rate; in clk_set_rate_range()
2071 clk->min_rate = min; in clk_set_rate_range()
2072 clk->max_rate = max; in clk_set_rate_range()
2074 rate = clk_core_get_rate_nolock(clk->core); in clk_set_rate_range()
2081 * usual reason (clock broken, clock protected, etc) but also in clk_set_rate_range()
2083 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range()
2085 * - the determine_rate() callback does not really check for in clk_set_rate_range()
2094 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range()
2097 clk->min_rate = old_min; in clk_set_rate_range()
2098 clk->max_rate = old_max; in clk_set_rate_range()
2102 if (clk->exclusive_count) in clk_set_rate_range()
2103 clk_core_rate_protect(clk->core); in clk_set_rate_range()
2112 * clk_set_min_rate - set a minimum clock rate for a clock source
2113 * @clk: clock source
2114 * @rate: desired minimum clock rate in Hz, inclusive
2123 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2128 * clk_set_max_rate - set a maximum clock rate for a clock source
2129 * @clk: clock source
2130 * @rate: desired maximum clock rate in Hz, inclusive
2139 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2144 * clk_get_parent - return the parent of a clk
2147 * Simply returns clk->parent. Returns NULL if clk is NULL.
2157 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2158 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2169 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2170 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2188 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2192 * clk_has_parent - check if a clock is a possible parent for another
2193 * @clk: clock source
2194 * @parent: parent clock source
2196 * This function can be used in drivers that need to check that a clock can be
2209 core = clk->core; in clk_has_parent()
2210 parent_core = parent->core; in clk_has_parent()
2213 if (core->parent == parent_core) in clk_has_parent()
2216 return match_string(core->parent_names, core->num_parents, in clk_has_parent()
2217 parent_core->name) >= 0; in clk_has_parent()
2233 if (core->parent == parent) in clk_core_set_parent_nolock()
2236 /* verify ops for for multi-parent clks */ in clk_core_set_parent_nolock()
2237 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2238 return -EPERM; in clk_core_set_parent_nolock()
2240 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2241 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2242 return -EBUSY; in clk_core_set_parent_nolock()
2245 return -EBUSY; in clk_core_set_parent_nolock()
2252 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2255 p_rate = parent->rate; in clk_core_set_parent_nolock()
2269 /* do the re-parent */ in clk_core_set_parent_nolock()
2272 /* propagate rate an accuracy recalculation accordingly */ in clk_core_set_parent_nolock()
2287 * clk_set_parent - switch the parent of a mux clk
2291 * Re-parent clk to use parent as its new input source. If clk is in
2301 * Returns 0 on success, -EERROR otherwise.
2312 if (clk->exclusive_count) in clk_set_parent()
2313 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2315 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2316 parent ? parent->core : NULL); in clk_set_parent()
2318 if (clk->exclusive_count) in clk_set_parent()
2319 clk_core_rate_protect(clk->core); in clk_set_parent()
2329 int ret = -EINVAL; in clk_core_set_phase_nolock()
2337 return -EBUSY; in clk_core_set_phase_nolock()
2341 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2342 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2344 core->phase = degrees; in clk_core_set_phase_nolock()
2353 * clk_set_phase - adjust the phase shift of a clock signal
2354 * @clk: clock signal source
2357 * Shifts the phase of a clock signal by the specified
2358 * degrees. Returns 0 on success, -EERROR otherwise.
2361 * signal that we adjust the clock signal phase against. For example
2362 * phase locked-loop clock signal generators we may shift phase with
2363 * respect to feedback clock signal input, but for other cases the
2364 * clock phase may be shifted with respect to some other, unspecified
2368 * the clock tree hierarchy, which sets it apart from clock rates and
2369 * clock accuracy. A parent clock phase attribute does not have an
2370 * impact on the phase attribute of a child clock.
2386 if (clk->exclusive_count) in clk_set_phase()
2387 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2389 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2391 if (clk->exclusive_count) in clk_set_phase()
2392 clk_core_rate_protect(clk->core); in clk_set_phase()
2406 if (core->ops->get_phase) in clk_core_get_phase()
2407 core->phase = core->ops->get_phase(core->hw); in clk_core_get_phase()
2408 ret = core->phase; in clk_core_get_phase()
2415 * clk_get_phase - return the phase shift of a clock signal
2416 * @clk: clock signal source
2418 * Returns the phase shift of a clock node in degrees, otherwise returns
2419 * -EERROR.
2426 return clk_core_get_phase(clk->core); in clk_get_phase()
2433 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2434 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2441 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2444 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2447 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2451 /* Don't trust the clock provider too much */ in clk_core_update_duty_cycle_nolock()
2452 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
2453 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
2468 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2469 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2470 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2471 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2490 return -EBUSY; in clk_core_set_duty_cycle_nolock()
2494 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
2497 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
2499 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
2511 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
2512 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
2513 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
2514 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
2521 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
2522 * @clk: clock signal source
2526 * Apply the duty cycle ratio if the ratio is valid and the clock can
2541 return -EINVAL; in clk_set_duty_cycle()
2548 if (clk->exclusive_count) in clk_set_duty_cycle()
2549 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
2551 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
2553 if (clk->exclusive_count) in clk_set_duty_cycle()
2554 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
2565 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
2572 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
2580 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
2581 * @clk: clock signal source
2584 * Returns the duty cycle ratio of a clock node multiplied by the provided
2592 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
2597 * clk_is_match - check if two clk's point to the same hardware clock
2602 * clock node. Put differently, returns true if struct clk *p and struct clk *q
2613 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
2615 if (p->core == q->core) in clk_is_match()
2638 seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu %5d %6d\n", in clk_summary_show_one()
2640 30 - level * 3, c->name, in clk_summary_show_one()
2641 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
2657 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
2664 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_summary_show()
2667 …seq_puts(s, " clock count count count rate accuracy phas… in clk_summary_show()
2668 …seq_puts(s, "-------------------------------------------------------------------------------------… in clk_summary_show()
2688 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
2689 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
2690 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
2691 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
2693 seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy(c)); in clk_dump_one()
2708 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
2720 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_dump_show()
2764 struct clk_core *core = s->private; in clk_flags_show()
2765 unsigned long flags = core->flags; in clk_flags_show()
2785 struct clk_core *core = s->private; in possible_parents_show()
2788 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
2789 seq_printf(s, "%s ", core->parent_names[i]); in possible_parents_show()
2791 seq_printf(s, "%s\n", core->parent_names[i]); in possible_parents_show()
2799 struct clk_core *core = s->private; in clk_duty_cycle_show()
2800 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
2802 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
2815 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
2816 core->dentry = root; in clk_debug_create_one()
2818 debugfs_create_ulong("clk_rate", 0444, root, &core->rate); in clk_debug_create_one()
2819 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
2820 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
2822 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
2823 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
2824 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
2825 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
2829 if (core->num_parents > 1) in clk_debug_create_one()
2833 if (core->ops->debug_init) in clk_debug_create_one()
2834 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
2838 * clk_debug_register - add a clk node to the debugfs clk directory
2848 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
2855 * clk_debug_unregister - remove a clk node from the debugfs clk directory
2859 * debugfs clk directory if clk->dentry points to debugfs created by
2865 hlist_del_init(&core->debug_node); in clk_debug_unregister()
2866 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
2867 core->dentry = NULL; in clk_debug_unregister()
2872 * clk_debug_init - lazily populate the debugfs clk directory
2876 * populates the debugfs clk directory once at boot-time when we know that
2877 * debugfs is setup. It should only be called once at boot-time, all other clks
2917 * __clk_core_init - initialize the data structures in a struct clk_core
2931 return -EINVAL; in __clk_core_init()
2939 /* check to see if a clock with this name is already registered */ in __clk_core_init()
2940 if (clk_core_lookup(core->name)) { in __clk_core_init()
2942 __func__, core->name); in __clk_core_init()
2943 ret = -EEXIST; in __clk_core_init()
2947 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
2948 if (core->ops->set_rate && in __clk_core_init()
2949 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
2950 core->ops->recalc_rate)) { in __clk_core_init()
2952 __func__, core->name); in __clk_core_init()
2953 ret = -EINVAL; in __clk_core_init()
2957 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
2959 __func__, core->name); in __clk_core_init()
2960 ret = -EINVAL; in __clk_core_init()
2964 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
2966 __func__, core->name); in __clk_core_init()
2967 ret = -EINVAL; in __clk_core_init()
2971 if (core->ops->set_rate_and_parent && in __clk_core_init()
2972 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
2974 __func__, core->name); in __clk_core_init()
2975 ret = -EINVAL; in __clk_core_init()
2980 for (i = 0; i < core->num_parents; i++) in __clk_core_init()
2981 WARN(!core->parent_names[i], in __clk_core_init()
2983 __func__, core->name); in __clk_core_init()
2985 core->parent = __clk_init_parent(core); in __clk_core_init()
2988 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
2994 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
2997 if (core->parent) { in __clk_core_init()
2998 hlist_add_head(&core->child_node, in __clk_core_init()
2999 &core->parent->children); in __clk_core_init()
3000 core->orphan = core->parent->orphan; in __clk_core_init()
3001 } else if (!core->num_parents) { in __clk_core_init()
3002 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3003 core->orphan = false; in __clk_core_init()
3005 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3006 core->orphan = true; in __clk_core_init()
3010 * optional platform-specific magic in __clk_core_init()
3012 * The .init callback is not used by any of the basic clock types, but in __clk_core_init()
3017 if (core->ops->init) in __clk_core_init()
3018 core->ops->init(core->hw); in __clk_core_init()
3021 * Set clk's accuracy. The preferred method is to use in __clk_core_init()
3023 * fallback is to use the parent's accuracy. If a clock doesn't have a in __clk_core_init()
3024 * parent (or is orphaned) then accuracy is set to zero (perfect in __clk_core_init()
3025 * clock). in __clk_core_init()
3027 if (core->ops->recalc_accuracy) in __clk_core_init()
3028 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3029 __clk_get_accuracy(core->parent)); in __clk_core_init()
3030 else if (core->parent) in __clk_core_init()
3031 core->accuracy = core->parent->accuracy; in __clk_core_init()
3033 core->accuracy = 0; in __clk_core_init()
3038 * query the current clock phase, or just assume it's in phase. in __clk_core_init()
3040 if (core->ops->get_phase) in __clk_core_init()
3041 core->phase = core->ops->get_phase(core->hw); in __clk_core_init()
3043 core->phase = 0; in __clk_core_init()
3053 * parent's rate. If a clock doesn't have a parent (or is orphaned) in __clk_core_init()
3056 if (core->ops->recalc_rate) in __clk_core_init()
3057 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3058 clk_core_get_rate_nolock(core->parent)); in __clk_core_init()
3059 else if (core->parent) in __clk_core_init()
3060 rate = core->parent->rate; in __clk_core_init()
3063 core->rate = core->req_rate = rate; in __clk_core_init()
3070 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3096 * clock. This is important for CLK_IS_CRITICAL clocks, which in __clk_core_init()
3108 kref_init(&core->ref); in __clk_core_init()
3113 hlist_del_init(&core->child_node); in __clk_core_init()
3134 return ERR_PTR(-ENOMEM); in __clk_create_clk()
3136 clk->core = hw->core; in __clk_create_clk()
3137 clk->dev_id = dev_id; in __clk_create_clk()
3138 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in __clk_create_clk()
3139 clk->max_rate = ULONG_MAX; in __clk_create_clk()
3142 hlist_add_head(&clk->clks_node, &hw->core->clks); in __clk_create_clk()
3152 hlist_del(&clk->clks_node); in __clk_free_clk()
3155 kfree_const(clk->con_id); in __clk_free_clk()
3160 * clk_register - allocate a new clock, register it and return an opaque cookie
3161 * @dev: device that is registering this clock
3162 * @hw: link to hardware-specific clock data
3164 * clk_register is the primary interface for populating the clock tree with new
3165 * clock nodes. It returns a pointer to the newly allocated struct clk which
3167 * rest of the clock API. In the event of an error clk_register will return an
3177 ret = -ENOMEM; in clk_register()
3181 core->name = kstrdup_const(hw->init->name, GFP_KERNEL); in clk_register()
3182 if (!core->name) { in clk_register()
3183 ret = -ENOMEM; in clk_register()
3187 if (WARN_ON(!hw->init->ops)) { in clk_register()
3188 ret = -EINVAL; in clk_register()
3191 core->ops = hw->init->ops; in clk_register()
3194 core->dev = dev; in clk_register()
3195 if (dev && dev->driver) in clk_register()
3196 core->owner = dev->driver->owner; in clk_register()
3197 core->hw = hw; in clk_register()
3198 core->flags = hw->init->flags; in clk_register()
3199 core->num_parents = hw->init->num_parents; in clk_register()
3200 core->min_rate = 0; in clk_register()
3201 core->max_rate = ULONG_MAX; in clk_register()
3202 hw->core = core; in clk_register()
3205 core->parent_names = kcalloc(core->num_parents, sizeof(char *), in clk_register()
3208 if (!core->parent_names) { in clk_register()
3209 ret = -ENOMEM; in clk_register()
3215 for (i = 0; i < core->num_parents; i++) { in clk_register()
3216 core->parent_names[i] = kstrdup_const(hw->init->parent_names[i], in clk_register()
3218 if (!core->parent_names[i]) { in clk_register()
3219 ret = -ENOMEM; in clk_register()
3224 /* avoid unnecessary string look-ups of clk_core's possible parents. */ in clk_register()
3225 core->parents = kcalloc(core->num_parents, sizeof(*core->parents), in clk_register()
3227 if (!core->parents) { in clk_register()
3228 ret = -ENOMEM; in clk_register()
3232 INIT_HLIST_HEAD(&core->clks); in clk_register()
3234 hw->clk = __clk_create_clk(hw, NULL, NULL); in clk_register()
3235 if (IS_ERR(hw->clk)) { in clk_register()
3236 ret = PTR_ERR(hw->clk); in clk_register()
3242 return hw->clk; in clk_register()
3244 __clk_free_clk(hw->clk); in clk_register()
3245 hw->clk = NULL; in clk_register()
3248 kfree(core->parents); in clk_register()
3250 while (--i >= 0) in clk_register()
3251 kfree_const(core->parent_names[i]); in clk_register()
3252 kfree(core->parent_names); in clk_register()
3255 kfree_const(core->name); in clk_register()
3264 * clk_hw_register - register a clk_hw and return an error code
3265 * @dev: device that is registering this clock
3266 * @hw: link to hardware-specific clock data
3268 * clk_hw_register is the primary interface for populating the clock tree with
3269 * new clock nodes. It returns an integer equal to zero indicating success or
3279 /* Free memory allocated for a clock. */
3283 int i = core->num_parents; in __clk_release()
3287 kfree(core->parents); in __clk_release()
3288 while (--i >= 0) in __clk_release()
3289 kfree_const(core->parent_names[i]); in __clk_release()
3291 kfree(core->parent_names); in __clk_release()
3292 kfree_const(core->name); in __clk_release()
3298 * after clk_unregister() was called on a clock and until last clock
3303 return -ENXIO; in clk_nodrv_prepare_enable()
3314 return -ENXIO; in clk_nodrv_set_rate()
3319 return -ENXIO; in clk_nodrv_set_parent()
3337 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
3338 if (root->parents[i] == target) in clk_core_evict_parent_cache_subtree()
3339 root->parents[i] = NULL; in clk_core_evict_parent_cache_subtree()
3341 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
3360 * clk_unregister - unregister a currently registered clock
3361 * @clk: clock to unregister
3370 clk_debug_unregister(clk->core); in clk_unregister()
3374 if (clk->core->ops == &clk_nodrv_ops) { in clk_unregister()
3375 pr_err("%s: unregistered clock: %s\n", __func__, in clk_unregister()
3376 clk->core->name); in clk_unregister()
3380 * Assign empty clock ops for consumers that might still hold in clk_unregister()
3381 * a reference to this clock. in clk_unregister()
3384 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
3387 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
3392 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
3397 clk_core_evict_parent_cache(clk->core); in clk_unregister()
3399 hlist_del_init(&clk->core->child_node); in clk_unregister()
3401 if (clk->core->prepare_count) in clk_unregister()
3402 pr_warn("%s: unregistering prepared clock: %s\n", in clk_unregister()
3403 __func__, clk->core->name); in clk_unregister()
3405 if (clk->core->protect_count) in clk_unregister()
3406 pr_warn("%s: unregistering protected clock: %s\n", in clk_unregister()
3407 __func__, clk->core->name); in clk_unregister()
3409 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
3416 * clk_hw_unregister - unregister a currently registered clk_hw
3417 * @hw: hardware-specific clock data to unregister
3421 clk_unregister(hw->clk); in clk_hw_unregister()
3436 * devm_clk_register - resource managed clk_register()
3437 * @dev: device that is registering this clock
3438 * @hw: link to hardware-specific clock data
3451 return ERR_PTR(-ENOMEM); in devm_clk_register()
3466 * devm_clk_hw_register - resource managed clk_hw_register()
3467 * @dev: device that is registering this clock
3468 * @hw: link to hardware-specific clock data
3481 return -ENOMEM; in devm_clk_hw_register()
3513 * devm_clk_unregister - resource managed clk_unregister()
3514 * @clk: clock to unregister
3516 * Deallocate a clock allocated with devm_clk_register(). Normally
3527 * devm_clk_hw_unregister - resource managed clk_hw_unregister()
3528 * @dev: device that is unregistering the hardware-specific clock data
3529 * @hw: link to hardware-specific clock data
3547 struct clk_core *core = !clk ? NULL : clk->core; in __clk_get()
3550 if (!try_module_get(core->owner)) in __clk_get()
3553 kref_get(&core->ref); in __clk_get()
3573 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
3575 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
3576 clk_core_rate_unprotect(clk->core); in __clk_put()
3577 clk->exclusive_count = 0; in __clk_put()
3580 hlist_del(&clk->clks_node); in __clk_put()
3581 if (clk->min_rate > clk->core->req_rate || in __clk_put()
3582 clk->max_rate < clk->core->req_rate) in __clk_put()
3583 clk_core_set_rate_nolock(clk->core, clk->core->req_rate); in __clk_put()
3585 owner = clk->core->owner; in __clk_put()
3586 kref_put(&clk->core->ref, __clk_release); in __clk_put()
3592 kfree_const(clk->con_id); in __clk_put()
3599 * clk_notifier_register - add a clk rate change notifier
3606 * re-enter into the clk framework by calling any top-level clk APIs;
3610 * clock rate is passed to the callback via struct clk_notifier_data.old_rate
3613 * clk_notifier_register() must be called from non-atomic context.
3614 * Returns -EINVAL if called with null arguments, -ENOMEM upon
3621 int ret = -ENOMEM; in clk_notifier_register()
3624 return -EINVAL; in clk_notifier_register()
3630 if (cn->clk == clk) in clk_notifier_register()
3634 if (cn->clk != clk) { in clk_notifier_register()
3639 cn->clk = clk; in clk_notifier_register()
3640 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
3642 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
3645 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
3647 clk->core->notifier_count++; in clk_notifier_register()
3657 * clk_notifier_unregister - remove a clk rate change notifier
3664 * Returns -EINVAL if called with null arguments; otherwise, passes
3670 int ret = -EINVAL; in clk_notifier_unregister()
3673 return -EINVAL; in clk_notifier_unregister()
3678 if (cn->clk == clk) in clk_notifier_unregister()
3681 if (cn->clk == clk) { in clk_notifier_unregister()
3682 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
3684 clk->core->notifier_count--; in clk_notifier_unregister()
3687 if (!cn->notifier_head.head) { in clk_notifier_unregister()
3688 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
3689 list_del(&cn->node); in clk_notifier_unregister()
3694 ret = -ENOENT; in clk_notifier_unregister()
3705 * struct of_clk_provider - Clock provider registration structure
3706 * @link: Entry in global list of clock providers
3707 * @node: Pointer to device tree node of clock provider
3708 * @get: Get clock callback. Returns NULL or a struct clk for the
3709 * given clock specifier
3743 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
3745 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
3746 pr_err("%s: invalid clock index %u\n", __func__, idx); in of_clk_src_onecell_get()
3747 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
3750 return clk_data->clks[idx]; in of_clk_src_onecell_get()
3758 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
3760 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
3762 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
3765 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
3770 * of_clk_add_provider() - Register a clock provider for a node
3771 * @np: Device node pointer associated with clock provider
3772 * @clk_src_get: callback for decoding clock
3785 return -ENOMEM; in of_clk_add_provider()
3787 cp->node = of_node_get(np); in of_clk_add_provider()
3788 cp->data = data; in of_clk_add_provider()
3789 cp->get = clk_src_get; in of_clk_add_provider()
3792 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
3794 pr_debug("Added clock from %pOF\n", np); in of_clk_add_provider()
3805 * of_clk_add_hw_provider() - Register a clock provider for a node
3806 * @np: Device node pointer associated with clock provider
3820 return -ENOMEM; in of_clk_add_hw_provider()
3822 cp->node = of_node_get(np); in of_clk_add_hw_provider()
3823 cp->data = data; in of_clk_add_hw_provider()
3824 cp->get_hw = get; in of_clk_add_hw_provider()
3827 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
3855 return -ENOMEM; in devm_of_clk_add_hw_provider()
3857 np = dev->of_node; in devm_of_clk_add_hw_provider()
3871 * of_clk_del_provider() - Remove a previously registered clock provider
3872 * @np: Device node pointer associated with clock provider
3880 if (cp->node == np) { in of_clk_del_provider()
3881 list_del(&cp->link); in of_clk_del_provider()
3882 of_node_put(cp->node); in of_clk_del_provider()
3906 devm_clk_provider_match, dev->of_node); in devm_of_clk_del_provider()
3918 if (provider->get_hw) in __of_clk_get_hw_from_provider()
3919 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
3921 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
3931 struct clk *clk = ERR_PTR(-EPROBE_DEFER); in __of_clk_get_from_provider()
3935 return ERR_PTR(-EINVAL); in __of_clk_get_from_provider()
3940 if (provider->node == clkspec->np) { in __of_clk_get_from_provider()
3948 clk = ERR_PTR(-ENOENT); in __of_clk_get_from_provider()
3960 * of_clk_get_from_provider() - Lookup a clock from a clock provider
3961 * @clkspec: pointer to a clock specifier data structure
3963 * This function looks up a struct clk from the registered list of clock
3964 * providers, an input is a clock specifier data structure as returned
3974 * of_clk_get_parent_count() - Count the number of clocks a device node has
3983 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
4002 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
4011 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
4013 of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) { in of_clk_get_parent_name()
4020 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
4024 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
4028 * Best effort to get the name if the clock has been in of_clk_get_parent_name()
4029 * registered with the framework. If the clock isn't in of_clk_get_parent_name()
4031 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
4036 clk_name = clkspec.np->name; in of_clk_get_parent_name()
4052 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
4054 * @np: Device node pointer associated with clock provider
4058 * Return: number of parents for the clock node.
4079 * This function looks for a parent clock. If there is one, then it
4080 * checks that the provider for this parent clock was initialized, in
4081 * this case the parent clock will be ready.
4098 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
4105 * previous parent are ready. If there is no clock in parent_ready()
4114 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
4115 * @np: Device node pointer associated with clock provider
4116 * @index: clock index
4117 * @flags: pointer to top-level framework flags
4119 * Detects if the clock-critical property exists and, if so, sets the
4123 * bindings, such as the one-clock-per-node style that are outdated.
4124 * Those bindings typically put all clock data into .dts and the Linux
4125 * driver has no clock data, thus making it impossible to set this flag
4139 return -EINVAL; in of_clk_detect_critical()
4141 of_property_for_each_u32(np, "clock-critical", prop, cur, idx) in of_clk_detect_critical()
4149 * of_clk_init() - Scan and init clock providers from the DT
4152 * This function scans the device tree for matching clock providers
4179 list_del(&clk_provider->node); in of_clk_init()
4180 of_node_put(clk_provider->np); in of_clk_init()
4187 parent->clk_init_cb = match->data; in of_clk_init()
4188 parent->np = of_node_get(np); in of_clk_init()
4189 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
4196 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
4199 of_node_set_flag(clk_provider->np, in of_clk_init()
4202 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
4203 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
4205 list_del(&clk_provider->node); in of_clk_init()
4206 of_node_put(clk_provider->np); in of_clk_init()
4216 * in case the clock parent was not mandatory in of_clk_init()