Lines Matching +full:warn +full:- +full:soc +full:- +full:level

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
10 #include <linux/clk-provider.h>
11 #include <linux/clk/clk-conf.h>
111 if (!core->rpm_enabled) in clk_pm_runtime_get()
114 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
119 if (!core->rpm_enabled) in clk_pm_runtime_put()
122 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
146 if (--prepare_refcnt) in clk_prepare_unlock()
186 if (--enable_refcnt) { in clk_enable_unlock()
196 return core->protect_count; in clk_core_rate_is_protected()
207 if (!core->ops->is_prepared) in clk_core_is_prepared()
208 return core->prepare_count; in clk_core_is_prepared()
211 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
226 if (!core->ops->is_enabled) in clk_core_is_enabled()
227 return core->enable_count; in clk_core_is_enabled()
239 if (core->rpm_enabled) { in clk_core_is_enabled()
240 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
241 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
247 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
249 if (core->rpm_enabled) in clk_core_is_enabled()
250 pm_runtime_put(core->dev); in clk_core_is_enabled()
259 return !clk ? NULL : clk->core->name; in __clk_get_name()
265 return hw->core->name; in clk_hw_get_name()
271 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
277 return hw->core->num_parents; in clk_hw_get_num_parents()
283 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
293 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
296 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
340 return -ENOENT; in of_parse_clkspec()
345 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
350 * clk_core_get - Find the clk_core parent of a clk
357 * node's 'clock-names' property or as the 'con_id' matching the device's
362 * clock-controller@c001 that has a clk_init_data::parent_data array
364 * clock-controller@f00abcd without needing to get the globally unique name of
367 * parent: clock-controller@f00abcd {
369 * #clock-cells = <0>;
372 * clock-controller@c001 {
375 * clock-names = "xtal";
376 * #clock-cells = <1>;
379 * Returns: -ENOENT when the provider can't be found or the clk doesn't
387 const char *name = core->parents[p_index].fw_name; in clk_core_get()
388 int index = core->parents[p_index].index; in clk_core_get()
389 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
390 struct device *dev = core->dev; in clk_core_get()
392 struct device_node *np = core->of_node; in clk_core_get()
410 return hw->core; in clk_core_get()
415 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
418 if (entry->hw) { in clk_core_fill_parent_index()
419 parent = entry->hw->core; in clk_core_fill_parent_index()
422 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
423 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
432 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
436 entry->core = parent; in clk_core_fill_parent_index()
442 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
445 if (!core->parents[index].core) in clk_core_get_parent_by_index()
448 return core->parents[index].core; in clk_core_get_parent_by_index()
456 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
458 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
464 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
472 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
473 return core->rate; in clk_core_get_rate_nolock()
485 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
494 return core->accuracy; in clk_core_get_accuracy_no_lock()
499 return hw->core->flags; in clk_hw_get_flags()
505 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
511 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
517 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
526 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
534 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
552 if (core->parent == parent) in clk_core_has_parent()
555 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
579 if (req->min_rate < old_req->min_rate) in clk_core_forward_rate_req()
580 req->min_rate = old_req->min_rate; in clk_core_forward_rate_req()
582 if (req->max_rate > old_req->max_rate) in clk_core_forward_rate_req()
583 req->max_rate = old_req->max_rate; in clk_core_forward_rate_req()
590 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags()
595 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
596 parent = core->parent; in clk_mux_determine_rate_flags()
597 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
601 req->rate = 0; in clk_mux_determine_rate_flags()
605 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
621 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
629 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
632 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
642 if (mux_is_better_rate(req->rate, parent_rate, in clk_mux_determine_rate_flags()
650 return -EINVAL; in clk_mux_determine_rate_flags()
654 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
655 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
656 req->rate = best; in clk_mux_determine_rate_flags()
666 return !core ? NULL : core->hw->clk; in __clk_lookup()
677 *min_rate = core->min_rate; in clk_core_get_boundaries()
678 *max_rate = core->max_rate; in clk_core_get_boundaries()
680 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
681 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
683 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
684 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
688 * clk_hw_get_rate_range() - returns the clock rate range for a hw clk
699 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
711 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
714 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
715 if (min_rate > user->max_rate || max_rate < user->min_rate) in clk_core_check_boundaries()
724 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
725 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
730 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
738 * Returns: 0 on success, -EERROR value on error
763 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
764 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
767 if (--core->protect_count > 0) in clk_core_rate_unprotect()
770 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
780 return -EINVAL; in clk_core_rate_nuke_protect()
782 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
785 ret = core->protect_count; in clk_core_rate_nuke_protect()
786 core->protect_count = 1; in clk_core_rate_nuke_protect()
793 * clk_rate_exclusive_put - release exclusivity over clock rate control
821 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
824 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
825 clk->exclusive_count--; in clk_rate_exclusive_put()
838 if (core->protect_count == 0) in clk_core_rate_protect()
839 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
841 core->protect_count++; in clk_core_rate_protect()
855 core->protect_count = count; in clk_core_rate_restore_protect()
859 * clk_rate_exclusive_get - get exclusivity over the clk rate control
874 * Returns 0 on success, -EERROR otherwise
882 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
883 clk->exclusive_count++; in clk_rate_exclusive_get()
897 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
898 "%s already unprepared\n", core->name)) in clk_core_unprepare()
901 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
902 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
905 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
908 if (--core->prepare_count > 0) in clk_core_unprepare()
911 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
915 if (core->ops->unprepare) in clk_core_unprepare()
916 core->ops->unprepare(core->hw); in clk_core_unprepare()
919 clk_core_unprepare(core->parent); in clk_core_unprepare()
931 * clk_unprepare - undo preparation of a clock source
946 clk_core_unprepare_lock(clk->core); in clk_unprepare()
959 if (core->prepare_count == 0) { in clk_core_prepare()
964 ret = clk_core_prepare(core->parent); in clk_core_prepare()
970 if (core->ops->prepare) in clk_core_prepare()
971 ret = core->ops->prepare(core->hw); in clk_core_prepare()
979 core->prepare_count++; in clk_core_prepare()
988 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
993 clk_core_unprepare(core->parent); in clk_core_prepare()
1011 * clk_prepare - prepare a clock source
1020 * Returns 0 on success, -EERROR otherwise.
1027 return clk_core_prepare_lock(clk->core); in clk_prepare()
1038 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1041 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1042 "Disabling critical %s\n", core->name)) in clk_core_disable()
1045 if (--core->enable_count > 0) in clk_core_disable()
1050 if (core->ops->disable) in clk_core_disable()
1051 core->ops->disable(core->hw); in clk_core_disable()
1055 clk_core_disable(core->parent); in clk_core_disable()
1068 * clk_disable - gate a clock
1074 * SoC-internal clk which is controlled via simple register writes. In the
1084 clk_core_disable_lock(clk->core); in clk_disable()
1097 if (WARN(core->prepare_count == 0, in clk_core_enable()
1098 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1099 return -ESHUTDOWN; in clk_core_enable()
1101 if (core->enable_count == 0) { in clk_core_enable()
1102 ret = clk_core_enable(core->parent); in clk_core_enable()
1109 if (core->ops->enable) in clk_core_enable()
1110 ret = core->ops->enable(core->hw); in clk_core_enable()
1115 clk_core_disable(core->parent); in clk_core_enable()
1120 core->enable_count++; in clk_core_enable()
1137 * clk_gate_restore_context - restore context for poweroff
1148 struct clk_core *core = hw->core; in clk_gate_restore_context()
1150 if (core->enable_count) in clk_gate_restore_context()
1151 core->ops->enable(hw); in clk_gate_restore_context()
1153 core->ops->disable(hw); in clk_gate_restore_context()
1162 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1168 if (core->ops && core->ops->save_context) in clk_core_save_context()
1169 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1178 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1179 core->ops->restore_context(core->hw); in clk_core_restore_context()
1181 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1186 * clk_save_context - save clock context for poweroff
1214 * clk_restore_context - restore clock context after poweroff
1232 * clk_enable - ungate a clock
1237 * if the operation will never sleep. One example is a SoC-internal clk which
1241 * must be called before clk_enable. Returns 0 on success, -EERROR
1249 return clk_core_enable_lock(clk->core); in clk_enable()
1254 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
1258 * making clk_enable()/clk_disable() no-ops, false otherwise.
1270 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1301 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1304 if (core->prepare_count) in clk_unprepare_unused_subtree()
1307 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1315 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1316 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1317 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1318 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1332 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1335 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1336 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1343 if (core->enable_count) in clk_disable_unused_subtree()
1346 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1350 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1356 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1357 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1358 else if (core->ops->disable) in clk_disable_unused_subtree()
1359 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1367 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1368 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1419 * Some clock providers hand-craft their clk_rate_requests and in clk_core_determine_round_nolock()
1426 if (!req->min_rate && !req->max_rate) in clk_core_determine_round_nolock()
1428 __func__, core->name); in clk_core_determine_round_nolock()
1430 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in clk_core_determine_round_nolock()
1434 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1435 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1439 req->rate = core->rate; in clk_core_determine_round_nolock()
1440 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1441 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1442 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1443 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1444 &req->best_parent_rate); in clk_core_determine_round_nolock()
1448 req->rate = rate; in clk_core_determine_round_nolock()
1450 return -EINVAL; in clk_core_determine_round_nolock()
1466 req->max_rate = ULONG_MAX; in clk_core_init_rate_req()
1471 req->rate = rate; in clk_core_init_rate_req()
1472 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1474 parent = core->parent; in clk_core_init_rate_req()
1476 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1477 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1479 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1480 req->best_parent_rate = 0; in clk_core_init_rate_req()
1485 * clk_hw_init_rate_request - Initializes a clk_rate_request
1500 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1505 * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent
1524 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1525 parent->core, req, in clk_hw_forward_rate_request()
1531 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1542 req->rate = 0; in clk_core_round_rate_nolock()
1549 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1552 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1553 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1557 req->best_parent_rate = parent_req.rate; in clk_core_round_rate_nolock()
1558 req->rate = parent_req.rate; in clk_core_round_rate_nolock()
1563 req->rate = core->rate; in clk_core_round_rate_nolock()
1568 * __clk_determine_rate - get the closest rate actually supported by a clock
1577 req->rate = 0; in __clk_determine_rate()
1581 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1586 * clk_hw_round_rate() - round the given rate for a hw clk
1605 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1607 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1616 * clk_round_rate - round the given rate for a clk
1634 if (clk->exclusive_count) in clk_round_rate()
1635 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1637 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1639 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1641 if (clk->exclusive_count) in clk_round_rate()
1642 clk_core_rate_protect(clk->core); in clk_round_rate()
1654 * __clk_notify - call clk notifier chain
1660 * Triggers a notifier call chain on the clk rate-change notification
1678 if (cn->clk->core == core) { in __clk_notify()
1679 cnd.clk = cn->clk; in __clk_notify()
1680 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1706 if (core->parent) in __clk_recalc_accuracies()
1707 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1709 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1710 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1713 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1715 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1721 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1728 * clk_get_accuracy - return the accuracy of clk
1744 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1756 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1757 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1785 old_rate = core->rate; in __clk_recalc_rates()
1787 if (core->parent) in __clk_recalc_rates()
1788 parent_rate = core->parent->rate; in __clk_recalc_rates()
1790 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1792 core->req_rate = core->rate; in __clk_recalc_rates()
1798 if (core->notifier_count && msg) in __clk_recalc_rates()
1799 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1801 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1807 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1814 * clk_get_rate - return the rate of clk
1830 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1843 return -EINVAL; in clk_fetch_parent_index()
1845 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1847 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1851 if (core->parents[i].core) in clk_fetch_parent_index()
1855 if (core->parents[i].hw) { in clk_fetch_parent_index()
1856 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1868 if (core->parents[i].name && in clk_fetch_parent_index()
1869 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1873 if (i == core->num_parents) in clk_fetch_parent_index()
1874 return -EINVAL; in clk_fetch_parent_index()
1876 core->parents[i].core = parent; in clk_fetch_parent_index()
1881 * clk_hw_get_parent_index - return the index of the parent clock
1884 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
1892 return -EINVAL; in clk_hw_get_parent_index()
1894 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
1905 core->orphan = is_orphan; in clk_core_update_orphan_status()
1907 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1913 bool was_orphan = core->orphan; in clk_reparent()
1915 hlist_del(&core->child_node); in clk_reparent()
1918 bool becomes_orphan = new_parent->orphan; in clk_reparent()
1921 if (new_parent->new_child == core) in clk_reparent()
1922 new_parent->new_child = NULL; in clk_reparent()
1924 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1929 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1934 core->parent = new_parent; in clk_reparent()
1941 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1964 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
1970 if (core->prepare_count) { in __clk_set_parent_before()
1991 if (core->prepare_count) { in __clk_set_parent_after()
1996 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
1997 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2015 if (parent && core->ops->set_parent) in __clk_set_parent()
2016 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2044 * pre-rate change notifications and returns early if no clks in the
2061 if (core->notifier_count) in __clk_speculate_rates()
2062 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2066 __func__, core->name, ret); in __clk_speculate_rates()
2070 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2085 core->new_rate = new_rate; in clk_calc_subtree()
2086 core->new_parent = new_parent; in clk_calc_subtree()
2087 core->new_parent_index = p_index; in clk_calc_subtree()
2089 core->new_child = NULL; in clk_calc_subtree()
2090 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2091 new_parent->new_child = core; in clk_calc_subtree()
2093 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2094 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
2095 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
2120 parent = old_parent = core->parent; in clk_calc_new_rates()
2122 best_parent_rate = parent->rate; in clk_calc_new_rates()
2138 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2142 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2143 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
2144 core->new_rate = core->rate; in clk_calc_new_rates()
2147 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
2149 new_rate = parent->new_rate; in clk_calc_new_rates()
2155 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2157 __func__, core->name); in clk_calc_new_rates()
2162 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2166 __func__, parent->name, core->name); in clk_calc_new_rates()
2171 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2172 best_parent_rate != parent->rate) in clk_calc_new_rates()
2192 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2195 if (core->notifier_count) { in clk_propagate_rate_change()
2196 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2201 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2203 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2210 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2211 if (core->new_child) { in clk_propagate_rate_change()
2212 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2234 old_rate = core->rate; in clk_change_rate()
2236 if (core->new_parent) { in clk_change_rate()
2237 parent = core->new_parent; in clk_change_rate()
2238 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2239 } else if (core->parent) { in clk_change_rate()
2240 parent = core->parent; in clk_change_rate()
2241 best_parent_rate = core->parent->rate; in clk_change_rate()
2247 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2252 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2253 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2254 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2256 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2258 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2260 core->new_parent_index); in clk_change_rate()
2261 } else if (core->ops->set_parent) { in clk_change_rate()
2262 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2265 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2266 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2269 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2272 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2274 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2275 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2277 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2279 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2281 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2286 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2289 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2290 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2292 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2293 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2299 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2301 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2306 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2307 if (core->new_child) in clk_change_rate()
2308 clk_change_rate(core->new_child); in clk_change_rate()
2357 return -EBUSY; in clk_core_set_rate_nolock()
2362 return -EINVAL; in clk_core_set_rate_nolock()
2372 fail_clk->name); in clk_core_set_rate_nolock()
2374 ret = -EBUSY; in clk_core_set_rate_nolock()
2381 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2389 * clk_set_rate - specify a new rate for clk
2407 * Returns 0 on success, -EERROR otherwise.
2419 if (clk->exclusive_count) in clk_set_rate()
2420 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2422 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2424 if (clk->exclusive_count) in clk_set_rate()
2425 clk_core_rate_protect(clk->core); in clk_set_rate()
2434 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2450 * Returns 0 on success, -EERROR otherwise.
2468 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2470 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2471 clk->exclusive_count++; in clk_set_rate_exclusive()
2492 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2496 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2498 return -EINVAL; in clk_set_rate_range_nolock()
2501 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2502 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2505 old_min = clk->min_rate; in clk_set_rate_range_nolock()
2506 old_max = clk->max_rate; in clk_set_rate_range_nolock()
2507 clk->min_rate = min; in clk_set_rate_range_nolock()
2508 clk->max_rate = max; in clk_set_rate_range_nolock()
2510 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2511 ret = -EINVAL; in clk_set_rate_range_nolock()
2515 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2516 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2517 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2531 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range_nolock()
2533 * - the determine_rate() callback does not really check for in clk_set_rate_range_nolock()
2537 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2540 clk->min_rate = old_min; in clk_set_rate_range_nolock()
2541 clk->max_rate = old_max; in clk_set_rate_range_nolock()
2545 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2546 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2552 * clk_set_rate_range - set a rate range for a clock source
2577 * clk_set_min_rate - set a minimum clock rate for a clock source
2588 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2590 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2595 * clk_set_max_rate - set a maximum clock rate for a clock source
2606 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2608 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2613 * clk_get_parent - return the parent of a clk
2616 * Simply returns clk->parent. Returns NULL if clk is NULL.
2626 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2627 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2638 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2639 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2657 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2661 * clk_has_parent - check if a clock is a possible parent for another
2676 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2692 if (core->parent == parent) in clk_core_set_parent_nolock()
2695 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2696 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2697 return -EPERM; in clk_core_set_parent_nolock()
2699 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2700 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2701 return -EBUSY; in clk_core_set_parent_nolock()
2704 return -EBUSY; in clk_core_set_parent_nolock()
2711 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2714 p_rate = parent->rate; in clk_core_set_parent_nolock()
2728 /* do the re-parent */ in clk_core_set_parent_nolock()
2747 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2752 * clk_set_parent - switch the parent of a mux clk
2756 * Re-parent clk to use parent as its new input source. If clk is in
2766 * Returns 0 on success, -EERROR otherwise.
2777 if (clk->exclusive_count) in clk_set_parent()
2778 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2780 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2781 parent ? parent->core : NULL); in clk_set_parent()
2783 if (clk->exclusive_count) in clk_set_parent()
2784 clk_core_rate_protect(clk->core); in clk_set_parent()
2794 int ret = -EINVAL; in clk_core_set_phase_nolock()
2802 return -EBUSY; in clk_core_set_phase_nolock()
2806 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2807 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2809 core->phase = degrees; in clk_core_set_phase_nolock()
2818 * clk_set_phase - adjust the phase shift of a clock signal
2823 * degrees. Returns 0 on success, -EERROR otherwise.
2827 * phase locked-loop clock signal generators we may shift phase with
2851 if (clk->exclusive_count) in clk_set_phase()
2852 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2854 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2856 if (clk->exclusive_count) in clk_set_phase()
2857 clk_core_rate_protect(clk->core); in clk_set_phase()
2870 if (!core->ops->get_phase) in clk_core_get_phase()
2874 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
2876 core->phase = ret; in clk_core_get_phase()
2882 * clk_get_phase - return the phase shift of a clock signal
2886 * -EERROR.
2896 ret = clk_core_get_phase(clk->core); in clk_get_phase()
2906 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2907 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2914 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2917 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2920 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2925 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
2926 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
2941 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2942 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2943 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2944 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2963 return -EBUSY; in clk_core_set_duty_cycle_nolock()
2967 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
2970 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
2972 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
2984 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
2985 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
2986 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
2987 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
2994 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
3014 return -EINVAL; in clk_set_duty_cycle()
3021 if (clk->exclusive_count) in clk_set_duty_cycle()
3022 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3024 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3026 if (clk->exclusive_count) in clk_set_duty_cycle()
3027 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3038 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3045 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
3053 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
3065 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3070 * clk_is_match - check if two clk's point to the same hardware clock
3086 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
3088 if (p->core == q->core) in clk_is_match()
3111 int level) in clk_summary_show_one() argument
3115 seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu ", in clk_summary_show_one()
3116 level * 3 + 1, "", in clk_summary_show_one()
3117 30 - level * 3, c->name, in clk_summary_show_one()
3118 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
3126 seq_puts(s, "-----"); in clk_summary_show_one()
3130 if (c->ops->is_enabled) in clk_summary_show_one()
3132 else if (!c->ops->enable) in clk_summary_show_one()
3139 int level) in clk_summary_show_subtree() argument
3144 clk_summary_show_one(s, c, level); in clk_summary_show_subtree()
3147 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
3148 clk_summary_show_subtree(s, child, level + 1); in clk_summary_show_subtree()
3154 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_summary_show()
3158 …seq_puts(s, "-------------------------------------------------------------------------------------… in clk_summary_show()
3172 static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level) in clk_dump_one() argument
3180 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
3181 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
3182 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
3183 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
3195 static void clk_dump_subtree(struct seq_file *s, struct clk_core *c, int level) in clk_dump_subtree() argument
3199 clk_dump_one(s, c, level); in clk_dump_subtree()
3201 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3203 clk_dump_subtree(s, child, level + 1); in clk_dump_subtree()
3213 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_dump_show()
3261 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3263 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3272 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3319 struct clk_core *core = s->private; in clk_flags_show()
3320 unsigned long flags = core->flags; in clk_flags_show()
3349 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3357 seq_puts(s, parent->name); in possible_parent_show()
3358 else if (core->parents[i].name) in possible_parent_show()
3359 seq_puts(s, core->parents[i].name); in possible_parent_show()
3360 else if (core->parents[i].fw_name) in possible_parent_show()
3361 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3362 else if (core->parents[i].index >= 0) in possible_parent_show()
3364 of_clk_get_parent_name(core->of_node, in possible_parent_show()
3365 core->parents[i].index)); in possible_parent_show()
3374 struct clk_core *core = s->private; in possible_parents_show()
3377 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3388 struct clk_core *core = s->private; in current_parent_show()
3390 if (core->parent) in current_parent_show()
3391 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3401 struct seq_file *s = file->private_data; in current_parent_write()
3402 struct clk_core *core = s->private; in current_parent_write()
3413 return -ENOENT; in current_parent_write()
3435 struct clk_core *core = s->private; in clk_duty_cycle_show()
3436 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3438 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3446 struct clk_core *core = s->private; in clk_min_rate_show()
3460 struct clk_core *core = s->private; in clk_max_rate_show()
3479 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3480 core->dentry = root; in clk_debug_create_one()
3486 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3487 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3489 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3490 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3491 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3492 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3499 if (core->num_parents > 1) in clk_debug_create_one()
3504 if (core->num_parents > 0) in clk_debug_create_one()
3508 if (core->num_parents > 1) in clk_debug_create_one()
3512 if (core->ops->debug_init) in clk_debug_create_one()
3513 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3517 * clk_debug_register - add a clk node to the debugfs clk directory
3527 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3534 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3538 * debugfs clk directory if clk->dentry points to debugfs created by
3544 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3545 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3546 core->dentry = NULL; in clk_debug_unregister()
3551 * clk_debug_init - lazily populate the debugfs clk directory
3555 * populates the debugfs clk directory once at boot-time when we know that
3556 * debugfs is setup. It should only be called once at boot-time, all other clks
3642 * 'req_rate' is set to something non-zero so that in clk_core_reparent_orphans_nolock()
3645 orphan->req_rate = orphan->rate; in clk_core_reparent_orphans_nolock()
3651 * __clk_core_init - initialize the data structures in a struct clk_core
3667 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3668 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3672 core->hw->core = core; in __clk_core_init()
3679 if (clk_core_lookup(core->name)) { in __clk_core_init()
3681 __func__, core->name); in __clk_core_init()
3682 ret = -EEXIST; in __clk_core_init()
3686 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3687 if (core->ops->set_rate && in __clk_core_init()
3688 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3689 core->ops->recalc_rate)) { in __clk_core_init()
3691 __func__, core->name); in __clk_core_init()
3692 ret = -EINVAL; in __clk_core_init()
3696 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3698 __func__, core->name); in __clk_core_init()
3699 ret = -EINVAL; in __clk_core_init()
3703 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3705 __func__, core->name); in __clk_core_init()
3706 ret = -EINVAL; in __clk_core_init()
3710 if (core->ops->set_rate_and_parent && in __clk_core_init()
3711 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3713 __func__, core->name); in __clk_core_init()
3714 ret = -EINVAL; in __clk_core_init()
3719 * optional platform-specific magic in __clk_core_init()
3732 if (core->ops->init) { in __clk_core_init()
3733 ret = core->ops->init(core->hw); in __clk_core_init()
3738 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3741 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3747 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
3751 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3752 core->orphan = parent->orphan; in __clk_core_init()
3753 } else if (!core->num_parents) { in __clk_core_init()
3754 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3755 core->orphan = false; in __clk_core_init()
3757 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3758 core->orphan = true; in __clk_core_init()
3768 if (core->ops->recalc_accuracy) in __clk_core_init()
3769 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3772 core->accuracy = parent->accuracy; in __clk_core_init()
3774 core->accuracy = 0; in __clk_core_init()
3785 core->name); in __clk_core_init()
3800 if (core->ops->recalc_rate) in __clk_core_init()
3801 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3804 rate = parent->rate; in __clk_core_init()
3807 core->rate = core->req_rate = rate; in __clk_core_init()
3814 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3818 __func__, core->name); in __clk_core_init()
3825 __func__, core->name); in __clk_core_init()
3833 kref_init(&core->ref); in __clk_core_init()
3838 hlist_del_init(&core->child_node); in __clk_core_init()
3839 core->hw->core = NULL; in __clk_core_init()
3851 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
3858 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3863 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
3869 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
3873 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
3887 return ERR_PTR(-ENOMEM); in alloc_clk()
3889 clk->core = core; in alloc_clk()
3890 clk->dev_id = dev_id; in alloc_clk()
3891 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
3892 clk->max_rate = ULONG_MAX; in alloc_clk()
3898 * free_clk - Free a clk consumer
3906 kfree_const(clk->con_id); in free_clk()
3932 core = hw->core; in clk_hw_create_clk()
3936 clk->dev = dev; in clk_hw_create_clk()
3938 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
3940 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
3943 kref_get(&core->ref); in clk_hw_create_clk()
3950 * clk_hw_get_clk - get clk consumer given an clk_hw
3961 struct device *dev = hw->core->dev; in clk_hw_get_clk()
3974 return -EINVAL; in clk_cpy_name()
3980 return -ENOMEM; in clk_cpy_name()
3988 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
3989 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
3990 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
3991 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
3999 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
4003 core->parents = parents; in clk_core_populate_parent_map()
4005 return -ENOMEM; in clk_core_populate_parent_map()
4009 parent->index = -1; in clk_core_populate_parent_map()
4011 /* throw a WARN if any entries are NULL */ in clk_core_populate_parent_map()
4012 WARN(!parent_names[i], in clk_core_populate_parent_map()
4014 __func__, core->name); in clk_core_populate_parent_map()
4015 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
4018 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
4019 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
4020 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
4023 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
4027 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
4029 ret = -EINVAL; in clk_core_populate_parent_map()
4030 WARN(1, "Must specify parents if num_parents > 0\n"); in clk_core_populate_parent_map()
4037 } while (--i >= 0); in clk_core_populate_parent_map()
4049 int i = core->num_parents; in clk_core_free_parent_map()
4051 if (!core->num_parents) in clk_core_free_parent_map()
4054 while (--i >= 0) { in clk_core_free_parent_map()
4055 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4056 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4059 kfree(core->parents); in clk_core_free_parent_map()
4067 const struct clk_init_data *init = hw->init; in __clk_register()
4072 * we catch use of hw->init early on in the core. in __clk_register()
4074 hw->init = NULL; in __clk_register()
4078 ret = -ENOMEM; in __clk_register()
4082 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4083 if (!core->name) { in __clk_register()
4084 ret = -ENOMEM; in __clk_register()
4088 if (WARN_ON(!init->ops)) { in __clk_register()
4089 ret = -EINVAL; in __clk_register()
4092 core->ops = init->ops; in __clk_register()
4095 core->rpm_enabled = true; in __clk_register()
4096 core->dev = dev; in __clk_register()
4097 core->of_node = np; in __clk_register()
4098 if (dev && dev->driver) in __clk_register()
4099 core->owner = dev->driver->owner; in __clk_register()
4100 core->hw = hw; in __clk_register()
4101 core->flags = init->flags; in __clk_register()
4102 core->num_parents = init->num_parents; in __clk_register()
4103 core->min_rate = 0; in __clk_register()
4104 core->max_rate = ULONG_MAX; in __clk_register()
4110 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4116 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4117 if (IS_ERR(hw->clk)) { in __clk_register()
4118 ret = PTR_ERR(hw->clk); in __clk_register()
4122 clk_core_link_consumer(core, hw->clk); in __clk_register()
4126 return hw->clk; in __clk_register()
4129 clk_core_unlink_consumer(hw->clk); in __clk_register()
4132 free_clk(hw->clk); in __clk_register()
4133 hw->clk = NULL; in __clk_register()
4139 kfree_const(core->name); in __clk_register()
4147 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
4151 * @dev->parent if dev doesn't have a device node, or NULL if neither
4152 * @dev or @dev->parent have a device node.
4163 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
4169 * clk_register - allocate a new clock, register it and return an opaque cookie
4171 * @hw: link to hardware-specific clock data
4188 * clk_hw_register - register a clk_hw and return an error code
4190 * @hw: link to hardware-specific clock data
4205 * of_clk_hw_register - register a clk_hw and return an error code
4207 * @hw: link to hardware-specific clock data
4229 kfree_const(core->name); in __clk_release()
4240 return -ENXIO; in clk_nodrv_prepare_enable()
4251 return -ENXIO; in clk_nodrv_set_rate()
4256 return -ENXIO; in clk_nodrv_set_parent()
4274 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
4275 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4276 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4278 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
4297 * clk_unregister - unregister a currently registered clock
4308 clk_debug_unregister(clk->core); in clk_unregister()
4312 ops = clk->core->ops; in clk_unregister()
4315 clk->core->name); in clk_unregister()
4323 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4326 if (ops->terminate) in clk_unregister()
4327 ops->terminate(clk->core->hw); in clk_unregister()
4329 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4334 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4339 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4341 hlist_del_init(&clk->core->child_node); in clk_unregister()
4343 if (clk->core->prepare_count) in clk_unregister()
4345 __func__, clk->core->name); in clk_unregister()
4347 if (clk->core->protect_count) in clk_unregister()
4349 __func__, clk->core->name); in clk_unregister()
4351 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4359 * clk_hw_unregister - unregister a currently registered clk_hw
4360 * @hw: hardware-specific clock data to unregister
4364 clk_unregister(hw->clk); in clk_hw_unregister()
4379 * devm_clk_register - resource managed clk_register()
4381 * @hw: link to hardware-specific clock data
4395 return ERR_PTR(-ENOMEM); in devm_clk_register()
4410 * devm_clk_hw_register - resource managed clk_hw_register()
4412 * @hw: link to hardware-specific clock data
4425 return -ENOMEM; in devm_clk_hw_register()
4445 * devm_clk_hw_get_clk - resource managed clk_hw_get_clk()
4464 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4468 return ERR_PTR(-ENOMEM); in devm_clk_hw_get_clk()
4500 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4502 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4503 clk_core_rate_unprotect(clk->core); in __clk_put()
4504 clk->exclusive_count = 0; in __clk_put()
4507 hlist_del(&clk->clks_node); in __clk_put()
4510 if (clk->min_rate > 0 || clk->max_rate < ULONG_MAX) in __clk_put()
4513 owner = clk->core->owner; in __clk_put()
4514 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4526 * clk_notifier_register - add a clk rate change notifier
4533 * re-enter into the clk framework by calling any top-level clk APIs;
4540 * clk_notifier_register() must be called from non-atomic context.
4541 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4548 int ret = -ENOMEM; in clk_notifier_register()
4551 return -EINVAL; in clk_notifier_register()
4557 if (cn->clk == clk) in clk_notifier_register()
4565 cn->clk = clk; in clk_notifier_register()
4566 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4568 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4571 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4573 clk->core->notifier_count++; in clk_notifier_register()
4583 * clk_notifier_unregister - remove a clk rate change notifier
4590 * Returns -EINVAL if called with null arguments; otherwise, passes
4596 int ret = -ENOENT; in clk_notifier_unregister()
4599 return -EINVAL; in clk_notifier_unregister()
4604 if (cn->clk == clk) { in clk_notifier_unregister()
4605 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4607 clk->core->notifier_count--; in clk_notifier_unregister()
4610 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4611 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4612 list_del(&cn->node); in clk_notifier_unregister()
4634 clk_notifier_unregister(devres->clk, devres->nb); in devm_clk_notifier_release()
4647 return -ENOMEM; in devm_clk_notifier_register()
4651 devres->clk = clk; in devm_clk_notifier_register()
4652 devres->nb = nb; in devm_clk_notifier_register()
4670 * struct of_clk_provider - Clock provider registration structure
4711 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4713 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4715 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4718 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4726 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4728 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4730 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4733 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4738 * of_clk_add_provider() - Register a clock provider for a node
4758 return -ENOMEM; in of_clk_add_provider()
4760 cp->node = of_node_get(np); in of_clk_add_provider()
4761 cp->data = data; in of_clk_add_provider()
4762 cp->get = clk_src_get; in of_clk_add_provider()
4765 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
4775 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_provider()
4782 * of_clk_add_hw_provider() - Register a clock provider for a node
4800 return -ENOMEM; in of_clk_add_hw_provider()
4802 cp->node = of_node_get(np); in of_clk_add_hw_provider()
4803 cp->data = data; in of_clk_add_hw_provider()
4804 cp->get_hw = get; in of_clk_add_hw_provider()
4807 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
4817 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_hw_provider()
4830 * for cases like MFD sub-devices where the child device driver wants to use
4831 * devm_*() APIs but not list the device in DT as a sub-node.
4837 np = dev->of_node; in get_clk_provider_node()
4838 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
4840 if (!of_find_property(np, "#clock-cells", NULL)) in get_clk_provider_node()
4841 if (of_find_property(parent_np, "#clock-cells", NULL)) in get_clk_provider_node()
4848 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
4854 * node or if the device node lacks of clock provider information (#clock-cells)
4856 * has the #clock-cells then it is used in registration. Provider is
4872 return -ENOMEM; in devm_of_clk_add_hw_provider()
4888 * of_clk_del_provider() - Remove a previously registered clock provider
4900 if (cp->node == np) { in of_clk_del_provider()
4901 list_del(&cp->link); in of_clk_del_provider()
4902 fwnode_dev_initialized(&np->fwnode, false); in of_clk_del_provider()
4903 of_node_put(cp->node); in of_clk_del_provider()
4913 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
4919 * Parses a device node's "clocks" and "clock-names" properties to find the
4922 * parsing error. The @index argument is ignored if @name is non-NULL.
4926 * phandle1: clock-controller@1 {
4927 * #clock-cells = <2>;
4930 * phandle2: clock-controller@2 {
4931 * #clock-cells = <1>;
4934 * clock-consumer@3 {
4936 * clock-names = "name1", "name2";
4939 * To get a device_node for `clock-controller@2' node you may call this
4942 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
4943 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
4944 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
4946 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
4947 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
4948 * the "clock-names" property of @np.
4953 int ret = -ENOENT; in of_parse_clkspec()
4959 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
4961 * return -EINVAL. in of_parse_clkspec()
4964 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
4965 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
4974 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
4977 np = np->parent; in of_parse_clkspec()
4978 if (np && !of_get_property(np, "clock-ranges", NULL)) in of_parse_clkspec()
4992 if (provider->get_hw) in __of_clk_get_hw_from_provider()
4993 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
4995 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5005 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
5008 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
5012 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
5024 * of_clk_get_from_provider() - Lookup a clock from a clock provider
5067 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
5072 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
5076 * This function parses the clocks and clock-names properties,
5083 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
5085 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
5090 * of_clk_get_parent_count() - Count the number of clocks a device node has
5099 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
5118 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
5127 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
5129 of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) { in of_clk_get_parent_name()
5136 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
5140 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
5147 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
5152 clk_name = clkspec.np->name; in of_clk_get_parent_name()
5168 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
5214 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
5230 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
5233 * @flags: pointer to top-level framework flags
5235 * Detects if the clock-critical property exists and, if so, sets the
5239 * bindings, such as the one-clock-per-node style that are outdated.
5255 return -EINVAL; in of_clk_detect_critical()
5257 of_property_for_each_u32(np, "clock-critical", prop, cur, idx) in of_clk_detect_critical()
5265 * of_clk_init() - Scan and init clock providers from the DT
5295 list_del(&clk_provider->node); in of_clk_init()
5296 of_node_put(clk_provider->np); in of_clk_init()
5303 parent->clk_init_cb = match->data; in of_clk_init()
5304 parent->np = of_node_get(np); in of_clk_init()
5305 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5312 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5315 of_node_set_flag(clk_provider->np, in of_clk_init()
5318 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5319 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5321 list_del(&clk_provider->node); in of_clk_init()
5322 of_node_put(clk_provider->np); in of_clk_init()