Lines Matching +full:clock +full:- +full:name
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>
56 const char *name; member
61 const char *name; member
116 if (!core->rpm_enabled) in clk_pm_runtime_get()
119 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
124 if (!core->rpm_enabled) in clk_pm_runtime_put()
127 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
131 * clk_pm_runtime_get_all() - Runtime "get" all clk provider devices
166 dev_name(failed->dev), failed->name); in clk_pm_runtime_get_all()
186 * clk_pm_runtime_put_all() - Runtime "put" all clk provider devices
202 struct device *dev = core->dev; in clk_pm_runtime_init()
205 core->rpm_enabled = true; in clk_pm_runtime_init()
208 hlist_add_head(&core->rpm_node, &clk_rpm_list); in clk_pm_runtime_init()
234 if (--prepare_refcnt) in clk_prepare_unlock()
274 if (--enable_refcnt) { in clk_enable_unlock()
284 return core->protect_count; in clk_core_rate_is_protected()
295 if (!core->ops->is_prepared) in clk_core_is_prepared()
296 return core->prepare_count; in clk_core_is_prepared()
299 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
314 if (!core->ops->is_enabled) in clk_core_is_enabled()
315 return core->enable_count; in clk_core_is_enabled()
318 * Check if clock controller's device is runtime active before in clk_core_is_enabled()
319 * calling .is_enabled callback. If not, assume that clock is in clk_core_is_enabled()
327 if (core->rpm_enabled) { in clk_core_is_enabled()
328 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
329 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
338 * anything here. We can also assume this clock isn't enabled. in clk_core_is_enabled()
340 if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) in clk_core_is_enabled()
341 if (!clk_core_is_enabled(core->parent)) { in clk_core_is_enabled()
346 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
348 if (core->rpm_enabled) in clk_core_is_enabled()
349 pm_runtime_put(core->dev); in clk_core_is_enabled()
358 return !clk ? NULL : clk->core->name; in __clk_get_name()
364 return hw->core->name; in clk_hw_get_name()
370 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
376 return hw->core->num_parents; in clk_hw_get_num_parents()
382 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
386 static struct clk_core *__clk_lookup_subtree(const char *name, in __clk_lookup_subtree() argument
392 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
395 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
396 ret = __clk_lookup_subtree(name, child); in __clk_lookup_subtree()
404 static struct clk_core *clk_core_lookup(const char *name) in clk_core_lookup() argument
409 if (!name) in clk_core_lookup()
414 ret = __clk_lookup_subtree(name, root_clk); in clk_core_lookup()
421 ret = __clk_lookup_subtree(name, root_clk); in clk_core_lookup()
431 const char *name, struct of_phandle_args *out_args);
436 const char *name, in of_parse_clkspec() argument
439 return -ENOENT; in of_parse_clkspec()
444 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
449 * clk_core_get - Find the clk_core parent of a clk
455 * array is indexed and treated as a local name matching a string in the device
456 * node's 'clock-names' property or as the 'con_id' matching the device's
460 * For example the following DT snippet would allow a clock registered by the
461 * clock-controller@c001 that has a clk_init_data::parent_data array
462 * with 'xtal' in the 'name' member to find the clock provided by the
463 * clock-controller@f00abcd without needing to get the globally unique name of
466 * parent: clock-controller@f00abcd {
468 * #clock-cells = <0>;
471 * clock-controller@c001 {
474 * clock-names = "xtal";
475 * #clock-cells = <1>;
478 * Returns: -ENOENT when the provider can't be found or the clk doesn't
479 * exist in the provider or the name can't be found in the DT node or
486 const char *name = core->parents[p_index].fw_name; in clk_core_get() local
487 int index = core->parents[p_index].index; in clk_core_get()
488 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
489 struct device *dev = core->dev; in clk_core_get()
491 struct device_node *np = core->of_node; in clk_core_get()
494 if (np && (name || index >= 0) && in clk_core_get()
495 !of_parse_clkspec(np, index, name, &clkspec)) { in clk_core_get()
498 } else if (name) { in clk_core_get()
503 hw = clk_find_hw(dev_id, name); in clk_core_get()
512 return hw->core; in clk_core_get()
517 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
520 if (entry->hw) { in clk_core_fill_parent_index()
521 parent = entry->hw->core; in clk_core_fill_parent_index()
524 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
525 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
534 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
538 entry->core = parent; in clk_core_fill_parent_index()
544 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
547 if (!core->parents[index].core) in clk_core_get_parent_by_index()
550 return core->parents[index].core; in clk_core_get_parent_by_index()
558 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
560 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
566 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
574 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
575 return core->rate; in clk_core_get_rate_nolock()
587 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
596 return core->accuracy; in clk_core_get_accuracy_no_lock()
601 return hw->core->flags; in clk_hw_get_flags()
607 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
613 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
619 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
628 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
636 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
654 if (core->parent == parent) in clk_core_has_parent()
657 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
681 if (req->min_rate < old_req->min_rate) in clk_core_forward_rate_req()
682 req->min_rate = old_req->min_rate; in clk_core_forward_rate_req()
684 if (req->max_rate > old_req->max_rate) in clk_core_forward_rate_req()
685 req->max_rate = old_req->max_rate; in clk_core_forward_rate_req()
692 struct clk_core *core = hw->core; in clk_core_determine_rate_no_reparent()
693 struct clk_core *parent = core->parent; in clk_core_determine_rate_no_reparent()
697 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_determine_rate_no_reparent()
701 req->rate = 0; in clk_core_determine_rate_no_reparent()
706 req->rate); in clk_core_determine_rate_no_reparent()
723 req->best_parent_rate = best; in clk_core_determine_rate_no_reparent()
724 req->rate = best; in clk_core_determine_rate_no_reparent()
733 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags()
738 if (core->flags & CLK_SET_RATE_NO_REPARENT) in clk_mux_determine_rate_flags()
742 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
750 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
753 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
768 if (mux_is_better_rate(req->rate, parent_rate, in clk_mux_determine_rate_flags()
776 return -EINVAL; in clk_mux_determine_rate_flags()
778 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
779 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
780 req->rate = best; in clk_mux_determine_rate_flags()
786 struct clk *__clk_lookup(const char *name) in __clk_lookup() argument
788 struct clk_core *core = clk_core_lookup(name); in __clk_lookup()
790 return !core ? NULL : core->hw->clk; in __clk_lookup()
801 *min_rate = core->min_rate; in clk_core_get_boundaries()
802 *max_rate = core->max_rate; in clk_core_get_boundaries()
804 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
805 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
807 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
808 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
812 * clk_hw_get_rate_range() - returns the clock rate range for a hw clk
818 * maximum that clock can reach.
823 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
835 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
838 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
839 if (min_rate > user->max_rate || max_rate < user->min_rate) in clk_core_check_boundaries()
848 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
849 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
854 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
860 * complex clock that may combine a mux with other operations.
862 * Returns: 0 on success, -EERROR value on error
879 …* clk_hw_determine_rate_no_reparent - clk_ops::determine_rate implementation for a clk that doesn'…
885 * mux), or from a more complex clock that may combine a mux with other
888 * Returns: 0 on success, -EERROR value on error
906 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
907 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
910 if (--core->protect_count > 0) in clk_core_rate_unprotect()
913 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
923 return -EINVAL; in clk_core_rate_nuke_protect()
925 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
928 ret = core->protect_count; in clk_core_rate_nuke_protect()
929 core->protect_count = 1; in clk_core_rate_nuke_protect()
936 * clk_rate_exclusive_put - release exclusivity over clock rate control
939 * clk_rate_exclusive_put() completes a critical section during which a clock
941 * clock which could result in a rate change or rate glitch. Exclusive clocks
946 * If exlusivity is claimed more than once on clock, even by the same consumer,
964 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
967 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
968 clk->exclusive_count--; in clk_rate_exclusive_put()
981 if (core->protect_count == 0) in clk_core_rate_protect()
982 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
984 core->protect_count++; in clk_core_rate_protect()
998 core->protect_count = count; in clk_core_rate_restore_protect()
1002 * clk_rate_exclusive_get - get exclusivity over the clk rate control
1005 * clk_rate_exclusive_get() begins a critical section during which a clock
1007 * clock which could result in a rate change or rate glitch. Exclusive clocks
1012 * If exlusivity is claimed more than once on clock, even by the same consumer,
1017 * Returns 0 on success, -EERROR otherwise
1025 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
1026 clk->exclusive_count++; in clk_rate_exclusive_get()
1059 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
1060 "%s already unprepared\n", core->name)) in clk_core_unprepare()
1063 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
1064 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
1067 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
1070 if (--core->prepare_count > 0) in clk_core_unprepare()
1073 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
1077 if (core->ops->unprepare) in clk_core_unprepare()
1078 core->ops->unprepare(core->hw); in clk_core_unprepare()
1081 clk_core_unprepare(core->parent); in clk_core_unprepare()
1093 * clk_unprepare - undo preparation of a clock source
1108 clk_core_unprepare_lock(clk->core); in clk_unprepare()
1121 if (core->prepare_count == 0) { in clk_core_prepare()
1126 ret = clk_core_prepare(core->parent); in clk_core_prepare()
1132 if (core->ops->prepare) in clk_core_prepare()
1133 ret = core->ops->prepare(core->hw); in clk_core_prepare()
1141 core->prepare_count++; in clk_core_prepare()
1144 * CLK_SET_RATE_GATE is a special case of clock protection in clk_core_prepare()
1148 * the clock is prepared. in clk_core_prepare()
1150 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1155 clk_core_unprepare(core->parent); in clk_core_prepare()
1173 * clk_prepare - prepare a clock source
1182 * Returns 0 on success, -EERROR otherwise.
1189 return clk_core_prepare_lock(clk->core); in clk_prepare()
1200 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1203 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1204 "Disabling critical %s\n", core->name)) in clk_core_disable()
1207 if (--core->enable_count > 0) in clk_core_disable()
1212 if (core->ops->disable) in clk_core_disable()
1213 core->ops->disable(core->hw); in clk_core_disable()
1217 clk_core_disable(core->parent); in clk_core_disable()
1230 * clk_disable - gate a clock
1236 * SoC-internal clk which is controlled via simple register writes. In the
1246 clk_core_disable_lock(clk->core); in clk_disable()
1259 if (WARN(core->prepare_count == 0, in clk_core_enable()
1260 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1261 return -ESHUTDOWN; in clk_core_enable()
1263 if (core->enable_count == 0) { in clk_core_enable()
1264 ret = clk_core_enable(core->parent); in clk_core_enable()
1271 if (core->ops->enable) in clk_core_enable()
1272 ret = core->ops->enable(core->hw); in clk_core_enable()
1277 clk_core_disable(core->parent); in clk_core_enable()
1282 core->enable_count++; in clk_core_enable()
1299 * clk_gate_restore_context - restore context for poweroff
1300 * @hw: the clk_hw pointer of clock whose state is to be restored
1302 * The clock gate restore context function enables or disables
1304 * where the clock context is lost and based on the enable_count
1305 * the clock either needs to be enabled/disabled. This
1310 struct clk_core *core = hw->core; in clk_gate_restore_context()
1312 if (core->enable_count) in clk_gate_restore_context()
1313 core->ops->enable(hw); in clk_gate_restore_context()
1315 core->ops->disable(hw); in clk_gate_restore_context()
1324 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1330 if (core->ops && core->ops->save_context) in clk_core_save_context()
1331 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1340 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1341 core->ops->restore_context(core->hw); in clk_core_restore_context()
1343 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1348 * clk_save_context - save clock context for poweroff
1350 * Saves the context of the clock register for powerstates in which the
1376 * clk_restore_context - restore clock context after poweroff
1378 * Restore the saved clock context upon resume.
1394 * clk_enable - ungate a clock
1399 * if the operation will never sleep. One example is a SoC-internal clk which
1403 * must be called before clk_enable. Returns 0 on success, -EERROR
1411 return clk_core_enable_lock(clk->core); in clk_enable()
1416 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
1417 * @clk: clock source
1419 * Returns true if clk_prepare() implicitly enables the clock, effectively
1420 * making clk_enable()/clk_disable() no-ops, false otherwise.
1423 * disabling the clock also requires unpreparing it to have any material
1432 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1463 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1466 if (core->prepare_count) in clk_unprepare_unused_subtree()
1469 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1474 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1475 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1476 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1477 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1489 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1492 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1493 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1497 if (core->enable_count) in clk_disable_unused_subtree()
1500 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1504 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1510 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1511 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1512 else if (core->ops->disable) in clk_disable_unused_subtree()
1513 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1519 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1520 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1583 * Some clock providers hand-craft their clk_rate_requests and in clk_core_determine_round_nolock()
1590 if (!req->min_rate && !req->max_rate) in clk_core_determine_round_nolock()
1592 __func__, core->name); in clk_core_determine_round_nolock()
1594 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in clk_core_determine_round_nolock()
1598 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1599 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1603 req->rate = core->rate; in clk_core_determine_round_nolock()
1604 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1605 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1606 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1607 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1608 &req->best_parent_rate); in clk_core_determine_round_nolock()
1612 req->rate = rate; in clk_core_determine_round_nolock()
1614 return -EINVAL; in clk_core_determine_round_nolock()
1630 req->max_rate = ULONG_MAX; in clk_core_init_rate_req()
1635 req->core = core; in clk_core_init_rate_req()
1636 req->rate = rate; in clk_core_init_rate_req()
1637 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1639 parent = core->parent; in clk_core_init_rate_req()
1641 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1642 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1644 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1645 req->best_parent_rate = 0; in clk_core_init_rate_req()
1650 * clk_hw_init_rate_request - Initializes a clk_rate_request
1665 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1670 * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent
1671 * @hw: the original clock that got the rate request
1677 * Initializes a clk_rate_request structure to submit to a clock parent
1689 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1690 parent->core, req, in clk_hw_forward_rate_request()
1697 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1708 req->rate = 0; in clk_core_round_rate_nolock()
1715 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1718 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1722 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1728 req->best_parent_rate = parent_req.rate; in clk_core_round_rate_nolock()
1729 req->rate = parent_req.rate; in clk_core_round_rate_nolock()
1734 req->rate = core->rate; in clk_core_round_rate_nolock()
1739 * __clk_determine_rate - get the closest rate actually supported by a clock
1740 * @hw: determine the rate of this clock
1748 req->rate = 0; in __clk_determine_rate()
1752 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1757 * clk_hw_round_rate() - round the given rate for a hw clk
1776 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1780 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1791 * clk_round_rate - round the given rate for a clk
1809 if (clk->exclusive_count) in clk_round_rate()
1810 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1812 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1816 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1820 if (clk->exclusive_count) in clk_round_rate()
1821 clk_core_rate_protect(clk->core); in clk_round_rate()
1833 * __clk_notify - call clk notifier chain
1839 * Triggers a notifier call chain on the clk rate-change notification
1842 * internal clock code only. Returns NOTIFY_DONE from the last driver
1857 if (cn->clk->core == core) { in __clk_notify()
1858 cnd.clk = cn->clk; in __clk_notify()
1859 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1875 * callback then it is assumed that the clock will take on the accuracy of its
1885 if (core->parent) in __clk_recalc_accuracies()
1886 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1888 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1889 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1892 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1894 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1900 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1907 * clk_get_accuracy - return the accuracy of clk
1923 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1935 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1936 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1950 * it is assumed that the clock will take on the rate of its parent.
1964 old_rate = core->rate; in __clk_recalc_rates()
1966 if (core->parent) in __clk_recalc_rates()
1967 parent_rate = core->parent->rate; in __clk_recalc_rates()
1969 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1971 core->req_rate = core->rate; in __clk_recalc_rates()
1977 if (core->notifier_count && msg) in __clk_recalc_rates()
1978 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1980 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1986 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1993 * clk_get_rate - return the rate of clk
1998 * the clock enabledness. If clk is NULL, or if an error occurred, then returns
2009 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
2022 return -EINVAL; in clk_fetch_parent_index()
2024 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
2026 if (core->parents[i].core == parent) in clk_fetch_parent_index()
2030 if (core->parents[i].core) in clk_fetch_parent_index()
2034 if (core->parents[i].hw) { in clk_fetch_parent_index()
2035 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
2047 if (core->parents[i].name && in clk_fetch_parent_index()
2048 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
2052 if (i == core->num_parents) in clk_fetch_parent_index()
2053 return -EINVAL; in clk_fetch_parent_index()
2055 core->parents[i].core = parent; in clk_fetch_parent_index()
2060 * clk_hw_get_parent_index - return the index of the parent clock
2063 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
2064 * clock does not have a current parent.
2071 return -EINVAL; in clk_hw_get_parent_index()
2073 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
2084 core->orphan = is_orphan; in clk_core_update_orphan_status()
2086 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
2092 bool was_orphan = core->orphan; in clk_reparent()
2094 hlist_del(&core->child_node); in clk_reparent()
2097 bool becomes_orphan = new_parent->orphan; in clk_reparent()
2100 if (new_parent->new_child == core) in clk_reparent()
2101 new_parent->new_child = NULL; in clk_reparent()
2103 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
2108 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
2113 core->parent = new_parent; in clk_reparent()
2120 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
2123 * 1. enable parents for CLK_OPS_PARENT_ENABLE clock in __clk_set_parent_before()
2128 * If the clock is not prepared, then a race with in __clk_set_parent_before()
2133 * If the clock is prepared, migrate the prepared state to the new in __clk_set_parent_before()
2135 * forcing the clock and the new parent on. This ensures that all in __clk_set_parent_before()
2143 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2149 if (core->prepare_count) { in __clk_set_parent_before()
2170 if (core->prepare_count) { in __clk_set_parent_after()
2175 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
2176 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2193 /* change clock input source */ in __clk_set_parent()
2194 if (parent && core->ops->set_parent) in __clk_set_parent()
2195 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2223 * pre-rate change notifications and returns early if no clks in the
2225 * implement the .recalc_rate callback then it is assumed that the clock will
2240 if (core->notifier_count) in __clk_speculate_rates()
2241 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2244 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
2245 __func__, core->name, ret); in __clk_speculate_rates()
2249 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2264 core->new_rate = new_rate; in clk_calc_subtree()
2265 core->new_parent = new_parent; in clk_calc_subtree()
2266 core->new_parent_index = p_index; in clk_calc_subtree()
2268 core->new_child = NULL; in clk_calc_subtree()
2269 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2270 new_parent->new_child = core; in clk_calc_subtree()
2272 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2273 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
2274 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
2279 * calculate the new rates returning the topmost clock that has to be
2299 parent = old_parent = core->parent; in clk_calc_new_rates()
2301 best_parent_rate = parent->rate; in clk_calc_new_rates()
2321 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2325 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2326 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
2327 core->new_rate = core->rate; in clk_calc_new_rates()
2330 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
2332 new_rate = parent->new_rate; in clk_calc_new_rates()
2338 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2340 __func__, core->name); in clk_calc_new_rates()
2345 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2349 __func__, parent->name, core->name); in clk_calc_new_rates()
2354 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2355 best_parent_rate != parent->rate) in clk_calc_new_rates()
2375 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2378 if (core->notifier_count) { in clk_propagate_rate_change()
2379 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2384 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2385 /* Skip children who will be reparented to another clock */ in clk_propagate_rate_change()
2386 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2393 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2394 if (core->new_child) { in clk_propagate_rate_change()
2395 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2417 old_rate = core->rate; in clk_change_rate()
2419 if (core->new_parent) { in clk_change_rate()
2420 parent = core->new_parent; in clk_change_rate()
2421 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2422 } else if (core->parent) { in clk_change_rate()
2423 parent = core->parent; in clk_change_rate()
2424 best_parent_rate = core->parent->rate; in clk_change_rate()
2430 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2435 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2436 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2437 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2439 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2441 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2443 core->new_parent_index); in clk_change_rate()
2444 } else if (core->ops->set_parent) { in clk_change_rate()
2445 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2448 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2449 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2452 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2455 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2457 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2458 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2460 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2462 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2464 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2469 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2472 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2473 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2475 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2476 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2480 * for certain clock types. in clk_change_rate()
2482 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2483 /* Skip children who will be reparented to another clock */ in clk_change_rate()
2484 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2489 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2490 if (core->new_child) in clk_change_rate()
2491 clk_change_rate(core->new_child); in clk_change_rate()
2544 return -EBUSY; in clk_core_set_rate_nolock()
2546 /* calculate new rates and get the topmost changed clock */ in clk_core_set_rate_nolock()
2549 return -EINVAL; in clk_core_set_rate_nolock()
2559 fail_clk->name); in clk_core_set_rate_nolock()
2561 ret = -EBUSY; in clk_core_set_rate_nolock()
2568 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2576 * clk_set_rate - specify a new rate for clk
2594 * Returns 0 on success, -EERROR otherwise.
2603 /* prevent racing with updates to the clock topology */ in clk_set_rate()
2606 if (clk->exclusive_count) in clk_set_rate()
2607 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2609 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2611 if (clk->exclusive_count) in clk_set_rate()
2612 clk_core_rate_protect(clk->core); in clk_set_rate()
2621 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2630 * same clock provider.
2637 * Returns 0 on success, -EERROR otherwise.
2646 /* prevent racing with updates to the clock topology */ in clk_set_rate_exclusive()
2652 * so before the consumer code path protect the clock provider in clk_set_rate_exclusive()
2655 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2657 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2658 clk->exclusive_count++; in clk_set_rate_exclusive()
2679 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2683 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2685 return -EINVAL; in clk_set_rate_range_nolock()
2688 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2689 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2692 old_min = clk->min_rate; in clk_set_rate_range_nolock()
2693 old_max = clk->max_rate; in clk_set_rate_range_nolock()
2694 clk->min_rate = min; in clk_set_rate_range_nolock()
2695 clk->max_rate = max; in clk_set_rate_range_nolock()
2697 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2698 ret = -EINVAL; in clk_set_rate_range_nolock()
2702 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2703 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2704 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2708 * opportunity to the provider to adjust the clock rate based on in clk_set_rate_range_nolock()
2711 * We also need to handle the case where the clock is currently in clk_set_rate_range_nolock()
2716 * There is a catch. It may fail for the usual reason (clock in clk_set_rate_range_nolock()
2717 * broken, clock protected, etc) but also because: in clk_set_rate_range_nolock()
2718 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range_nolock()
2720 * - the determine_rate() callback does not really check for in clk_set_rate_range_nolock()
2724 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2727 clk->min_rate = old_min; in clk_set_rate_range_nolock()
2728 clk->max_rate = old_max; in clk_set_rate_range_nolock()
2732 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2733 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2739 * clk_set_rate_range - set a rate range for a clock source
2740 * @clk: clock source
2741 * @min: desired minimum clock rate in Hz, inclusive
2742 * @max: desired maximum clock rate in Hz, inclusive
2764 * clk_set_min_rate - set a minimum clock rate for a clock source
2765 * @clk: clock source
2766 * @rate: desired minimum clock rate in Hz, inclusive
2775 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2777 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2782 * clk_set_max_rate - set a maximum clock rate for a clock source
2783 * @clk: clock source
2784 * @rate: desired maximum clock rate in Hz, inclusive
2793 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2795 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2800 * clk_get_parent - return the parent of a clk
2803 * Simply returns clk->parent. Returns NULL if clk is NULL.
2813 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2814 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2825 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2826 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2844 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2848 * clk_has_parent - check if a clock is a possible parent for another
2849 * @clk: clock source
2850 * @parent: parent clock source
2852 * This function can be used in drivers that need to check that a clock can be
2863 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2879 if (core->parent == parent) in clk_core_set_parent_nolock()
2882 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2883 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2884 return -EPERM; in clk_core_set_parent_nolock()
2886 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2887 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2888 return -EBUSY; in clk_core_set_parent_nolock()
2891 return -EBUSY; in clk_core_set_parent_nolock()
2898 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2901 p_rate = parent->rate; in clk_core_set_parent_nolock()
2915 /* do the re-parent */ in clk_core_set_parent_nolock()
2934 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2939 * clk_set_parent - switch the parent of a mux clk
2943 * Re-parent clk to use parent as its new input source. If clk is in
2953 * Returns 0 on success, -EERROR otherwise.
2964 if (clk->exclusive_count) in clk_set_parent()
2965 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2967 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2968 parent ? parent->core : NULL); in clk_set_parent()
2970 if (clk->exclusive_count) in clk_set_parent()
2971 clk_core_rate_protect(clk->core); in clk_set_parent()
2981 int ret = -EINVAL; in clk_core_set_phase_nolock()
2989 return -EBUSY; in clk_core_set_phase_nolock()
2993 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2994 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2996 core->phase = degrees; in clk_core_set_phase_nolock()
3005 * clk_set_phase - adjust the phase shift of a clock signal
3006 * @clk: clock signal source
3009 * Shifts the phase of a clock signal by the specified
3010 * degrees. Returns 0 on success, -EERROR otherwise.
3013 * signal that we adjust the clock signal phase against. For example
3014 * phase locked-loop clock signal generators we may shift phase with
3015 * respect to feedback clock signal input, but for other cases the
3016 * clock phase may be shifted with respect to some other, unspecified
3020 * the clock tree hierarchy, which sets it apart from clock rates and
3021 * clock accuracy. A parent clock phase attribute does not have an
3022 * impact on the phase attribute of a child clock.
3038 if (clk->exclusive_count) in clk_set_phase()
3039 clk_core_rate_unprotect(clk->core); in clk_set_phase()
3041 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
3043 if (clk->exclusive_count) in clk_set_phase()
3044 clk_core_rate_protect(clk->core); in clk_set_phase()
3057 if (!core->ops->get_phase) in clk_core_get_phase()
3061 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
3063 core->phase = ret; in clk_core_get_phase()
3069 * clk_get_phase - return the phase shift of a clock signal
3070 * @clk: clock signal source
3072 * Returns the phase shift of a clock node in degrees, otherwise returns
3073 * -EERROR.
3083 ret = clk_core_get_phase(clk->core); in clk_get_phase()
3093 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
3094 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
3101 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
3104 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
3107 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
3111 /* Don't trust the clock provider too much */ in clk_core_update_duty_cycle_nolock()
3112 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
3113 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
3128 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
3129 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
3130 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
3131 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
3150 return -EBUSY; in clk_core_set_duty_cycle_nolock()
3154 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3157 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3159 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3171 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3172 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3173 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3174 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3181 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
3182 * @clk: clock signal source
3186 * Apply the duty cycle ratio if the ratio is valid and the clock can
3201 return -EINVAL; in clk_set_duty_cycle()
3208 if (clk->exclusive_count) in clk_set_duty_cycle()
3209 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3211 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3213 if (clk->exclusive_count) in clk_set_duty_cycle()
3214 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3225 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3232 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
3240 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
3241 * @clk: clock signal source
3244 * Returns the duty cycle ratio of a clock node multiplied by the provided
3252 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3257 * clk_is_match - check if two clk's point to the same hardware clock
3262 * clock node. Put differently, returns true if struct clk *p and struct clk *q
3273 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
3275 if (p->core == q->core) in clk_is_match()
3304 seq_printf(s, "%*s%-*s %-7d %-8d %-8d %-11lu %-10lu ", in clk_summary_show_one()
3306 35 - level * 3, c->name, in clk_summary_show_one()
3307 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
3313 seq_printf(s, "%-5d", phase); in clk_summary_show_one()
3315 seq_puts(s, "-----"); in clk_summary_show_one()
3317 seq_printf(s, " %-6d", clk_core_get_scaled_duty_cycle(c, 100000)); in clk_summary_show_one()
3319 if (c->ops->is_enabled) in clk_summary_show_one()
3321 else if (!c->ops->enable) in clk_summary_show_one()
3326 hlist_for_each_entry(clk_user, &c->clks, clks_node) { in clk_summary_show_one()
3327 seq_printf(s, "%*s%-*s %-25s\n", in clk_summary_show_one()
3330 clk_user->dev_id ? clk_user->dev_id : "deviceless", in clk_summary_show_one()
3331 clk_user->con_id ? clk_user->con_id : "no_connection_id"); in clk_summary_show_one()
3345 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
3352 struct hlist_head **lists = s->private; in clk_summary_show()
3356 …seq_puts(s, " clock count count count rate accuracy phas… in clk_summary_show()
3357 …s(s, "--------------------------------------------------------------------------------------------… in clk_summary_show()
3384 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
3385 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
3386 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
3387 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
3405 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3417 struct hlist_head **lists = s->private; in clk_dump_show()
3487 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3489 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3498 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3530 *val = core->phase; in clk_phase_get()
3538 const char *name; member
3558 struct clk_core *core = s->private; in clk_flags_show()
3559 unsigned long flags = core->flags; in clk_flags_show()
3564 seq_printf(s, "%s\n", clk_flags[i].name); in clk_flags_show()
3581 const char *name = NULL; in possible_parent_show() local
3584 * Go through the following options to fetch a parent's name. in possible_parent_show()
3586 * 1. Fetch the registered parent clock and use its name in possible_parent_show()
3587 * 2. Use the global (fallback) name if specified in possible_parent_show()
3589 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3597 seq_puts(s, parent->name); in possible_parent_show()
3598 } else if (core->parents[i].name) { in possible_parent_show()
3599 seq_puts(s, core->parents[i].name); in possible_parent_show()
3600 } else if (core->parents[i].fw_name) { in possible_parent_show()
3601 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3603 if (core->parents[i].index >= 0) in possible_parent_show()
3604 name = of_clk_get_parent_name(core->of_node, core->parents[i].index); in possible_parent_show()
3605 if (!name) in possible_parent_show()
3606 name = "(missing)"; in possible_parent_show()
3608 seq_puts(s, name); in possible_parent_show()
3616 struct clk_core *core = s->private; in possible_parents_show()
3619 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3630 struct clk_core *core = s->private; in current_parent_show()
3632 if (core->parent) in current_parent_show()
3633 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3643 struct seq_file *s = file->private_data; in current_parent_write()
3644 struct clk_core *core = s->private; in current_parent_write()
3655 return -ENOENT; in current_parent_write()
3677 struct clk_core *core = s->private; in clk_duty_cycle_show()
3678 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3680 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3688 struct clk_core *core = s->private; in clk_min_rate_show()
3702 struct clk_core *core = s->private; in clk_max_rate_show()
3721 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3722 core->dentry = root; in clk_debug_create_one()
3728 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3732 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3733 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3734 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3735 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3742 if (core->num_parents > 1) in clk_debug_create_one()
3747 if (core->num_parents > 0) in clk_debug_create_one()
3751 if (core->num_parents > 1) in clk_debug_create_one()
3755 if (core->ops->debug_init) in clk_debug_create_one()
3756 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3760 * clk_debug_register - add a clk node to the debugfs clk directory
3770 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3777 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3781 * debugfs clk directory if clk->dentry points to debugfs created by
3787 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3788 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3789 core->dentry = NULL; in clk_debug_unregister()
3794 * clk_debug_init - lazily populate the debugfs clk directory
3798 * populates the debugfs clk directory once at boot-time when we know that
3799 * debugfs is setup. It should only be called once at boot-time, all other clks
3867 * clock. This is important for CLK_IS_CRITICAL clocks, which in clk_core_reparent_orphans_nolock()
3879 * 0 if the clock doesn't have clk_ops::recalc_rate and in clk_core_reparent_orphans_nolock()
3885 * 'req_rate' is set to something non-zero so that in clk_core_reparent_orphans_nolock()
3888 orphan->req_rate = orphan->rate; in clk_core_reparent_orphans_nolock()
3894 * __clk_core_init - initialize the data structures in a struct clk_core
3910 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3911 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3915 core->hw->core = core; in __clk_core_init()
3921 /* check to see if a clock with this name is already registered */ in __clk_core_init()
3922 if (clk_core_lookup(core->name)) { in __clk_core_init()
3924 __func__, core->name); in __clk_core_init()
3925 ret = -EEXIST; in __clk_core_init()
3929 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3930 if (core->ops->set_rate && in __clk_core_init()
3931 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3932 core->ops->recalc_rate)) { in __clk_core_init()
3934 __func__, core->name); in __clk_core_init()
3935 ret = -EINVAL; in __clk_core_init()
3939 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3941 __func__, core->name); in __clk_core_init()
3942 ret = -EINVAL; in __clk_core_init()
3946 if (core->ops->set_parent && !core->ops->determine_rate) { in __clk_core_init()
3948 __func__, core->name); in __clk_core_init()
3949 ret = -EINVAL; in __clk_core_init()
3953 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3955 __func__, core->name); in __clk_core_init()
3956 ret = -EINVAL; in __clk_core_init()
3960 if (core->ops->set_rate_and_parent && in __clk_core_init()
3961 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3963 __func__, core->name); in __clk_core_init()
3964 ret = -EINVAL; in __clk_core_init()
3969 * optional platform-specific magic in __clk_core_init()
3971 * The .init callback is not used by any of the basic clock types, but in __clk_core_init()
3973 * CCF to get an accurate view of clock for any other callbacks. It may in __clk_core_init()
3980 * the clock in __clk_core_init()
3982 if (core->ops->init) { in __clk_core_init()
3983 ret = core->ops->init(core->hw); in __clk_core_init()
3988 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3991 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3997 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
4001 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
4002 core->orphan = parent->orphan; in __clk_core_init()
4003 } else if (!core->num_parents) { in __clk_core_init()
4004 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
4005 core->orphan = false; in __clk_core_init()
4007 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
4008 core->orphan = true; in __clk_core_init()
4014 * fallback is to use the parent's accuracy. If a clock doesn't have a in __clk_core_init()
4016 * clock). in __clk_core_init()
4018 if (core->ops->recalc_accuracy) in __clk_core_init()
4019 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
4022 core->accuracy = parent->accuracy; in __clk_core_init()
4024 core->accuracy = 0; in __clk_core_init()
4029 * query the current clock phase, or just assume it's in phase. in __clk_core_init()
4035 core->name); in __clk_core_init()
4047 * parent's rate. If a clock doesn't have a parent (or is orphaned) in __clk_core_init()
4050 if (core->ops->recalc_rate) in __clk_core_init()
4051 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
4054 rate = parent->rate; in __clk_core_init()
4057 core->rate = core->req_rate = rate; in __clk_core_init()
4064 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
4068 __func__, core->name); in __clk_core_init()
4075 __func__, core->name); in __clk_core_init()
4086 hlist_del_init(&core->child_node); in __clk_core_init()
4087 core->hw->core = NULL; in __clk_core_init()
4099 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
4106 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
4111 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
4117 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
4121 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
4123 * @dev_id: string describing device name
4135 return ERR_PTR(-ENOMEM); in alloc_clk()
4137 clk->core = core; in alloc_clk()
4138 clk->dev_id = dev_id; in alloc_clk()
4139 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
4140 clk->max_rate = ULONG_MAX; in alloc_clk()
4146 * free_clk - Free a clk consumer
4154 kfree_const(clk->con_id); in free_clk()
4163 * @dev_id: string describing device name
4180 core = hw->core; in clk_hw_create_clk()
4184 clk->dev = dev; in clk_hw_create_clk()
4186 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
4188 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
4191 kref_get(&core->ref); in clk_hw_create_clk()
4198 * clk_hw_get_clk - get clk consumer given an clk_hw
4204 * to get a consumer clk and act on the clock element
4209 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4210 const char *name = dev ? dev_name(dev) : NULL; in clk_hw_get_clk() local
4212 return clk_hw_create_clk(dev, hw, name, con_id); in clk_hw_get_clk()
4222 return -EINVAL; in clk_cpy_name()
4228 return -ENOMEM; in clk_cpy_name()
4236 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
4237 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
4238 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
4239 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
4247 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
4251 core->parents = parents; in clk_core_populate_parent_map()
4253 return -ENOMEM; in clk_core_populate_parent_map()
4257 parent->index = -1; in clk_core_populate_parent_map()
4262 __func__, core->name); in clk_core_populate_parent_map()
4263 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
4266 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
4267 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
4268 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
4271 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
4272 parent_data[i].name, in clk_core_populate_parent_map()
4275 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
4277 ret = -EINVAL; in clk_core_populate_parent_map()
4283 kfree_const(parents[i].name); in clk_core_populate_parent_map()
4285 } while (--i >= 0); in clk_core_populate_parent_map()
4297 int i = core->num_parents; in clk_core_free_parent_map()
4299 if (!core->num_parents) in clk_core_free_parent_map()
4302 while (--i >= 0) { in clk_core_free_parent_map()
4303 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4304 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4307 kfree(core->parents); in clk_core_free_parent_map()
4315 if (core->rpm_enabled) { in __clk_release()
4317 hlist_del(&core->rpm_node); in __clk_release()
4322 kfree_const(core->name); in __clk_release()
4331 const struct clk_init_data *init = hw->init; in __clk_register()
4336 * we catch use of hw->init early on in the core. in __clk_register()
4338 hw->init = NULL; in __clk_register()
4342 ret = -ENOMEM; in __clk_register()
4346 kref_init(&core->ref); in __clk_register()
4348 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4349 if (!core->name) { in __clk_register()
4350 ret = -ENOMEM; in __clk_register()
4354 if (WARN_ON(!init->ops)) { in __clk_register()
4355 ret = -EINVAL; in __clk_register()
4358 core->ops = init->ops; in __clk_register()
4360 core->dev = dev; in __clk_register()
4362 core->of_node = np; in __clk_register()
4363 if (dev && dev->driver) in __clk_register()
4364 core->owner = dev->driver->owner; in __clk_register()
4365 core->hw = hw; in __clk_register()
4366 core->flags = init->flags; in __clk_register()
4367 core->num_parents = init->num_parents; in __clk_register()
4368 core->min_rate = 0; in __clk_register()
4369 core->max_rate = ULONG_MAX; in __clk_register()
4375 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4381 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4382 if (IS_ERR(hw->clk)) { in __clk_register()
4383 ret = PTR_ERR(hw->clk); in __clk_register()
4387 clk_core_link_consumer(core, hw->clk); in __clk_register()
4391 return hw->clk; in __clk_register()
4394 clk_core_unlink_consumer(hw->clk); in __clk_register()
4397 free_clk(hw->clk); in __clk_register()
4398 hw->clk = NULL; in __clk_register()
4404 kref_put(&core->ref, __clk_release); in __clk_register()
4410 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
4414 * @dev->parent if dev doesn't have a device node, or NULL if neither
4415 * @dev or @dev->parent have a device node.
4426 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
4432 * clk_register - allocate a new clock, register it and return an opaque cookie
4433 * @dev: device that is registering this clock
4434 * @hw: link to hardware-specific clock data
4436 * clk_register is the *deprecated* interface for populating the clock tree with
4437 * new clock nodes. Use clk_hw_register() instead.
4441 * rest of the clock API. In the event of an error clk_register will return an
4451 * clk_hw_register - register a clk_hw and return an error code
4452 * @dev: device that is registering this clock
4453 * @hw: link to hardware-specific clock data
4455 * clk_hw_register is the primary interface for populating the clock tree with
4456 * new clock nodes. It returns an integer equal to zero indicating success or
4468 * of_clk_hw_register - register a clk_hw and return an error code
4469 * @node: device_node of device that is registering this clock
4470 * @hw: link to hardware-specific clock data
4472 * of_clk_hw_register() is the primary interface for populating the clock tree
4473 * with new clock nodes when a struct device is not available, but a struct
4486 * after clk_unregister() was called on a clock and until last clock
4491 return -ENXIO; in clk_nodrv_prepare_enable()
4502 return -ENXIO; in clk_nodrv_set_rate()
4507 return -ENXIO; in clk_nodrv_set_parent()
4513 return -ENXIO; in clk_nodrv_determine_rate()
4532 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
4533 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4534 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4536 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
4555 * clk_unregister - unregister a currently registered clock
4556 * @clk: clock to unregister
4566 clk_debug_unregister(clk->core); in clk_unregister()
4570 ops = clk->core->ops; in clk_unregister()
4572 pr_err("%s: unregistered clock: %s\n", __func__, in clk_unregister()
4573 clk->core->name); in clk_unregister()
4578 * Assign empty clock ops for consumers that might still hold in clk_unregister()
4579 * a reference to this clock. in clk_unregister()
4582 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4585 if (ops->terminate) in clk_unregister()
4586 ops->terminate(clk->core->hw); in clk_unregister()
4588 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4593 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4598 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4600 hlist_del_init(&clk->core->child_node); in clk_unregister()
4602 if (clk->core->prepare_count) in clk_unregister()
4603 pr_warn("%s: unregistering prepared clock: %s\n", in clk_unregister()
4604 __func__, clk->core->name); in clk_unregister()
4606 if (clk->core->protect_count) in clk_unregister()
4607 pr_warn("%s: unregistering protected clock: %s\n", in clk_unregister()
4608 __func__, clk->core->name); in clk_unregister()
4611 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4617 * clk_hw_unregister - unregister a currently registered clk_hw
4618 * @hw: hardware-specific clock data to unregister
4622 clk_unregister(hw->clk); in clk_hw_unregister()
4637 * devm_clk_register - resource managed clk_register()
4638 * @dev: device that is registering this clock
4639 * @hw: link to hardware-specific clock data
4653 return ERR_PTR(-ENOMEM); in devm_clk_register()
4668 * devm_clk_hw_register - resource managed clk_hw_register()
4669 * @dev: device that is registering this clock
4670 * @hw: link to hardware-specific clock data
4683 return -ENOMEM; in devm_clk_hw_register()
4703 * devm_clk_hw_get_clk - resource managed clk_hw_get_clk()
4704 * @dev: device that is registering this clock
4722 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4726 return ERR_PTR(-ENOMEM); in devm_clk_hw_get_clk()
4758 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4760 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4761 clk_core_rate_unprotect(clk->core); in __clk_put()
4762 clk->exclusive_count = 0; in __clk_put()
4767 /* If we had any boundaries on that clock, let's drop them. */ in __clk_put()
4768 if (clk->min_rate > 0 || clk->max_rate < ULONG_MAX) in __clk_put()
4773 owner = clk->core->owner; in __clk_put()
4774 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4782 * clk_notifier_register - add a clk rate change notifier
4789 * re-enter into the clk framework by calling any top-level clk APIs;
4793 * clock rate is passed to the callback via struct clk_notifier_data.old_rate
4796 * clk_notifier_register() must be called from non-atomic context.
4797 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4804 int ret = -ENOMEM; in clk_notifier_register()
4807 return -EINVAL; in clk_notifier_register()
4813 if (cn->clk == clk) in clk_notifier_register()
4821 cn->clk = clk; in clk_notifier_register()
4822 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4824 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4827 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4829 clk->core->notifier_count++; in clk_notifier_register()
4839 * clk_notifier_unregister - remove a clk rate change notifier
4846 * Returns -EINVAL if called with null arguments; otherwise, passes
4852 int ret = -ENOENT; in clk_notifier_unregister()
4855 return -EINVAL; in clk_notifier_unregister()
4860 if (cn->clk == clk) { in clk_notifier_unregister()
4861 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4863 clk->core->notifier_count--; in clk_notifier_unregister()
4866 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4867 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4868 list_del(&cn->node); in clk_notifier_unregister()
4890 clk_notifier_unregister(devres->clk, devres->nb); in devm_clk_notifier_release()
4903 return -ENOMEM; in devm_clk_notifier_register()
4907 devres->clk = clk; in devm_clk_notifier_register()
4908 devres->nb = nb; in devm_clk_notifier_register()
4927 * struct of_clk_provider - Clock provider registration structure
4928 * @link: Entry in global list of clock providers
4929 * @node: Pointer to device tree node of clock provider
4930 * @get: Get clock callback. Returns NULL or a struct clk for the
4931 * given clock specifier
4933 * struct clk_hw for the given clock specifier
4968 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4970 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4971 pr_err("%s: invalid clock index %u\n", __func__, idx); in of_clk_src_onecell_get()
4972 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4975 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4983 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4985 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4987 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4990 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4995 * of_clk_add_provider() - Register a clock provider for a node
4996 * @np: Device node pointer associated with clock provider
4997 * @clk_src_get: callback for decoding clock
5015 return -ENOMEM; in of_clk_add_provider()
5017 cp->node = of_node_get(np); in of_clk_add_provider()
5018 cp->data = data; in of_clk_add_provider()
5019 cp->get = clk_src_get; in of_clk_add_provider()
5022 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
5024 pr_debug("Added clock from %pOF\n", np); in of_clk_add_provider()
5032 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_provider()
5039 * of_clk_add_hw_provider() - Register a clock provider for a node
5040 * @np: Device node pointer associated with clock provider
5057 return -ENOMEM; in of_clk_add_hw_provider()
5059 cp->node = of_node_get(np); in of_clk_add_hw_provider()
5060 cp->data = data; in of_clk_add_hw_provider()
5061 cp->get_hw = get; in of_clk_add_hw_provider()
5064 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
5074 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_hw_provider()
5086 * We allow a child device to use its parent device as the clock provider node
5087 * for cases like MFD sub-devices where the child device driver wants to use
5088 * devm_*() APIs but not list the device in DT as a sub-node.
5094 np = dev->of_node; in get_clk_provider_node()
5095 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
5097 if (!of_property_present(np, "#clock-cells")) in get_clk_provider_node()
5098 if (of_property_present(parent_np, "#clock-cells")) in get_clk_provider_node()
5105 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
5106 * @dev: Device acting as the clock provider (used for DT node and lifetime)
5110 * Registers clock provider for given device's node. If the device has no DT
5111 * node or if the device node lacks of clock provider information (#clock-cells)
5113 * has the #clock-cells then it is used in registration. Provider is
5129 return -ENOMEM; in devm_of_clk_add_hw_provider()
5145 * of_clk_del_provider() - Remove a previously registered clock provider
5146 * @np: Device node pointer associated with clock provider
5157 if (cp->node == np) { in of_clk_del_provider()
5158 list_del(&cp->link); in of_clk_del_provider()
5159 fwnode_dev_initialized(&np->fwnode, false); in of_clk_del_provider()
5160 of_node_put(cp->node); in of_clk_del_provider()
5170 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
5171 * @np: device node to parse clock specifier from
5172 * @index: index of phandle to parse clock out of. If index < 0, @name is used
5173 * @name: clock name to find and parse. If name is NULL, the index is used
5174 * @out_args: Result of parsing the clock specifier
5176 * Parses a device node's "clocks" and "clock-names" properties to find the
5177 * phandle and cells for the index or name that is desired. The resulting clock
5179 * parsing error. The @index argument is ignored if @name is non-NULL.
5183 * phandle1: clock-controller@1 {
5184 * #clock-cells = <2>;
5187 * phandle2: clock-controller@2 {
5188 * #clock-cells = <1>;
5191 * clock-consumer@3 {
5193 * clock-names = "name1", "name2";
5196 * To get a device_node for `clock-controller@2' node you may call this
5199 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
5200 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
5201 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
5203 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
5204 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
5205 * the "clock-names" property of @np.
5208 const char *name, struct of_phandle_args *out_args) in of_parse_clkspec() argument
5210 int ret = -ENOENT; in of_parse_clkspec()
5212 /* Walk up the tree of devices looking for a clock property that matches */ in of_parse_clkspec()
5215 * For named clocks, first look up the name in the in of_parse_clkspec()
5216 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
5218 * return -EINVAL. in of_parse_clkspec()
5220 if (name) in of_parse_clkspec()
5221 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
5222 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
5226 if (name && index >= 0) in of_parse_clkspec()
5230 * No matching clock found on this node. If the parent node in of_parse_clkspec()
5231 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
5234 np = np->parent; in of_parse_clkspec()
5235 if (np && !of_property_present(np, "clock-ranges")) in of_parse_clkspec()
5249 if (provider->get_hw) in __of_clk_get_hw_from_provider()
5250 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5252 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5262 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
5265 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
5269 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
5281 * of_clk_get_from_provider() - Lookup a clock from a clock provider
5282 * @clkspec: pointer to a clock specifier data structure
5284 * This function looks up a struct clk from the registered list of clock
5285 * providers, an input is a clock specifier data structure as returned
5324 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
5329 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
5330 * @np: pointer to clock consumer node
5331 * @name: name of consumer's clock input, or NULL for the first clock reference
5333 * This function parses the clocks and clock-names properties,
5334 * and uses them to look up the struct clk from the registered list of clock
5337 struct clk *of_clk_get_by_name(struct device_node *np, const char *name) in of_clk_get_by_name() argument
5340 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
5342 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
5347 * of_clk_get_parent_count() - Count the number of clocks a device node has
5356 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
5374 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
5383 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
5385 of_property_for_each_u32(clkspec.np, "clock-indices", pv) { in of_clk_get_parent_name()
5393 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
5394 if (of_property_present(clkspec.np, "clock-indices") && !found) in of_clk_get_parent_name()
5397 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
5401 * Best effort to get the name if the clock has been in of_clk_get_parent_name()
5402 * registered with the framework. If the clock isn't in of_clk_get_parent_name()
5403 * registered, we return the node name as the name of in of_clk_get_parent_name()
5404 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
5409 clk_name = clkspec.np->name; in of_clk_get_parent_name()
5425 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
5427 * @np: Device node pointer associated with clock provider
5431 * Return: number of parents for the clock node.
5452 * This function looks for a parent clock. If there is one, then it
5453 * checks that the provider for this parent clock was initialized, in
5454 * this case the parent clock will be ready.
5471 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
5478 * previous parent are ready. If there is no clock in parent_ready()
5487 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
5488 * @np: Device node pointer associated with clock provider
5489 * @index: clock index
5490 * @flags: pointer to top-level framework flags
5492 * Detects if the clock-critical property exists and, if so, sets the
5496 * bindings, such as the one-clock-per-node style that are outdated.
5497 * Those bindings typically put all clock data into .dts and the Linux
5498 * driver has no clock data, thus making it impossible to set this flag
5510 return -EINVAL; in of_clk_detect_critical()
5512 of_property_for_each_u32(np, "clock-critical", idx) in of_clk_detect_critical()
5520 * of_clk_init() - Scan and init clock providers from the DT
5523 * This function scans the device tree for matching clock providers
5550 list_del(&clk_provider->node); in of_clk_init()
5551 of_node_put(clk_provider->np); in of_clk_init()
5558 parent->clk_init_cb = match->data; in of_clk_init()
5559 parent->np = of_node_get(np); in of_clk_init()
5560 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5567 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5570 of_node_set_flag(clk_provider->np, in of_clk_init()
5573 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5574 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5576 list_del(&clk_provider->node); in of_clk_init()
5577 of_node_put(clk_provider->np); in of_clk_init()
5587 * in case the clock parent was not mandatory in of_clk_init()