Lines Matching +full:clock +full:- +full:accuracy
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
4 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
6 * Standard functionality for the common clock API. See Documentation/driver-api/clk.rst
9 #include <linux/clk/clk-conf.h>
12 #include <linux/clk-provider.h>
91 unsigned long accuracy; member
123 if (!core->rpm_enabled) in clk_pm_runtime_get()
126 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
131 if (!core->rpm_enabled) in clk_pm_runtime_put()
134 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
138 * clk_pm_runtime_get_all() - Runtime "get" all clk provider devices
173 dev_name(failed->dev), failed->name); in clk_pm_runtime_get_all()
193 * clk_pm_runtime_put_all() - Runtime "put" all clk provider devices
209 struct device *dev = core->dev; in clk_pm_runtime_init()
212 core->rpm_enabled = true; in clk_pm_runtime_init()
215 hlist_add_head(&core->rpm_node, &clk_rpm_list); in clk_pm_runtime_init()
241 if (--prepare_refcnt) in clk_prepare_unlock()
281 if (--enable_refcnt) { in clk_enable_unlock()
291 return core->protect_count; in clk_core_rate_is_protected()
302 if (!core->ops->is_prepared) in clk_core_is_prepared()
303 return core->prepare_count; in clk_core_is_prepared()
306 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
321 if (!core->ops->is_enabled) in clk_core_is_enabled()
322 return core->enable_count; in clk_core_is_enabled()
325 * Check if clock controller's device is runtime active before in clk_core_is_enabled()
326 * calling .is_enabled callback. If not, assume that clock is in clk_core_is_enabled()
334 if (core->rpm_enabled) { in clk_core_is_enabled()
335 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
336 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
345 * anything here. We can also assume this clock isn't enabled. in clk_core_is_enabled()
347 if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) in clk_core_is_enabled()
348 if (!clk_core_is_enabled(core->parent)) { in clk_core_is_enabled()
353 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
355 if (core->rpm_enabled) in clk_core_is_enabled()
356 pm_runtime_put(core->dev); in clk_core_is_enabled()
365 return !clk ? NULL : clk->core->name; in __clk_get_name()
371 return hw->core->name; in clk_hw_get_name()
377 return hw->core->dev; in clk_hw_get_dev()
383 return hw->core->of_node; in clk_hw_get_of_node()
389 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
395 return hw->core->num_parents; in clk_hw_get_num_parents()
401 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
417 if (!strcmp(core->name, name)) in clk_core_lookup()
433 return -ENOENT; in of_parse_clkspec()
438 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
443 * clk_core_get - Find the clk_core parent of a clk
450 * node's 'clock-names' property or as the 'con_id' matching the device's
454 * For example the following DT snippet would allow a clock registered by the
455 * clock-controller@c001 that has a clk_init_data::parent_data array
456 * with 'xtal' in the 'name' member to find the clock provided by the
457 * clock-controller@f00abcd without needing to get the globally unique name of
460 * parent: clock-controller@f00abcd {
462 * #clock-cells = <0>;
465 * clock-controller@c001 {
468 * clock-names = "xtal";
469 * #clock-cells = <1>;
472 * Returns: -ENOENT when the provider can't be found or the clk doesn't
480 const char *name = core->parents[p_index].fw_name; in clk_core_get()
481 int index = core->parents[p_index].index; in clk_core_get()
482 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
483 struct device *dev = core->dev; in clk_core_get()
485 struct device_node *np = core->of_node; in clk_core_get()
506 return hw->core; in clk_core_get()
511 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
514 if (entry->hw) { in clk_core_fill_parent_index()
515 parent = entry->hw->core; in clk_core_fill_parent_index()
518 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
519 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
528 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
532 entry->core = parent; in clk_core_fill_parent_index()
538 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
541 if (!core->parents[index].core) in clk_core_get_parent_by_index()
544 return core->parents[index].core; in clk_core_get_parent_by_index()
552 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
554 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
560 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
568 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
569 return core->rate; in clk_core_get_rate_nolock()
581 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
590 return core->accuracy; in clk_core_get_accuracy_no_lock()
595 return hw->core->flags; in clk_hw_get_flags()
601 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
607 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
616 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
624 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
642 if (core->parent == parent) in clk_core_has_parent()
645 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
669 if (req->min_rate < old_req->min_rate) in clk_core_forward_rate_req()
670 req->min_rate = old_req->min_rate; in clk_core_forward_rate_req()
672 if (req->max_rate > old_req->max_rate) in clk_core_forward_rate_req()
673 req->max_rate = old_req->max_rate; in clk_core_forward_rate_req()
680 struct clk_core *core = hw->core; in clk_core_determine_rate_no_reparent()
681 struct clk_core *parent = core->parent; in clk_core_determine_rate_no_reparent()
685 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_determine_rate_no_reparent()
689 req->rate = 0; in clk_core_determine_rate_no_reparent()
694 req->rate); in clk_core_determine_rate_no_reparent()
711 req->best_parent_rate = best; in clk_core_determine_rate_no_reparent()
712 req->rate = best; in clk_core_determine_rate_no_reparent()
721 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags()
726 if (core->flags & CLK_SET_RATE_NO_REPARENT) in clk_mux_determine_rate_flags()
730 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
738 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
741 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
756 if (mux_is_better_rate(req->rate, parent_rate, in clk_mux_determine_rate_flags()
764 return -EINVAL; in clk_mux_determine_rate_flags()
766 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
767 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
768 req->rate = best; in clk_mux_determine_rate_flags()
778 return !core ? NULL : core->hw->clk; in __clk_lookup()
789 *min_rate = core->min_rate; in clk_core_get_boundaries()
790 *max_rate = core->max_rate; in clk_core_get_boundaries()
792 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
793 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
795 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
796 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
800 * clk_hw_get_rate_range() - returns the clock rate range for a hw clk
806 * maximum that clock can reach.
811 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
823 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
826 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
827 if (min_rate > user->max_rate || max_rate < user->min_rate) in clk_core_check_boundaries()
836 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
837 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
842 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
848 * complex clock that may combine a mux with other operations.
850 * Returns: 0 on success, -EERROR value on error
867 …* clk_hw_determine_rate_no_reparent - clk_ops::determine_rate implementation for a clk that doesn'…
873 * mux), or from a more complex clock that may combine a mux with other
876 * Returns: 0 on success, -EERROR value on error
894 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
895 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
898 if (--core->protect_count > 0) in clk_core_rate_unprotect()
901 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
911 return -EINVAL; in clk_core_rate_nuke_protect()
913 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
916 ret = core->protect_count; in clk_core_rate_nuke_protect()
917 core->protect_count = 1; in clk_core_rate_nuke_protect()
924 * clk_rate_exclusive_put - release exclusivity over clock rate control
927 * clk_rate_exclusive_put() completes a critical section during which a clock
929 * clock which could result in a rate change or rate glitch. Exclusive clocks
934 * If exlusivity is claimed more than once on clock, even by the same consumer,
952 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
955 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
956 clk->exclusive_count--; in clk_rate_exclusive_put()
969 if (core->protect_count == 0) in clk_core_rate_protect()
970 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
972 core->protect_count++; in clk_core_rate_protect()
986 core->protect_count = count; in clk_core_rate_restore_protect()
990 * clk_rate_exclusive_get - get exclusivity over the clk rate control
993 * clk_rate_exclusive_get() begins a critical section during which a clock
995 * clock which could result in a rate change or rate glitch. Exclusive clocks
1000 * If exlusivity is claimed more than once on clock, even by the same consumer,
1005 * Returns 0 on success, -EERROR otherwise
1013 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
1014 clk->exclusive_count++; in clk_rate_exclusive_get()
1047 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
1048 "%s already unprepared\n", core->name)) in clk_core_unprepare()
1051 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
1052 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
1055 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
1058 if (--core->prepare_count > 0) in clk_core_unprepare()
1061 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
1065 if (core->ops->unprepare) in clk_core_unprepare()
1066 core->ops->unprepare(core->hw); in clk_core_unprepare()
1069 clk_core_unprepare(core->parent); in clk_core_unprepare()
1081 * clk_unprepare - undo preparation of a clock source
1096 clk_core_unprepare_lock(clk->core); in clk_unprepare()
1109 if (core->prepare_count == 0) { in clk_core_prepare()
1114 ret = clk_core_prepare(core->parent); in clk_core_prepare()
1120 if (core->ops->prepare) in clk_core_prepare()
1121 ret = core->ops->prepare(core->hw); in clk_core_prepare()
1129 core->prepare_count++; in clk_core_prepare()
1132 * CLK_SET_RATE_GATE is a special case of clock protection in clk_core_prepare()
1136 * the clock is prepared. in clk_core_prepare()
1138 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1143 clk_core_unprepare(core->parent); in clk_core_prepare()
1161 * clk_prepare - prepare a clock source
1170 * Returns 0 on success, -EERROR otherwise.
1177 return clk_core_prepare_lock(clk->core); in clk_prepare()
1188 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1191 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1192 "Disabling critical %s\n", core->name)) in clk_core_disable()
1195 if (--core->enable_count > 0) in clk_core_disable()
1200 if (core->ops->disable) in clk_core_disable()
1201 core->ops->disable(core->hw); in clk_core_disable()
1205 clk_core_disable(core->parent); in clk_core_disable()
1218 * clk_disable - gate a clock
1224 * SoC-internal clk which is controlled via simple register writes. In the
1234 clk_core_disable_lock(clk->core); in clk_disable()
1247 if (WARN(core->prepare_count == 0, in clk_core_enable()
1248 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1249 return -ESHUTDOWN; in clk_core_enable()
1251 if (core->enable_count == 0) { in clk_core_enable()
1252 ret = clk_core_enable(core->parent); in clk_core_enable()
1259 if (core->ops->enable) in clk_core_enable()
1260 ret = core->ops->enable(core->hw); in clk_core_enable()
1265 clk_core_disable(core->parent); in clk_core_enable()
1270 core->enable_count++; in clk_core_enable()
1287 * clk_gate_restore_context - restore context for poweroff
1288 * @hw: the clk_hw pointer of clock whose state is to be restored
1290 * The clock gate restore context function enables or disables
1292 * where the clock context is lost and based on the enable_count
1293 * the clock either needs to be enabled/disabled. This
1298 struct clk_core *core = hw->core; in clk_gate_restore_context()
1300 if (core->enable_count) in clk_gate_restore_context()
1301 core->ops->enable(hw); in clk_gate_restore_context()
1303 core->ops->disable(hw); in clk_gate_restore_context()
1312 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1318 if (core->ops && core->ops->save_context) in clk_core_save_context()
1319 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1328 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1329 core->ops->restore_context(core->hw); in clk_core_restore_context()
1331 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1336 * clk_save_context - save clock context for poweroff
1338 * Saves the context of the clock register for powerstates in which the
1364 * clk_restore_context - restore clock context after poweroff
1366 * Restore the saved clock context upon resume.
1382 * clk_enable - ungate a clock
1387 * if the operation will never sleep. One example is a SoC-internal clk which
1391 * must be called before clk_enable. Returns 0 on success, -EERROR
1399 return clk_core_enable_lock(clk->core); in clk_enable()
1404 * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it.
1405 * @clk: clock source
1407 * Returns true if clk_prepare() implicitly enables the clock, effectively
1408 * making clk_enable()/clk_disable() no-ops, false otherwise.
1411 * disabling the clock also requires unpreparing it to have any material
1420 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1451 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1454 if (core->prepare_count) in clk_unprepare_unused_subtree()
1457 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1462 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1463 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1464 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1465 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1477 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1480 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1481 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1485 if (core->enable_count) in clk_disable_unused_subtree()
1488 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1492 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1498 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1499 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1500 else if (core->ops->disable) in clk_disable_unused_subtree()
1501 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1507 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1508 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1571 * Some clock providers hand-craft their clk_rate_requests and in clk_core_determine_round_nolock()
1578 if (!req->min_rate && !req->max_rate) in clk_core_determine_round_nolock()
1580 __func__, core->name); in clk_core_determine_round_nolock()
1582 req->rate = clamp(req->rate, req->min_rate, req->max_rate); in clk_core_determine_round_nolock()
1586 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1587 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1591 req->rate = core->rate; in clk_core_determine_round_nolock()
1592 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1593 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1594 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1595 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1596 &req->best_parent_rate); in clk_core_determine_round_nolock()
1600 req->rate = rate; in clk_core_determine_round_nolock()
1602 return -EINVAL; in clk_core_determine_round_nolock()
1618 req->max_rate = ULONG_MAX; in clk_core_init_rate_req()
1623 req->core = core; in clk_core_init_rate_req()
1624 req->rate = rate; in clk_core_init_rate_req()
1625 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1627 parent = core->parent; in clk_core_init_rate_req()
1629 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1630 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1632 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1633 req->best_parent_rate = 0; in clk_core_init_rate_req()
1638 * clk_hw_init_rate_request - Initializes a clk_rate_request
1653 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1658 * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent
1659 * @hw: the original clock that got the rate request
1665 * Initializes a clk_rate_request structure to submit to a clock parent
1677 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1678 parent->core, req, in clk_hw_forward_rate_request()
1685 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1696 req->rate = 0; in clk_core_round_rate_nolock()
1703 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1706 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1710 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1716 req->best_parent_rate = parent_req.rate; in clk_core_round_rate_nolock()
1717 req->rate = parent_req.rate; in clk_core_round_rate_nolock()
1722 req->rate = core->rate; in clk_core_round_rate_nolock()
1727 * __clk_determine_rate - get the closest rate actually supported by a clock
1728 * @hw: determine the rate of this clock
1736 req->rate = 0; in __clk_determine_rate()
1740 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1745 * clk_hw_round_rate() - round the given rate for a hw clk
1764 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1768 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1779 * clk_round_rate - round the given rate for a clk
1797 if (clk->exclusive_count) in clk_round_rate()
1798 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1800 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1804 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1808 if (clk->exclusive_count) in clk_round_rate()
1809 clk_core_rate_protect(clk->core); in clk_round_rate()
1821 * __clk_notify - call clk notifier chain
1827 * Triggers a notifier call chain on the clk rate-change notification
1830 * internal clock code only. Returns NOTIFY_DONE from the last driver
1845 if (cn->clk->core == core) { in __clk_notify()
1846 cnd.clk = cn->clk; in __clk_notify()
1847 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1863 * callback then it is assumed that the clock will take on the accuracy of its
1873 if (core->parent) in __clk_recalc_accuracies()
1874 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1876 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1877 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1880 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1882 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1888 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1895 * clk_get_accuracy - return the accuracy of clk
1896 * @clk: the clk whose accuracy is being returned
1898 * Simply returns the cached accuracy of the clk, unless
1905 long accuracy; in clk_get_accuracy() local
1911 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1914 return accuracy; in clk_get_accuracy()
1923 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1924 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1938 * it is assumed that the clock will take on the rate of its parent.
1952 old_rate = core->rate; in __clk_recalc_rates()
1954 if (core->parent) in __clk_recalc_rates()
1955 parent_rate = core->parent->rate; in __clk_recalc_rates()
1957 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1959 core->req_rate = core->rate; in __clk_recalc_rates()
1965 if (core->notifier_count && msg) in __clk_recalc_rates()
1966 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1968 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1974 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1981 * clk_get_rate - return the rate of clk
1986 * the clock enabledness. If clk is NULL, or if an error occurred, then returns
1997 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
2010 return -EINVAL; in clk_fetch_parent_index()
2012 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
2014 if (core->parents[i].core == parent) in clk_fetch_parent_index()
2018 if (core->parents[i].core) in clk_fetch_parent_index()
2022 if (core->parents[i].hw) { in clk_fetch_parent_index()
2023 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
2035 if (core->parents[i].name && in clk_fetch_parent_index()
2036 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
2040 if (i == core->num_parents) in clk_fetch_parent_index()
2041 return -EINVAL; in clk_fetch_parent_index()
2043 core->parents[i].core = parent; in clk_fetch_parent_index()
2048 * clk_hw_get_parent_index - return the index of the parent clock
2051 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
2052 * clock does not have a current parent.
2059 return -EINVAL; in clk_hw_get_parent_index()
2061 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
2072 core->orphan = is_orphan; in clk_core_update_orphan_status()
2074 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
2080 bool was_orphan = core->orphan; in clk_reparent()
2082 hlist_del(&core->child_node); in clk_reparent()
2085 bool becomes_orphan = new_parent->orphan; in clk_reparent()
2088 if (new_parent->new_child == core) in clk_reparent()
2089 new_parent->new_child = NULL; in clk_reparent()
2091 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
2096 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
2101 core->parent = new_parent; in clk_reparent()
2108 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
2111 * 1. enable parents for CLK_OPS_PARENT_ENABLE clock in __clk_set_parent_before()
2116 * If the clock is not prepared, then a race with in __clk_set_parent_before()
2121 * If the clock is prepared, migrate the prepared state to the new in __clk_set_parent_before()
2123 * forcing the clock and the new parent on. This ensures that all in __clk_set_parent_before()
2131 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2137 if (core->prepare_count) { in __clk_set_parent_before()
2158 if (core->prepare_count) { in __clk_set_parent_after()
2163 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
2164 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2181 /* change clock input source */ in __clk_set_parent()
2182 if (parent && core->ops->set_parent) in __clk_set_parent()
2183 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2211 * pre-rate change notifications and returns early if no clks in the
2213 * implement the .recalc_rate callback then it is assumed that the clock will
2228 if (core->notifier_count) in __clk_speculate_rates()
2229 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2232 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
2233 __func__, core->name, ret); in __clk_speculate_rates()
2237 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2252 core->new_rate = new_rate; in clk_calc_subtree()
2253 core->new_parent = new_parent; in clk_calc_subtree()
2254 core->new_parent_index = p_index; in clk_calc_subtree()
2256 core->new_child = NULL; in clk_calc_subtree()
2257 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2258 new_parent->new_child = core; in clk_calc_subtree()
2260 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2261 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
2262 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
2267 * calculate the new rates returning the topmost clock that has to be
2287 parent = old_parent = core->parent; in clk_calc_new_rates()
2289 best_parent_rate = parent->rate; in clk_calc_new_rates()
2309 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2313 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2314 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
2315 core->new_rate = core->rate; in clk_calc_new_rates()
2318 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
2320 new_rate = parent->new_rate; in clk_calc_new_rates()
2326 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2328 __func__, core->name); in clk_calc_new_rates()
2333 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2337 __func__, parent->name, core->name); in clk_calc_new_rates()
2342 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2343 best_parent_rate != parent->rate) in clk_calc_new_rates()
2363 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2366 if (core->notifier_count) { in clk_propagate_rate_change()
2367 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2372 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2373 /* Skip children who will be reparented to another clock */ in clk_propagate_rate_change()
2374 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2381 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2382 if (core->new_child) { in clk_propagate_rate_change()
2383 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2405 old_rate = core->rate; in clk_change_rate()
2407 if (core->new_parent) { in clk_change_rate()
2408 parent = core->new_parent; in clk_change_rate()
2409 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2410 } else if (core->parent) { in clk_change_rate()
2411 parent = core->parent; in clk_change_rate()
2412 best_parent_rate = core->parent->rate; in clk_change_rate()
2418 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2423 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2424 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2425 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2427 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2429 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2431 core->new_parent_index); in clk_change_rate()
2432 } else if (core->ops->set_parent) { in clk_change_rate()
2433 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2436 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2437 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2440 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2443 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2445 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2446 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2448 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2450 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2452 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2457 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2460 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2461 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2463 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2464 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2468 * for certain clock types. in clk_change_rate()
2470 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2471 /* Skip children who will be reparented to another clock */ in clk_change_rate()
2472 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2477 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2478 if (core->new_child) in clk_change_rate()
2479 clk_change_rate(core->new_child); in clk_change_rate()
2532 return -EBUSY; in clk_core_set_rate_nolock()
2534 /* calculate new rates and get the topmost changed clock */ in clk_core_set_rate_nolock()
2537 return -EINVAL; in clk_core_set_rate_nolock()
2547 fail_clk->name); in clk_core_set_rate_nolock()
2549 ret = -EBUSY; in clk_core_set_rate_nolock()
2556 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2564 * clk_set_rate - specify a new rate for clk
2582 * Returns 0 on success, -EERROR otherwise.
2591 /* prevent racing with updates to the clock topology */ in clk_set_rate()
2594 if (clk->exclusive_count) in clk_set_rate()
2595 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2597 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2599 if (clk->exclusive_count) in clk_set_rate()
2600 clk_core_rate_protect(clk->core); in clk_set_rate()
2609 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2618 * same clock provider.
2625 * Returns 0 on success, -EERROR otherwise.
2634 /* prevent racing with updates to the clock topology */ in clk_set_rate_exclusive()
2640 * so before the consumer code path protect the clock provider in clk_set_rate_exclusive()
2643 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2645 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2646 clk->exclusive_count++; in clk_set_rate_exclusive()
2667 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2671 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2673 return -EINVAL; in clk_set_rate_range_nolock()
2676 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2677 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2680 old_min = clk->min_rate; in clk_set_rate_range_nolock()
2681 old_max = clk->max_rate; in clk_set_rate_range_nolock()
2682 clk->min_rate = min; in clk_set_rate_range_nolock()
2683 clk->max_rate = max; in clk_set_rate_range_nolock()
2685 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2686 ret = -EINVAL; in clk_set_rate_range_nolock()
2690 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2691 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2692 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2696 * opportunity to the provider to adjust the clock rate based on in clk_set_rate_range_nolock()
2699 * We also need to handle the case where the clock is currently in clk_set_rate_range_nolock()
2704 * There is a catch. It may fail for the usual reason (clock in clk_set_rate_range_nolock()
2705 * broken, clock protected, etc) but also because: in clk_set_rate_range_nolock()
2706 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range_nolock()
2708 * - the determine_rate() callback does not really check for in clk_set_rate_range_nolock()
2712 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2715 clk->min_rate = old_min; in clk_set_rate_range_nolock()
2716 clk->max_rate = old_max; in clk_set_rate_range_nolock()
2720 if (clk->exclusive_count) in clk_set_rate_range_nolock()
2721 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2727 * clk_set_rate_range - set a rate range for a clock source
2728 * @clk: clock source
2729 * @min: desired minimum clock rate in Hz, inclusive
2730 * @max: desired maximum clock rate in Hz, inclusive
2752 * clk_set_min_rate - set a minimum clock rate for a clock source
2753 * @clk: clock source
2754 * @rate: desired minimum clock rate in Hz, inclusive
2763 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2765 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2770 * clk_set_max_rate - set a maximum clock rate for a clock source
2771 * @clk: clock source
2772 * @rate: desired maximum clock rate in Hz, inclusive
2781 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2783 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2788 * clk_get_parent - return the parent of a clk
2791 * Simply returns clk->parent. Returns NULL if clk is NULL.
2801 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2802 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2813 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2814 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2832 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2836 * clk_has_parent - check if a clock is a possible parent for another
2837 * @clk: clock source
2838 * @parent: parent clock source
2840 * This function can be used in drivers that need to check that a clock can be
2851 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2867 if (core->parent == parent) in clk_core_set_parent_nolock()
2870 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2871 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2872 return -EPERM; in clk_core_set_parent_nolock()
2874 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2875 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2876 return -EBUSY; in clk_core_set_parent_nolock()
2879 return -EBUSY; in clk_core_set_parent_nolock()
2886 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2889 p_rate = parent->rate; in clk_core_set_parent_nolock()
2903 /* do the re-parent */ in clk_core_set_parent_nolock()
2906 /* propagate rate an accuracy recalculation accordingly */ in clk_core_set_parent_nolock()
2922 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2927 * clk_set_parent - switch the parent of a mux clk
2931 * Re-parent clk to use parent as its new input source. If clk is in
2941 * Returns 0 on success, -EERROR otherwise.
2952 if (clk->exclusive_count) in clk_set_parent()
2953 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2955 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2956 parent ? parent->core : NULL); in clk_set_parent()
2958 if (clk->exclusive_count) in clk_set_parent()
2959 clk_core_rate_protect(clk->core); in clk_set_parent()
2969 int ret = -EINVAL; in clk_core_set_phase_nolock()
2977 return -EBUSY; in clk_core_set_phase_nolock()
2981 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2982 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2984 core->phase = degrees; in clk_core_set_phase_nolock()
2993 * clk_set_phase - adjust the phase shift of a clock signal
2994 * @clk: clock signal source
2997 * Shifts the phase of a clock signal by the specified
2998 * degrees. Returns 0 on success, -EERROR otherwise.
3001 * signal that we adjust the clock signal phase against. For example
3002 * phase locked-loop clock signal generators we may shift phase with
3003 * respect to feedback clock signal input, but for other cases the
3004 * clock phase may be shifted with respect to some other, unspecified
3008 * the clock tree hierarchy, which sets it apart from clock rates and
3009 * clock accuracy. A parent clock phase attribute does not have an
3010 * impact on the phase attribute of a child clock.
3026 if (clk->exclusive_count) in clk_set_phase()
3027 clk_core_rate_unprotect(clk->core); in clk_set_phase()
3029 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
3031 if (clk->exclusive_count) in clk_set_phase()
3032 clk_core_rate_protect(clk->core); in clk_set_phase()
3045 if (!core->ops->get_phase) in clk_core_get_phase()
3049 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
3051 core->phase = ret; in clk_core_get_phase()
3057 * clk_get_phase - return the phase shift of a clock signal
3058 * @clk: clock signal source
3060 * Returns the phase shift of a clock node in degrees, otherwise returns
3061 * -EERROR.
3071 ret = clk_core_get_phase(clk->core); in clk_get_phase()
3081 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
3082 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
3089 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
3092 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
3095 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
3099 /* Don't trust the clock provider too much */ in clk_core_update_duty_cycle_nolock()
3100 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
3101 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
3116 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
3117 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
3118 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
3119 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
3138 return -EBUSY; in clk_core_set_duty_cycle_nolock()
3142 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3145 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3147 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3159 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3160 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3161 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3162 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3169 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
3170 * @clk: clock signal source
3174 * Apply the duty cycle ratio if the ratio is valid and the clock can
3189 return -EINVAL; in clk_set_duty_cycle()
3196 if (clk->exclusive_count) in clk_set_duty_cycle()
3197 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3199 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3201 if (clk->exclusive_count) in clk_set_duty_cycle()
3202 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3213 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3220 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
3228 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
3229 * @clk: clock signal source
3232 * Returns the duty cycle ratio of a clock node multiplied by the provided
3240 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3245 * clk_is_match - check if two clk's point to the same hardware clock
3250 * clock node. Put differently, returns true if struct clk *p and struct clk *q
3261 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
3263 if (p->core == q->core) in clk_is_match()
3292 seq_printf(s, "%*s%-*s %-7d %-8d %-8d %-11lu %-10lu ", in clk_summary_show_one()
3294 35 - level * 3, c->name, in clk_summary_show_one()
3295 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
3301 seq_printf(s, "%-5d", phase); in clk_summary_show_one()
3303 seq_puts(s, "-----"); in clk_summary_show_one()
3305 seq_printf(s, " %-6d", clk_core_get_scaled_duty_cycle(c, 100000)); in clk_summary_show_one()
3307 if (c->ops->is_enabled) in clk_summary_show_one()
3309 else if (!c->ops->enable) in clk_summary_show_one()
3314 hlist_for_each_entry(clk_user, &c->clks, clks_node) { in clk_summary_show_one()
3315 seq_printf(s, "%*s%-*s %-25s\n", in clk_summary_show_one()
3318 clk_user->dev_id ? clk_user->dev_id : "deviceless", in clk_summary_show_one()
3319 clk_user->con_id ? clk_user->con_id : "no_connection_id"); in clk_summary_show_one()
3333 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
3340 struct hlist_head **lists = s->private; in clk_summary_show()
3344 …seq_puts(s, " clock count count count rate accuracy phas… in clk_summary_show()
3345 …s(s, "--------------------------------------------------------------------------------------------… in clk_summary_show()
3372 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
3373 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
3374 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
3375 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
3379 seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy_recalc(c)); in clk_dump_one()
3393 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3405 struct hlist_head **lists = s->private; in clk_dump_show()
3475 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3477 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3486 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3518 *val = core->phase; in clk_phase_get()
3546 struct clk_core *core = s->private; in clk_flags_show()
3547 unsigned long flags = core->flags; in clk_flags_show()
3574 * 1. Fetch the registered parent clock and use its name in possible_parent_show()
3577 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3585 seq_puts(s, parent->name); in possible_parent_show()
3586 } else if (core->parents[i].name) { in possible_parent_show()
3587 seq_puts(s, core->parents[i].name); in possible_parent_show()
3588 } else if (core->parents[i].fw_name) { in possible_parent_show()
3589 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3591 if (core->parents[i].index >= 0) in possible_parent_show()
3592 name = of_clk_get_parent_name(core->of_node, core->parents[i].index); in possible_parent_show()
3604 struct clk_core *core = s->private; in possible_parents_show()
3607 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3618 struct clk_core *core = s->private; in current_parent_show()
3620 if (core->parent) in current_parent_show()
3621 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3631 struct seq_file *s = file->private_data; in current_parent_write()
3632 struct clk_core *core = s->private; in current_parent_write()
3643 return -ENOENT; in current_parent_write()
3665 struct clk_core *core = s->private; in clk_duty_cycle_show()
3666 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3668 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3676 struct clk_core *core = s->private; in clk_min_rate_show()
3690 struct clk_core *core = s->private; in clk_max_rate_show()
3709 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3710 core->dentry = root; in clk_debug_create_one()
3716 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3720 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3721 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3722 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3723 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3730 if (core->num_parents > 1) in clk_debug_create_one()
3735 if (core->num_parents > 0) in clk_debug_create_one()
3739 if (core->num_parents > 1) in clk_debug_create_one()
3743 if (core->ops->debug_init) in clk_debug_create_one()
3744 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3748 * clk_debug_register - add a clk node to the debugfs clk directory
3758 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3765 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3769 * debugfs clk directory if clk->dentry points to debugfs created by
3775 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3776 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3777 core->dentry = NULL; in clk_debug_unregister()
3782 * clk_debug_init - lazily populate the debugfs clk directory
3786 * populates the debugfs clk directory once at boot-time when we know that
3787 * debugfs is setup. It should only be called once at boot-time, all other clks
3855 * clock. This is important for CLK_IS_CRITICAL clocks, which in clk_core_reparent_orphans_nolock()
3867 * 0 if the clock doesn't have clk_ops::recalc_rate and in clk_core_reparent_orphans_nolock()
3873 * 'req_rate' is set to something non-zero so that in clk_core_reparent_orphans_nolock()
3876 orphan->req_rate = orphan->rate; in clk_core_reparent_orphans_nolock()
3882 * __clk_core_init - initialize the data structures in a struct clk_core
3898 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3899 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3903 core->hw->core = core; in __clk_core_init()
3909 /* check to see if a clock with this name is already registered */ in __clk_core_init()
3910 if (clk_core_lookup(core->name)) { in __clk_core_init()
3912 __func__, core->name); in __clk_core_init()
3913 ret = -EEXIST; in __clk_core_init()
3917 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3918 if (core->ops->set_rate && in __clk_core_init()
3919 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3920 core->ops->recalc_rate)) { in __clk_core_init()
3922 __func__, core->name); in __clk_core_init()
3923 ret = -EINVAL; in __clk_core_init()
3927 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3929 __func__, core->name); in __clk_core_init()
3930 ret = -EINVAL; in __clk_core_init()
3934 if (core->ops->set_parent && !core->ops->determine_rate) { in __clk_core_init()
3936 __func__, core->name); in __clk_core_init()
3937 ret = -EINVAL; in __clk_core_init()
3941 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3943 __func__, core->name); in __clk_core_init()
3944 ret = -EINVAL; in __clk_core_init()
3948 if (core->ops->set_rate_and_parent && in __clk_core_init()
3949 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3951 __func__, core->name); in __clk_core_init()
3952 ret = -EINVAL; in __clk_core_init()
3957 * optional platform-specific magic in __clk_core_init()
3959 * The .init callback is not used by any of the basic clock types, but in __clk_core_init()
3961 * CCF to get an accurate view of clock for any other callbacks. It may in __clk_core_init()
3968 * the clock in __clk_core_init()
3970 if (core->ops->init) { in __clk_core_init()
3971 ret = core->ops->init(core->hw); in __clk_core_init()
3976 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3979 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3985 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
3989 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3990 core->orphan = parent->orphan; in __clk_core_init()
3991 } else if (!core->num_parents) { in __clk_core_init()
3992 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3993 core->orphan = false; in __clk_core_init()
3995 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3996 core->orphan = true; in __clk_core_init()
3998 hash_add(clk_hashtable, &core->hashtable_node, in __clk_core_init()
3999 full_name_hash(NULL, core->name, strlen(core->name))); in __clk_core_init()
4002 * Set clk's accuracy. The preferred method is to use in __clk_core_init()
4004 * fallback is to use the parent's accuracy. If a clock doesn't have a in __clk_core_init()
4005 * parent (or is orphaned) then accuracy is set to zero (perfect in __clk_core_init()
4006 * clock). in __clk_core_init()
4008 if (core->ops->recalc_accuracy) in __clk_core_init()
4009 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
4012 core->accuracy = parent->accuracy; in __clk_core_init()
4014 core->accuracy = 0; in __clk_core_init()
4019 * query the current clock phase, or just assume it's in phase. in __clk_core_init()
4025 core->name); in __clk_core_init()
4037 * parent's rate. If a clock doesn't have a parent (or is orphaned) in __clk_core_init()
4040 if (core->ops->recalc_rate) in __clk_core_init()
4041 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
4044 rate = parent->rate; in __clk_core_init()
4047 core->rate = core->req_rate = rate; in __clk_core_init()
4054 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
4058 __func__, core->name); in __clk_core_init()
4065 __func__, core->name); in __clk_core_init()
4076 hash_del(&core->hashtable_node); in __clk_core_init()
4077 hlist_del_init(&core->child_node); in __clk_core_init()
4078 core->hw->core = NULL; in __clk_core_init()
4090 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
4097 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
4102 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
4108 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
4112 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
4126 return ERR_PTR(-ENOMEM); in alloc_clk()
4128 clk->core = core; in alloc_clk()
4129 clk->dev_id = dev_id; in alloc_clk()
4130 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
4131 clk->max_rate = ULONG_MAX; in alloc_clk()
4137 * free_clk - Free a clk consumer
4145 kfree_const(clk->con_id); in free_clk()
4171 core = hw->core; in clk_hw_create_clk()
4175 clk->dev = dev; in clk_hw_create_clk()
4177 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
4179 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
4182 kref_get(&core->ref); in clk_hw_create_clk()
4189 * clk_hw_get_clk - get clk consumer given an clk_hw
4195 * to get a consumer clk and act on the clock element
4200 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4213 return -EINVAL; in clk_cpy_name()
4219 return -ENOMEM; in clk_cpy_name()
4227 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
4228 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
4229 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
4230 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
4238 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
4242 core->parents = parents; in clk_core_populate_parent_map()
4244 return -ENOMEM; in clk_core_populate_parent_map()
4248 parent->index = -1; in clk_core_populate_parent_map()
4253 __func__, core->name); in clk_core_populate_parent_map()
4254 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
4257 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
4258 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
4259 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
4262 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
4266 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
4268 ret = -EINVAL; in clk_core_populate_parent_map()
4276 } while (--i >= 0); in clk_core_populate_parent_map()
4288 int i = core->num_parents; in clk_core_free_parent_map()
4290 if (!core->num_parents) in clk_core_free_parent_map()
4293 while (--i >= 0) { in clk_core_free_parent_map()
4294 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4295 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4298 kfree(core->parents); in clk_core_free_parent_map()
4306 if (core->rpm_enabled) { in __clk_release()
4308 hlist_del(&core->rpm_node); in __clk_release()
4313 kfree_const(core->name); in __clk_release()
4322 const struct clk_init_data *init = hw->init; in __clk_register()
4327 * we catch use of hw->init early on in the core. in __clk_register()
4329 hw->init = NULL; in __clk_register()
4333 ret = -ENOMEM; in __clk_register()
4337 kref_init(&core->ref); in __clk_register()
4339 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4340 if (!core->name) { in __clk_register()
4341 ret = -ENOMEM; in __clk_register()
4345 if (WARN_ON(!init->ops)) { in __clk_register()
4346 ret = -EINVAL; in __clk_register()
4349 core->ops = init->ops; in __clk_register()
4351 core->dev = dev; in __clk_register()
4353 core->of_node = np; in __clk_register()
4354 if (dev && dev->driver) in __clk_register()
4355 core->owner = dev->driver->owner; in __clk_register()
4356 core->hw = hw; in __clk_register()
4357 core->flags = init->flags; in __clk_register()
4358 core->num_parents = init->num_parents; in __clk_register()
4359 core->min_rate = 0; in __clk_register()
4360 core->max_rate = ULONG_MAX; in __clk_register()
4366 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4372 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4373 if (IS_ERR(hw->clk)) { in __clk_register()
4374 ret = PTR_ERR(hw->clk); in __clk_register()
4378 clk_core_link_consumer(core, hw->clk); in __clk_register()
4382 return hw->clk; in __clk_register()
4385 clk_core_unlink_consumer(hw->clk); in __clk_register()
4388 free_clk(hw->clk); in __clk_register()
4389 hw->clk = NULL; in __clk_register()
4395 kref_put(&core->ref, __clk_release); in __clk_register()
4399 init->name, hw); in __clk_register()
4402 np, ERR_PTR(ret), init->name, hw); in __clk_register()
4408 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
4412 * @dev->parent if dev doesn't have a device node, or NULL if neither
4413 * @dev or @dev->parent have a device node.
4424 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
4430 * clk_register - allocate a new clock, register it and return an opaque cookie
4431 * @dev: device that is registering this clock
4432 * @hw: link to hardware-specific clock data
4434 * clk_register is the *deprecated* interface for populating the clock tree with
4435 * new clock nodes. Use clk_hw_register() instead.
4439 * rest of the clock API. In the event of an error clk_register will return an
4449 * clk_hw_register - register a clk_hw and return an error code
4450 * @dev: device that is registering this clock
4451 * @hw: link to hardware-specific clock data
4453 * clk_hw_register is the primary interface for populating the clock tree with
4454 * new clock nodes. It returns an integer equal to zero indicating success or
4466 * of_clk_hw_register - register a clk_hw and return an error code
4467 * @node: device_node of device that is registering this clock
4468 * @hw: link to hardware-specific clock data
4470 * of_clk_hw_register() is the primary interface for populating the clock tree
4471 * with new clock nodes when a struct device is not available, but a struct
4484 * after clk_unregister() was called on a clock and until last clock
4489 return -ENXIO; in clk_nodrv_prepare_enable()
4500 return -ENXIO; in clk_nodrv_set_rate()
4505 return -ENXIO; in clk_nodrv_set_parent()
4511 return -ENXIO; in clk_nodrv_determine_rate()
4530 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
4531 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4532 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4534 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
4553 * clk_unregister - unregister a currently registered clock
4554 * @clk: clock to unregister
4564 clk_debug_unregister(clk->core); in clk_unregister()
4568 ops = clk->core->ops; in clk_unregister()
4570 pr_err("%s: unregistered clock: %s\n", __func__, in clk_unregister()
4571 clk->core->name); in clk_unregister()
4576 * Assign empty clock ops for consumers that might still hold in clk_unregister()
4577 * a reference to this clock. in clk_unregister()
4580 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4583 if (ops->terminate) in clk_unregister()
4584 ops->terminate(clk->core->hw); in clk_unregister()
4586 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4591 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4596 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4598 hash_del(&clk->core->hashtable_node); in clk_unregister()
4599 hlist_del_init(&clk->core->child_node); in clk_unregister()
4601 if (clk->core->prepare_count) in clk_unregister()
4602 pr_warn("%s: unregistering prepared clock: %s\n", in clk_unregister()
4603 __func__, clk->core->name); in clk_unregister()
4605 if (clk->core->protect_count) in clk_unregister()
4606 pr_warn("%s: unregistering protected clock: %s\n", in clk_unregister()
4607 __func__, clk->core->name); in clk_unregister()
4610 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4616 * clk_hw_unregister - unregister a currently registered clk_hw
4617 * @hw: hardware-specific clock data to unregister
4621 clk_unregister(hw->clk); in clk_hw_unregister()
4636 * devm_clk_register - resource managed clk_register()
4637 * @dev: device that is registering this clock
4638 * @hw: link to hardware-specific clock data
4652 return ERR_PTR(-ENOMEM); in devm_clk_register()
4667 * devm_clk_hw_register - resource managed clk_hw_register()
4668 * @dev: device that is registering this clock
4669 * @hw: link to hardware-specific clock data
4682 return -ENOMEM; in devm_clk_hw_register()
4702 * devm_clk_hw_get_clk - resource managed clk_hw_get_clk()
4703 * @dev: device that is registering this clock
4721 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4725 return ERR_PTR(-ENOMEM); in devm_clk_hw_get_clk()
4757 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4759 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4760 clk_core_rate_unprotect(clk->core); in __clk_put()
4761 clk->exclusive_count = 0; in __clk_put()
4766 /* If we had any boundaries on that clock, let's drop them. */ in __clk_put()
4767 if (clk->min_rate > 0 || clk->max_rate < ULONG_MAX) in __clk_put()
4772 owner = clk->core->owner; in __clk_put()
4773 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4781 * clk_notifier_register - add a clk rate change notifier
4788 * re-enter into the clk framework by calling any top-level clk APIs;
4792 * clock rate is passed to the callback via struct clk_notifier_data.old_rate
4795 * clk_notifier_register() must be called from non-atomic context.
4796 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4803 int ret = -ENOMEM; in clk_notifier_register()
4806 return -EINVAL; in clk_notifier_register()
4812 if (cn->clk == clk) in clk_notifier_register()
4820 cn->clk = clk; in clk_notifier_register()
4821 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4823 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4826 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4828 clk->core->notifier_count++; in clk_notifier_register()
4838 * clk_notifier_unregister - remove a clk rate change notifier
4845 * Returns -EINVAL if called with null arguments; otherwise, passes
4851 int ret = -ENOENT; in clk_notifier_unregister()
4854 return -EINVAL; in clk_notifier_unregister()
4859 if (cn->clk == clk) { in clk_notifier_unregister()
4860 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4862 clk->core->notifier_count--; in clk_notifier_unregister()
4865 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4866 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4867 list_del(&cn->node); in clk_notifier_unregister()
4889 clk_notifier_unregister(devres->clk, devres->nb); in devm_clk_notifier_release()
4902 return -ENOMEM; in devm_clk_notifier_register()
4906 devres->clk = clk; in devm_clk_notifier_register()
4907 devres->nb = nb; in devm_clk_notifier_register()
4926 * struct of_clk_provider - Clock provider registration structure
4927 * @link: Entry in global list of clock providers
4928 * @node: Pointer to device tree node of clock provider
4929 * @get: Get clock callback. Returns NULL or a struct clk for the
4930 * given clock specifier
4932 * struct clk_hw for the given clock specifier
4967 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4969 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4970 pr_err("%s: invalid clock index %u\n", __func__, idx); in of_clk_src_onecell_get()
4971 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4974 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4982 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4984 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4986 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4989 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4994 * of_clk_add_provider() - Register a clock provider for a node
4995 * @np: Device node pointer associated with clock provider
4996 * @clk_src_get: callback for decoding clock
5014 return -ENOMEM; in of_clk_add_provider()
5016 cp->node = of_node_get(np); in of_clk_add_provider()
5017 cp->data = data; in of_clk_add_provider()
5018 cp->get = clk_src_get; in of_clk_add_provider()
5021 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
5023 pr_debug("Added clock from %pOF\n", np); in of_clk_add_provider()
5031 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_provider()
5038 * of_clk_add_hw_provider() - Register a clock provider for a node
5039 * @np: Device node pointer associated with clock provider
5056 return -ENOMEM; in of_clk_add_hw_provider()
5058 cp->node = of_node_get(np); in of_clk_add_hw_provider()
5059 cp->data = data; in of_clk_add_hw_provider()
5060 cp->get_hw = get; in of_clk_add_hw_provider()
5063 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
5073 fwnode_dev_initialized(&np->fwnode, true); in of_clk_add_hw_provider()
5085 * We allow a child device to use its parent device as the clock provider node
5086 * for cases like MFD sub-devices where the child device driver wants to use
5087 * devm_*() APIs but not list the device in DT as a sub-node.
5093 np = dev->of_node; in get_clk_provider_node()
5094 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
5096 if (!of_property_present(np, "#clock-cells")) in get_clk_provider_node()
5097 if (of_property_present(parent_np, "#clock-cells")) in get_clk_provider_node()
5104 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
5105 * @dev: Device acting as the clock provider (used for DT node and lifetime)
5109 * Registers clock provider for given device's node. If the device has no DT
5110 * node or if the device node lacks of clock provider information (#clock-cells)
5112 * has the #clock-cells then it is used in registration. Provider is
5128 return -ENOMEM; in devm_of_clk_add_hw_provider()
5144 * of_clk_del_provider() - Remove a previously registered clock provider
5145 * @np: Device node pointer associated with clock provider
5156 if (cp->node == np) { in of_clk_del_provider()
5157 list_del(&cp->link); in of_clk_del_provider()
5158 fwnode_dev_initialized(&np->fwnode, false); in of_clk_del_provider()
5159 of_node_put(cp->node); in of_clk_del_provider()
5169 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
5170 * @np: device node to parse clock specifier from
5171 * @index: index of phandle to parse clock out of. If index < 0, @name is used
5172 * @name: clock name to find and parse. If name is NULL, the index is used
5173 * @out_args: Result of parsing the clock specifier
5175 * Parses a device node's "clocks" and "clock-names" properties to find the
5176 * phandle and cells for the index or name that is desired. The resulting clock
5178 * parsing error. The @index argument is ignored if @name is non-NULL.
5182 * phandle1: clock-controller@1 {
5183 * #clock-cells = <2>;
5186 * phandle2: clock-controller@2 {
5187 * #clock-cells = <1>;
5190 * clock-consumer@3 {
5192 * clock-names = "name1", "name2";
5195 * To get a device_node for `clock-controller@2' node you may call this
5198 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
5199 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
5200 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
5202 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
5203 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
5204 * the "clock-names" property of @np.
5209 int ret = -ENOENT; in of_parse_clkspec()
5211 /* Walk up the tree of devices looking for a clock property that matches */ in of_parse_clkspec()
5215 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
5217 * return -EINVAL. in of_parse_clkspec()
5220 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
5221 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
5229 * No matching clock found on this node. If the parent node in of_parse_clkspec()
5230 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
5233 np = np->parent; in of_parse_clkspec()
5234 if (np && !of_property_present(np, "clock-ranges")) in of_parse_clkspec()
5248 if (provider->get_hw) in __of_clk_get_hw_from_provider()
5249 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5251 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
5261 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
5264 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
5267 if (!of_device_is_available(clkspec->np)) in of_clk_get_hw_from_clkspec()
5268 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
5272 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
5284 * of_clk_get_from_provider() - Lookup a clock from a clock provider
5285 * @clkspec: pointer to a clock specifier data structure
5287 * This function looks up a struct clk from the registered list of clock
5288 * providers, an input is a clock specifier data structure as returned
5327 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
5332 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
5333 * @np: pointer to clock consumer node
5334 * @name: name of consumer's clock input, or NULL for the first clock reference
5336 * This function parses the clocks and clock-names properties,
5337 * and uses them to look up the struct clk from the registered list of clock
5343 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
5345 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
5350 * of_clk_get_parent_count() - Count the number of clocks a device node has
5359 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
5377 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
5386 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
5388 of_property_for_each_u32(clkspec.np, "clock-indices", pv) { in of_clk_get_parent_name()
5396 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
5397 if (of_property_present(clkspec.np, "clock-indices") && !found) { in of_clk_get_parent_name()
5402 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
5406 * Best effort to get the name if the clock has been in of_clk_get_parent_name()
5407 * registered with the framework. If the clock isn't in of_clk_get_parent_name()
5409 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
5414 clk_name = clkspec.np->name; in of_clk_get_parent_name()
5430 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
5432 * @np: Device node pointer associated with clock provider
5436 * Return: number of parents for the clock node.
5457 * This function looks for a parent clock. If there is one, then it
5458 * checks that the provider for this parent clock was initialized, in
5459 * this case the parent clock will be ready.
5476 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
5483 * previous parent are ready. If there is no clock in parent_ready()
5492 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
5493 * @np: Device node pointer associated with clock provider
5494 * @index: clock index
5495 * @flags: pointer to top-level framework flags
5497 * Detects if the clock-critical property exists and, if so, sets the
5501 * bindings, such as the one-clock-per-node style that are outdated.
5502 * Those bindings typically put all clock data into .dts and the Linux
5503 * driver has no clock data, thus making it impossible to set this flag
5515 return -EINVAL; in of_clk_detect_critical()
5517 of_property_for_each_u32(np, "clock-critical", idx) in of_clk_detect_critical()
5525 * of_clk_init() - Scan and init clock providers from the DT
5528 * This function scans the device tree for matching clock providers
5555 list_del(&clk_provider->node); in of_clk_init()
5556 of_node_put(clk_provider->np); in of_clk_init()
5563 parent->clk_init_cb = match->data; in of_clk_init()
5564 parent->np = of_node_get(np); in of_clk_init()
5565 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5572 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5575 of_node_set_flag(clk_provider->np, in of_clk_init()
5578 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5579 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5581 list_del(&clk_provider->node); in of_clk_init()
5582 of_node_put(clk_provider->np); in of_clk_init()
5592 * in case the clock parent was not mandatory in of_clk_init()