Lines Matching +full:clk +full:- +full:phase +full:-
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
4 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
6 * Standard functionality for the common clock API. See Documentation/driver-api/clk.rst
9 #include <linux/clk.h>
10 #include <linux/clk-provider.h>
11 #include <linux/clk/clk-conf.h>
25 #include "clk.h"
81 int phase; member
95 #include <trace/events/clk.h>
97 struct clk { struct
113 if (!core->rpm_enabled) in clk_pm_runtime_get()
116 ret = pm_runtime_get_sync(core->dev); in clk_pm_runtime_get()
118 pm_runtime_put_noidle(core->dev); in clk_pm_runtime_get()
126 if (!core->rpm_enabled) in clk_pm_runtime_put()
129 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
153 if (--prepare_refcnt) in clk_prepare_unlock()
193 if (--enable_refcnt) { in clk_enable_unlock()
203 return core->protect_count; in clk_core_rate_is_protected()
214 if (!core->ops->is_prepared) in clk_core_is_prepared()
215 return core->prepare_count; in clk_core_is_prepared()
218 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
233 if (!core->ops->is_enabled) in clk_core_is_enabled()
234 return core->enable_count; in clk_core_is_enabled()
246 if (core->rpm_enabled) { in clk_core_is_enabled()
247 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
248 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
254 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
256 if (core->rpm_enabled) in clk_core_is_enabled()
257 pm_runtime_put(core->dev); in clk_core_is_enabled()
264 const char *__clk_get_name(const struct clk *clk) in __clk_get_name() argument
266 return !clk ? NULL : clk->core->name; in __clk_get_name()
272 return hw->core->name; in clk_hw_get_name()
276 struct clk_hw *__clk_get_hw(struct clk *clk) in __clk_get_hw() argument
278 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
284 return hw->core->num_parents; in clk_hw_get_num_parents()
290 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
300 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
303 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
320 /* search the 'proper' clk tree first */ in clk_core_lookup()
347 return -ENOENT; in of_parse_clkspec()
352 return ERR_PTR(-ENOENT); in of_clk_get_hw_from_clkspec()
357 * clk_core_get - Find the clk_core parent of a clk
358 * @core: clk to find parent of
361 * This is the preferred method for clk providers to find the parent of a
362 * clk when that parent is external to the clk controller. The parent_names
364 * node's 'clock-names' property or as the 'con_id' matching the device's
365 * dev_name() in a clk_lookup. This allows clk providers to use their own
369 * clock-controller@c001 that has a clk_init_data::parent_data array
371 * clock-controller@f00abcd without needing to get the globally unique name of
372 * the xtal clk.
374 * parent: clock-controller@f00abcd {
376 * #clock-cells = <0>;
379 * clock-controller@c001 {
382 * clock-names = "xtal";
383 * #clock-cells = <1>;
386 * Returns: -ENOENT when the provider can't be found or the clk doesn't
388 * in a clkdev lookup. NULL when the provider knows about the clk but it
390 * A valid clk_core pointer when the clk can be found in the provider.
394 const char *name = core->parents[p_index].fw_name; in clk_core_get()
395 int index = core->parents[p_index].index; in clk_core_get()
396 struct clk_hw *hw = ERR_PTR(-ENOENT); in clk_core_get()
397 struct device *dev = core->dev; in clk_core_get()
399 struct device_node *np = core->of_node; in clk_core_get()
417 return hw->core; in clk_core_get()
422 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
423 struct clk_core *parent = ERR_PTR(-ENOENT); in clk_core_fill_parent_index()
425 if (entry->hw) { in clk_core_fill_parent_index()
426 parent = entry->hw->core; in clk_core_fill_parent_index()
433 parent = ERR_PTR(-EPROBE_DEFER); in clk_core_fill_parent_index()
436 if (PTR_ERR(parent) == -ENOENT && entry->name) in clk_core_fill_parent_index()
437 parent = clk_core_lookup(entry->name); in clk_core_fill_parent_index()
442 entry->core = parent; in clk_core_fill_parent_index()
448 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
451 if (!core->parents[index].core) in clk_core_get_parent_by_index()
454 return core->parents[index].core; in clk_core_get_parent_by_index()
462 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
464 return !parent ? NULL : parent->hw; in clk_hw_get_parent_by_index()
468 unsigned int __clk_get_enable_count(struct clk *clk) in __clk_get_enable_count() argument
470 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
478 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
479 return core->rate; in clk_core_get_rate_nolock()
482 * Clk must have a parent because num_parents > 0 but the parent isn't in clk_core_get_rate_nolock()
483 * known yet. Best to return 0 as the rate of this clk until we can in clk_core_get_rate_nolock()
491 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
500 return core->accuracy; in clk_core_get_accuracy_no_lock()
505 return hw->core->flags; in clk_hw_get_flags()
511 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
517 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
523 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
527 bool __clk_is_enabled(struct clk *clk) in __clk_is_enabled() argument
529 if (!clk) in __clk_is_enabled()
532 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
540 return abs(now - rate) < abs(best - rate); in mux_is_better_rate()
549 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags()
555 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
556 parent = core->parent; in clk_mux_determine_rate_flags()
557 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
558 ret = __clk_determine_rate(parent ? parent->hw : NULL, in clk_mux_determine_rate_flags()
574 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
580 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
582 ret = __clk_determine_rate(parent->hw, &parent_req); in clk_mux_determine_rate_flags()
589 if (mux_is_better_rate(req->rate, parent_req.rate, in clk_mux_determine_rate_flags()
597 return -EINVAL; in clk_mux_determine_rate_flags()
601 req->best_parent_hw = best_parent->hw; in clk_mux_determine_rate_flags()
602 req->best_parent_rate = best; in clk_mux_determine_rate_flags()
603 req->rate = best; in clk_mux_determine_rate_flags()
609 struct clk *__clk_lookup(const char *name) in __clk_lookup()
613 return !core ? NULL : core->hw->clk; in __clk_lookup()
620 struct clk *clk_user; in clk_core_get_boundaries()
624 *min_rate = core->min_rate; in clk_core_get_boundaries()
625 *max_rate = core->max_rate; in clk_core_get_boundaries()
627 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
628 *min_rate = max(*min_rate, clk_user->min_rate); in clk_core_get_boundaries()
630 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
631 *max_rate = min(*max_rate, clk_user->max_rate); in clk_core_get_boundaries()
637 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
638 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
643 * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a mux type clk
644 * @hw: mux type clk to determine rate on
651 * Returns: 0 on success, -EERROR value on error
667 /*** clk api ***/
676 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
677 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
680 if (--core->protect_count > 0) in clk_core_rate_unprotect()
683 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
693 return -EINVAL; in clk_core_rate_nuke_protect()
695 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
698 ret = core->protect_count; in clk_core_rate_nuke_protect()
699 core->protect_count = 1; in clk_core_rate_nuke_protect()
706 * clk_rate_exclusive_put - release exclusivity over clock rate control
707 * @clk: the clk over which the exclusivity is released
723 void clk_rate_exclusive_put(struct clk *clk) in clk_rate_exclusive_put() argument
725 if (!clk) in clk_rate_exclusive_put()
734 if (WARN_ON(clk->exclusive_count <= 0)) in clk_rate_exclusive_put()
737 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
738 clk->exclusive_count--; in clk_rate_exclusive_put()
751 if (core->protect_count == 0) in clk_core_rate_protect()
752 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
754 core->protect_count++; in clk_core_rate_protect()
768 core->protect_count = count; in clk_core_rate_restore_protect()
772 * clk_rate_exclusive_get - get exclusivity over the clk rate control
773 * @clk: the clk over which the exclusity of rate control is requested
787 * Returns 0 on success, -EERROR otherwise
789 int clk_rate_exclusive_get(struct clk *clk) in clk_rate_exclusive_get() argument
791 if (!clk) in clk_rate_exclusive_get()
795 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
796 clk->exclusive_count++; in clk_rate_exclusive_get()
810 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
811 "%s already unprepared\n", core->name)) in clk_core_unprepare()
814 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
815 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
818 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
821 if (--core->prepare_count > 0) in clk_core_unprepare()
824 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
828 if (core->ops->unprepare) in clk_core_unprepare()
829 core->ops->unprepare(core->hw); in clk_core_unprepare()
834 clk_core_unprepare(core->parent); in clk_core_unprepare()
845 * clk_unprepare - undo preparation of a clock source
846 * @clk: the clk being unprepared
849 * simple case, clk_unprepare can be used instead of clk_disable to gate a clk
850 * if the operation may sleep. One example is a clk which is accessed over
851 * I2c. In the complex case a clk gate operation may require a fast and a slow
855 void clk_unprepare(struct clk *clk) in clk_unprepare() argument
857 if (IS_ERR_OR_NULL(clk)) in clk_unprepare()
860 clk_core_unprepare_lock(clk->core); in clk_unprepare()
873 if (core->prepare_count == 0) { in clk_core_prepare()
878 ret = clk_core_prepare(core->parent); in clk_core_prepare()
884 if (core->ops->prepare) in clk_core_prepare()
885 ret = core->ops->prepare(core->hw); in clk_core_prepare()
893 core->prepare_count++; in clk_core_prepare()
902 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
907 clk_core_unprepare(core->parent); in clk_core_prepare()
925 * clk_prepare - prepare a clock source
926 * @clk: the clk being prepared
929 * case, clk_prepare can be used instead of clk_enable to ungate a clk if the
930 * operation may sleep. One example is a clk which is accessed over I2c. In
931 * the complex case a clk ungate operation may require a fast and a slow part.
934 * Returns 0 on success, -EERROR otherwise.
936 int clk_prepare(struct clk *clk) in clk_prepare() argument
938 if (!clk) in clk_prepare()
941 return clk_core_prepare_lock(clk->core); in clk_prepare()
952 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
955 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
956 "Disabling critical %s\n", core->name)) in clk_core_disable()
959 if (--core->enable_count > 0) in clk_core_disable()
964 if (core->ops->disable) in clk_core_disable()
965 core->ops->disable(core->hw); in clk_core_disable()
969 clk_core_disable(core->parent); in clk_core_disable()
982 * clk_disable - gate a clock
983 * @clk: the clk being gated
987 * clk if the operation is fast and will never sleep. One example is a
988 * SoC-internal clk which is controlled via simple register writes. In the
989 * complex case a clk gate operation may require a fast and a slow part. It is
993 void clk_disable(struct clk *clk) in clk_disable() argument
995 if (IS_ERR_OR_NULL(clk)) in clk_disable()
998 clk_core_disable_lock(clk->core); in clk_disable()
1011 if (WARN(core->prepare_count == 0, in clk_core_enable()
1012 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1013 return -ESHUTDOWN; in clk_core_enable()
1015 if (core->enable_count == 0) { in clk_core_enable()
1016 ret = clk_core_enable(core->parent); in clk_core_enable()
1023 if (core->ops->enable) in clk_core_enable()
1024 ret = core->ops->enable(core->hw); in clk_core_enable()
1029 clk_core_disable(core->parent); in clk_core_enable()
1034 core->enable_count++; in clk_core_enable()
1051 * clk_gate_restore_context - restore context for poweroff
1062 struct clk_core *core = hw->core; in clk_gate_restore_context()
1064 if (core->enable_count) in clk_gate_restore_context()
1065 core->ops->enable(hw); in clk_gate_restore_context()
1067 core->ops->disable(hw); in clk_gate_restore_context()
1076 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1082 if (core->ops && core->ops->save_context) in clk_core_save_context()
1083 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1092 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1093 core->ops->restore_context(core->hw); in clk_core_restore_context()
1095 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1100 * clk_save_context - save clock context for poweroff
1108 struct clk_core *clk; in clk_save_context() local
1111 hlist_for_each_entry(clk, &clk_root_list, child_node) { in clk_save_context()
1112 ret = clk_core_save_context(clk); in clk_save_context()
1117 hlist_for_each_entry(clk, &clk_orphan_list, child_node) { in clk_save_context()
1118 ret = clk_core_save_context(clk); in clk_save_context()
1128 * clk_restore_context - restore clock context after poweroff
1146 * clk_enable - ungate a clock
1147 * @clk: the clk being ungated
1150 * simple case, clk_enable can be used instead of clk_prepare to ungate a clk
1151 * if the operation will never sleep. One example is a SoC-internal clk which
1152 * is controlled via simple register writes. In the complex case a clk ungate
1155 * must be called before clk_enable. Returns 0 on success, -EERROR
1158 int clk_enable(struct clk *clk) in clk_enable() argument
1160 if (!clk) in clk_enable()
1163 return clk_core_enable_lock(clk->core); in clk_enable()
1194 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1197 if (core->prepare_count) in clk_unprepare_unused_subtree()
1200 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1208 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1209 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1210 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1211 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1225 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1228 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1229 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1236 if (core->enable_count) in clk_disable_unused_subtree()
1239 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1243 * some gate clocks have special needs during the disable-unused in clk_disable_unused_subtree()
1249 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1250 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1251 else if (core->ops->disable) in clk_disable_unused_subtree()
1252 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1260 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1261 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1277 pr_warn("clk: Not disabling unused clocks\n"); in clk_disable_unused()
1313 * - if the provider is not protected at all in clk_core_determine_round_nolock()
1314 * - if the calling consumer is the only one which has exclusivity in clk_core_determine_round_nolock()
1318 req->rate = core->rate; in clk_core_determine_round_nolock()
1319 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1320 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1321 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1322 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1323 &req->best_parent_rate); in clk_core_determine_round_nolock()
1327 req->rate = rate; in clk_core_determine_round_nolock()
1329 return -EINVAL; in clk_core_determine_round_nolock()
1343 parent = core->parent; in clk_core_init_rate_req()
1345 req->best_parent_hw = parent->hw; in clk_core_init_rate_req()
1346 req->best_parent_rate = parent->rate; in clk_core_init_rate_req()
1348 req->best_parent_hw = NULL; in clk_core_init_rate_req()
1349 req->best_parent_rate = 0; in clk_core_init_rate_req()
1355 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1364 req->rate = 0; in clk_core_round_rate_nolock()
1372 else if (core->flags & CLK_SET_RATE_PARENT) in clk_core_round_rate_nolock()
1373 return clk_core_round_rate_nolock(core->parent, req); in clk_core_round_rate_nolock()
1375 req->rate = core->rate; in clk_core_round_rate_nolock()
1380 * __clk_determine_rate - get the closest rate actually supported by a clock
1389 req->rate = 0; in __clk_determine_rate()
1393 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1398 * clk_hw_round_rate() - round the given rate for a hw clk
1399 * @hw: the hw clk for which we are rounding a rate
1402 * Takes in a rate as input and rounds it to a rate that the clk can actually
1406 * For clk providers to call from within clk_ops such as .round_rate,
1409 * Return: returns rounded rate of hw clk if clk supports round_rate operation
1417 clk_core_get_boundaries(hw->core, &req.min_rate, &req.max_rate); in clk_hw_round_rate()
1420 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1429 * clk_round_rate - round the given rate for a clk
1430 * @clk: the clk for which we are rounding a rate
1433 * Takes in a rate as input and rounds it to a rate that the clk can actually
1434 * use which is then returned. If clk doesn't support round_rate operation
1437 long clk_round_rate(struct clk *clk, unsigned long rate) in clk_round_rate() argument
1442 if (!clk) in clk_round_rate()
1447 if (clk->exclusive_count) in clk_round_rate()
1448 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1450 clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate); in clk_round_rate()
1453 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1455 if (clk->exclusive_count) in clk_round_rate()
1456 clk_core_rate_protect(clk->core); in clk_round_rate()
1468 * __clk_notify - call clk notifier chain
1469 * @core: clk that is changing rate
1470 * @msg: clk notifier type (see include/linux/clk.h)
1471 * @old_rate: old clk rate
1472 * @new_rate: new clk rate
1474 * Triggers a notifier call chain on the clk rate-change notification
1475 * for 'clk'. Passes a pointer to the struct clk and the previous
1492 if (cn->clk->core == core) { in __clk_notify()
1493 cnd.clk = cn->clk; in __clk_notify()
1494 ret = srcu_notifier_call_chain(&cn->notifier_head, msg, in __clk_notify()
1506 * @core: first clk in the subtree
1508 * Walks the subtree of clks starting with clk and recalculates accuracies as
1509 * it goes. Note that if a clk does not implement the .recalc_accuracy
1520 if (core->parent) in __clk_recalc_accuracies()
1521 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1523 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1524 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1527 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1529 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1535 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1542 * clk_get_accuracy - return the accuracy of clk
1543 * @clk: the clk whose accuracy is being returned
1545 * Simply returns the cached accuracy of the clk, unless
1548 * If clk is NULL then returns 0.
1550 long clk_get_accuracy(struct clk *clk) in clk_get_accuracy() argument
1554 if (!clk) in clk_get_accuracy()
1558 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1570 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1571 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1579 * @core: first clk in the subtree
1580 * @msg: notification type (see include/linux/clk.h)
1582 * Walks the subtree of clks starting with clk and recalculates rates as it
1583 * goes. Note that if a clk does not implement the .recalc_rate callback then
1597 old_rate = core->rate; in __clk_recalc_rates()
1599 if (core->parent) in __clk_recalc_rates()
1600 parent_rate = core->parent->rate; in __clk_recalc_rates()
1602 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1608 if (core->notifier_count && msg) in __clk_recalc_rates()
1609 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1611 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1617 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1624 * clk_get_rate - return the rate of clk
1625 * @clk: the clk whose rate is being returned
1627 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1629 * If clk is NULL then returns 0.
1631 unsigned long clk_get_rate(struct clk *clk) in clk_get_rate() argument
1635 if (!clk) in clk_get_rate()
1639 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1652 return -EINVAL; in clk_fetch_parent_index()
1654 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1656 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1660 if (core->parents[i].core) in clk_fetch_parent_index()
1664 if (core->parents[i].hw) { in clk_fetch_parent_index()
1665 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1677 if (core->parents[i].name && in clk_fetch_parent_index()
1678 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1682 if (i == core->num_parents) in clk_fetch_parent_index()
1683 return -EINVAL; in clk_fetch_parent_index()
1685 core->parents[i].core = parent; in clk_fetch_parent_index()
1690 * clk_hw_get_parent_index - return the index of the parent clock
1691 * @hw: clk_hw associated with the clk being consumed
1693 * Fetches and returns the index of parent clock. Returns -EINVAL if the given
1701 return -EINVAL; in clk_hw_get_parent_index()
1703 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
1714 core->orphan = is_orphan; in clk_core_update_orphan_status()
1716 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1722 bool was_orphan = core->orphan; in clk_reparent()
1724 hlist_del(&core->child_node); in clk_reparent()
1727 bool becomes_orphan = new_parent->orphan; in clk_reparent()
1730 if (new_parent->new_child == core) in clk_reparent()
1731 new_parent->new_child = NULL; in clk_reparent()
1733 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1738 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1743 core->parent = new_parent; in clk_reparent()
1750 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1773 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
1779 if (core->prepare_count) { in __clk_set_parent_before()
1784 /* update the clk tree topology */ in __clk_set_parent_before()
1800 if (core->prepare_count) { in __clk_set_parent_after()
1805 /* re-balance ref counting if CLK_OPS_PARENT_ENABLE is set */ in __clk_set_parent_after()
1806 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
1824 if (parent && core->ops->set_parent) in __clk_set_parent()
1825 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
1845 * @core: first clk in the subtree
1846 * @parent_rate: the "future" rate of clk's parent
1848 * Walks the subtree of clks starting with clk, speculating rates as it
1852 * pre-rate change notifications and returns early if no clks in the
1853 * subtree have subscribed to the notifications. Note that if a clk does not
1869 if (core->notifier_count) in __clk_speculate_rates()
1870 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
1873 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n", in __clk_speculate_rates()
1874 __func__, core->name, ret); in __clk_speculate_rates()
1878 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
1893 core->new_rate = new_rate; in clk_calc_subtree()
1894 core->new_parent = new_parent; in clk_calc_subtree()
1895 core->new_parent_index = p_index; in clk_calc_subtree()
1896 /* include clk in new parent's PRE_RATE_CHANGE notifications */ in clk_calc_subtree()
1897 core->new_child = NULL; in clk_calc_subtree()
1898 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
1899 new_parent->new_child = core; in clk_calc_subtree()
1901 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
1902 child->new_rate = clk_recalc(child, new_rate); in clk_calc_subtree()
1903 clk_calc_subtree(child, child->new_rate, NULL, 0); in clk_calc_subtree()
1928 parent = old_parent = core->parent; in clk_calc_new_rates()
1930 best_parent_rate = parent->rate; in clk_calc_new_rates()
1934 /* find the closest rate and parent clk/rate */ in clk_calc_new_rates()
1950 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
1954 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
1955 /* pass-through clock without adjustable parent */ in clk_calc_new_rates()
1956 core->new_rate = core->rate; in clk_calc_new_rates()
1959 /* pass-through clock with adjustable parent */ in clk_calc_new_rates()
1961 new_rate = parent->new_rate; in clk_calc_new_rates()
1967 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
1969 __func__, core->name); in clk_calc_new_rates()
1974 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
1977 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_calc_new_rates()
1978 __func__, parent->name, core->name); in clk_calc_new_rates()
1983 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
1984 best_parent_rate != parent->rate) in clk_calc_new_rates()
2004 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2007 if (core->notifier_count) { in clk_propagate_rate_change()
2008 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2013 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2015 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2022 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2023 if (core->new_child) { in clk_propagate_rate_change()
2024 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2046 old_rate = core->rate; in clk_change_rate()
2048 if (core->new_parent) { in clk_change_rate()
2049 parent = core->new_parent; in clk_change_rate()
2050 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2051 } else if (core->parent) { in clk_change_rate()
2052 parent = core->parent; in clk_change_rate()
2053 best_parent_rate = core->parent->rate; in clk_change_rate()
2059 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2068 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2069 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2070 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2072 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2074 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2076 core->new_parent_index); in clk_change_rate()
2077 } else if (core->ops->set_parent) { in clk_change_rate()
2078 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2081 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2082 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2085 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2088 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2090 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2091 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2093 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2095 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2097 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2106 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2109 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2110 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2112 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2113 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2119 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2121 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2126 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2127 if (core->new_child) in clk_change_rate()
2128 clk_change_rate(core->new_child); in clk_change_rate()
2178 return -EBUSY; in clk_core_set_rate_nolock()
2183 return -EINVAL; in clk_core_set_rate_nolock()
2193 fail_clk->name); in clk_core_set_rate_nolock()
2195 ret = -EBUSY; in clk_core_set_rate_nolock()
2202 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2210 * clk_set_rate - specify a new rate for clk
2211 * @clk: the clk whose rate is being changed
2212 * @rate: the new rate for clk
2214 * In the simplest case clk_set_rate will only adjust the rate of clk.
2217 * propagate up to clk's parent; whether or not this happens depends on the
2218 * outcome of clk's .round_rate implementation. If *parent_rate is unchanged
2220 * *parent_rate comes back with a new rate for clk's parent then we propagate
2221 * up to clk's parent and set its rate. Upward propagation will continue
2222 * until either a clk does not support the CLK_SET_RATE_PARENT flag or
2223 * .round_rate stops requesting changes to clk's parent_rate.
2228 * Returns 0 on success, -EERROR otherwise.
2230 int clk_set_rate(struct clk *clk, unsigned long rate) in clk_set_rate() argument
2234 if (!clk) in clk_set_rate()
2240 if (clk->exclusive_count) in clk_set_rate()
2241 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2243 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2245 if (clk->exclusive_count) in clk_set_rate()
2246 clk_core_rate_protect(clk->core); in clk_set_rate()
2255 * clk_set_rate_exclusive - specify a new rate and get exclusive control
2256 * @clk: the clk whose rate is being changed
2257 * @rate: the new rate for clk
2271 * Returns 0 on success, -EERROR otherwise.
2273 int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) in clk_set_rate_exclusive() argument
2277 if (!clk) in clk_set_rate_exclusive()
2289 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2291 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2292 clk->exclusive_count++; in clk_set_rate_exclusive()
2302 * clk_set_rate_range - set a rate range for a clock source
2303 * @clk: clock source
2309 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) in clk_set_rate_range() argument
2314 if (!clk) in clk_set_rate_range()
2318 pr_err("%s: clk %s dev %s con %s: invalid range [%lu, %lu]\n", in clk_set_rate_range()
2319 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range()
2321 return -EINVAL; in clk_set_rate_range()
2326 if (clk->exclusive_count) in clk_set_rate_range()
2327 clk_core_rate_unprotect(clk->core); in clk_set_rate_range()
2330 old_min = clk->min_rate; in clk_set_rate_range()
2331 old_max = clk->max_rate; in clk_set_rate_range()
2332 clk->min_rate = min; in clk_set_rate_range()
2333 clk->max_rate = max; in clk_set_rate_range()
2335 rate = clk_core_get_rate_nolock(clk->core); in clk_set_rate_range()
2344 * - round_rate() was not favorable and fell on the wrong in clk_set_rate_range()
2346 * - the determine_rate() callback does not really check for in clk_set_rate_range()
2355 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range()
2358 clk->min_rate = old_min; in clk_set_rate_range()
2359 clk->max_rate = old_max; in clk_set_rate_range()
2363 if (clk->exclusive_count) in clk_set_rate_range()
2364 clk_core_rate_protect(clk->core); in clk_set_rate_range()
2373 * clk_set_min_rate - set a minimum clock rate for a clock source
2374 * @clk: clock source
2379 int clk_set_min_rate(struct clk *clk, unsigned long rate) in clk_set_min_rate() argument
2381 if (!clk) in clk_set_min_rate()
2384 return clk_set_rate_range(clk, rate, clk->max_rate); in clk_set_min_rate()
2389 * clk_set_max_rate - set a maximum clock rate for a clock source
2390 * @clk: clock source
2395 int clk_set_max_rate(struct clk *clk, unsigned long rate) in clk_set_max_rate() argument
2397 if (!clk) in clk_set_max_rate()
2400 return clk_set_rate_range(clk, clk->min_rate, rate); in clk_set_max_rate()
2405 * clk_get_parent - return the parent of a clk
2406 * @clk: the clk whose parent gets returned
2408 * Simply returns clk->parent. Returns NULL if clk is NULL.
2410 struct clk *clk_get_parent(struct clk *clk) in clk_get_parent() argument
2412 struct clk *parent; in clk_get_parent()
2414 if (!clk) in clk_get_parent()
2418 /* TODO: Create a per-user clk and change callers to call clk_put */ in clk_get_parent()
2419 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2430 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2431 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2449 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2453 * clk_has_parent - check if a clock is a possible parent for another
2454 * @clk: clock source
2460 * Returns true if @parent is a possible parent for @clk, false otherwise.
2462 bool clk_has_parent(struct clk *clk, struct clk *parent) in clk_has_parent() argument
2468 if (!clk || !parent) in clk_has_parent()
2471 core = clk->core; in clk_has_parent()
2472 parent_core = parent->core; in clk_has_parent()
2475 if (core->parent == parent_core) in clk_has_parent()
2478 for (i = 0; i < core->num_parents; i++) in clk_has_parent()
2479 if (!strcmp(core->parents[i].name, parent_core->name)) in clk_has_parent()
2498 if (core->parent == parent) in clk_core_set_parent_nolock()
2501 /* verify ops for multi-parent clks */ in clk_core_set_parent_nolock()
2502 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2503 return -EPERM; in clk_core_set_parent_nolock()
2505 /* check that we are allowed to re-parent if the clock is in use */ in clk_core_set_parent_nolock()
2506 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2507 return -EBUSY; in clk_core_set_parent_nolock()
2510 return -EBUSY; in clk_core_set_parent_nolock()
2516 pr_debug("%s: clk %s can not be parent of clk %s\n", in clk_core_set_parent_nolock()
2517 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2520 p_rate = parent->rate; in clk_core_set_parent_nolock()
2534 /* do the re-parent */ in clk_core_set_parent_nolock()
2553 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2558 * clk_set_parent - switch the parent of a mux clk
2559 * @clk: the mux clk whose input we are switching
2560 * @parent: the new input to clk
2562 * Re-parent clk to use parent as its new input source. If clk is in
2563 * prepared state, the clk will get enabled for the duration of this call. If
2564 * that's not acceptable for a specific clk (Eg: the consumer can't handle
2566 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
2568 * After successfully changing clk's parent clk_set_parent will update the
2569 * clk topology, sysfs topology and propagate rate recalculation via
2572 * Returns 0 on success, -EERROR otherwise.
2574 int clk_set_parent(struct clk *clk, struct clk *parent) in clk_set_parent() argument
2578 if (!clk) in clk_set_parent()
2583 if (clk->exclusive_count) in clk_set_parent()
2584 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2586 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2587 parent ? parent->core : NULL); in clk_set_parent()
2589 if (clk->exclusive_count) in clk_set_parent()
2590 clk_core_rate_protect(clk->core); in clk_set_parent()
2600 int ret = -EINVAL; in clk_core_set_phase_nolock()
2608 return -EBUSY; in clk_core_set_phase_nolock()
2612 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2613 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2615 core->phase = degrees; in clk_core_set_phase_nolock()
2624 * clk_set_phase - adjust the phase shift of a clock signal
2625 * @clk: clock signal source
2628 * Shifts the phase of a clock signal by the specified
2629 * degrees. Returns 0 on success, -EERROR otherwise.
2632 * signal that we adjust the clock signal phase against. For example
2633 * phase locked-loop clock signal generators we may shift phase with
2635 * clock phase may be shifted with respect to some other, unspecified
2638 * Additionally the concept of phase shift does not propagate through
2640 * clock accuracy. A parent clock phase attribute does not have an
2641 * impact on the phase attribute of a child clock.
2643 int clk_set_phase(struct clk *clk, int degrees) in clk_set_phase() argument
2647 if (!clk) in clk_set_phase()
2657 if (clk->exclusive_count) in clk_set_phase()
2658 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2660 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2662 if (clk->exclusive_count) in clk_set_phase()
2663 clk_core_rate_protect(clk->core); in clk_set_phase()
2676 if (!core->ops->get_phase) in clk_core_get_phase()
2679 /* Always try to update cached phase if possible */ in clk_core_get_phase()
2680 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
2682 core->phase = ret; in clk_core_get_phase()
2688 * clk_get_phase - return the phase shift of a clock signal
2689 * @clk: clock signal source
2691 * Returns the phase shift of a clock node in degrees, otherwise returns
2692 * -EERROR.
2694 int clk_get_phase(struct clk *clk) in clk_get_phase() argument
2698 if (!clk) in clk_get_phase()
2702 ret = clk_core_get_phase(clk->core); in clk_get_phase()
2712 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2713 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2720 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2723 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2726 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2731 if (duty->den == 0 || duty->num > duty->den) { in clk_core_update_duty_cycle_nolock()
2732 ret = -EINVAL; in clk_core_update_duty_cycle_nolock()
2747 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2748 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2749 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2750 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2769 return -EBUSY; in clk_core_set_duty_cycle_nolock()
2773 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
2776 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
2778 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
2790 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
2791 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
2792 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
2793 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
2800 * clk_set_duty_cycle - adjust the duty cycle ratio of a clock signal
2801 * @clk: clock signal source
2810 int clk_set_duty_cycle(struct clk *clk, unsigned int num, unsigned int den) in clk_set_duty_cycle() argument
2815 if (!clk) in clk_set_duty_cycle()
2820 return -EINVAL; in clk_set_duty_cycle()
2827 if (clk->exclusive_count) in clk_set_duty_cycle()
2828 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
2830 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
2832 if (clk->exclusive_count) in clk_set_duty_cycle()
2833 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
2844 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
2851 ret = mult_frac(scale, duty->num, duty->den); in clk_core_get_scaled_duty_cycle()
2859 * clk_get_scaled_duty_cycle - return the duty cycle ratio of a clock signal
2860 * @clk: clock signal source
2866 int clk_get_scaled_duty_cycle(struct clk *clk, unsigned int scale) in clk_get_scaled_duty_cycle() argument
2868 if (!clk) in clk_get_scaled_duty_cycle()
2871 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
2876 * clk_is_match - check if two clk's point to the same hardware clock
2877 * @p: clk compared against q
2878 * @q: clk compared against p
2880 * Returns true if the two struct clk pointers both point to the same hardware
2881 * clock node. Put differently, returns true if struct clk *p and struct clk *q
2886 bool clk_is_match(const struct clk *p, const struct clk *q) in clk_is_match()
2888 /* trivial case: identical struct clk's or both NULL */ in clk_is_match()
2892 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
2894 if (p->core == q->core) in clk_is_match()
2919 int phase; in clk_summary_show_one() local
2921 seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu ", in clk_summary_show_one()
2923 30 - level * 3, c->name, in clk_summary_show_one()
2924 c->enable_count, c->prepare_count, c->protect_count, in clk_summary_show_one()
2928 phase = clk_core_get_phase(c); in clk_summary_show_one()
2929 if (phase >= 0) in clk_summary_show_one()
2930 seq_printf(s, "%5d", phase); in clk_summary_show_one()
2932 seq_puts(s, "-----"); in clk_summary_show_one()
2944 hlist_for_each_entry(child, &c->children, child_node) in clk_summary_show_subtree()
2951 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_summary_show()
2954 …" clock count count count rate accuracy phase cycle\n"); in clk_summary_show()
2955 …seq_puts(s, "-------------------------------------------------------------------------------------… in clk_summary_show()
2971 int phase; in clk_dump_one() local
2977 seq_printf(s, "\"%s\": { ", c->name); in clk_dump_one()
2978 seq_printf(s, "\"enable_count\": %d,", c->enable_count); in clk_dump_one()
2979 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); in clk_dump_one()
2980 seq_printf(s, "\"protect_count\": %d,", c->protect_count); in clk_dump_one()
2985 phase = clk_core_get_phase(c); in clk_dump_one()
2986 if (phase >= 0) in clk_dump_one()
2987 seq_printf(s, "\"phase\": %d,", phase); in clk_dump_one()
2998 hlist_for_each_entry(child, &c->children, child_node) { in clk_dump_subtree()
3010 struct hlist_head **lists = (struct hlist_head **)s->private; in clk_dump_show()
3058 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3060 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3069 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3085 *val = core->rate; in clk_rate_get()
3113 struct clk_core *core = s->private; in clk_flags_show()
3114 unsigned long flags = core->flags; in clk_flags_show()
3143 * 4. Fetch parent clock's clock-output-name if DT index was set in possible_parent_show()
3151 seq_puts(s, parent->name); in possible_parent_show()
3152 else if (core->parents[i].name) in possible_parent_show()
3153 seq_puts(s, core->parents[i].name); in possible_parent_show()
3154 else if (core->parents[i].fw_name) in possible_parent_show()
3155 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3156 else if (core->parents[i].index >= 0) in possible_parent_show()
3158 of_clk_get_parent_name(core->of_node, in possible_parent_show()
3159 core->parents[i].index)); in possible_parent_show()
3168 struct clk_core *core = s->private; in possible_parents_show()
3171 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3182 struct clk_core *core = s->private; in current_parent_show()
3184 if (core->parent) in current_parent_show()
3185 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3193 struct clk_core *core = s->private; in clk_duty_cycle_show()
3194 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3196 seq_printf(s, "%u/%u\n", duty->num, duty->den); in clk_duty_cycle_show()
3204 struct clk_core *core = s->private; in clk_min_rate_show()
3218 struct clk_core *core = s->private; in clk_max_rate_show()
3237 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3238 core->dentry = root; in clk_debug_create_one()
3244 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3245 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3247 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3248 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3249 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3250 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3258 if (core->num_parents > 0) in clk_debug_create_one()
3262 if (core->num_parents > 1) in clk_debug_create_one()
3266 if (core->ops->debug_init) in clk_debug_create_one()
3267 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3271 * clk_debug_register - add a clk node to the debugfs clk directory
3272 * @core: the clk being added to the debugfs clk directory
3274 * Dynamically adds a clk to the debugfs clk directory if debugfs has been
3275 * initialized. Otherwise it bails out early since the debugfs clk directory
3281 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3288 * clk_debug_unregister - remove a clk node from the debugfs clk directory
3289 * @core: the clk being removed from the debugfs clk directory
3291 * Dynamically removes a clk and all its child nodes from the
3292 * debugfs clk directory if clk->dentry points to debugfs created by
3298 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3299 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3300 core->dentry = NULL; in clk_debug_unregister()
3305 * clk_debug_init - lazily populate the debugfs clk directory
3309 * populates the debugfs clk directory once at boot-time when we know that
3310 * debugfs is setup. It should only be called once at boot-time, all other clks
3317 rootdir = debugfs_create_dir("clk", NULL); in clk_debug_init()
3364 /* update the clk tree topology */ in clk_core_reparent_orphans_nolock()
3374 * __clk_core_init - initialize the data structures in a struct clk_core
3385 int phase; in __clk_core_init() local
3388 return -EINVAL; in __clk_core_init()
3397 if (clk_core_lookup(core->name)) { in __clk_core_init()
3398 pr_debug("%s: clk %s already initialized\n", in __clk_core_init()
3399 __func__, core->name); in __clk_core_init()
3400 ret = -EEXIST; in __clk_core_init()
3404 /* check that clk_ops are sane. See Documentation/driver-api/clk.rst */ in __clk_core_init()
3405 if (core->ops->set_rate && in __clk_core_init()
3406 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3407 core->ops->recalc_rate)) { in __clk_core_init()
3409 __func__, core->name); in __clk_core_init()
3410 ret = -EINVAL; in __clk_core_init()
3414 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3416 __func__, core->name); in __clk_core_init()
3417 ret = -EINVAL; in __clk_core_init()
3421 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3423 __func__, core->name); in __clk_core_init()
3424 ret = -EINVAL; in __clk_core_init()
3428 if (core->ops->set_rate_and_parent && in __clk_core_init()
3429 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3431 __func__, core->name); in __clk_core_init()
3432 ret = -EINVAL; in __clk_core_init()
3437 * optional platform-specific magic in __clk_core_init()
3450 if (core->ops->init) { in __clk_core_init()
3451 ret = core->ops->init(core->hw); in __clk_core_init()
3456 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3459 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3460 * parent has not yet been clk_core_init'd then place clk in the orphan in __clk_core_init()
3461 * list. If clk doesn't have any parents then place it in the root in __clk_core_init()
3462 * clk list. in __clk_core_init()
3464 * Every time a new clk is clk_init'd then we walk the list of orphan in __clk_core_init()
3465 * clocks and re-parent any that are children of the clock currently in __clk_core_init()
3469 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3470 core->orphan = parent->orphan; in __clk_core_init()
3471 } else if (!core->num_parents) { in __clk_core_init()
3472 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3473 core->orphan = false; in __clk_core_init()
3475 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3476 core->orphan = true; in __clk_core_init()
3480 * Set clk's accuracy. The preferred method is to use in __clk_core_init()
3486 if (core->ops->recalc_accuracy) in __clk_core_init()
3487 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3490 core->accuracy = parent->accuracy; in __clk_core_init()
3492 core->accuracy = 0; in __clk_core_init()
3495 * Set clk's phase by clk_core_get_phase() caching the phase. in __clk_core_init()
3496 * Since a phase is by definition relative to its parent, just in __clk_core_init()
3497 * query the current clock phase, or just assume it's in phase. in __clk_core_init()
3499 phase = clk_core_get_phase(core); in __clk_core_init()
3500 if (phase < 0) { in __clk_core_init()
3501 ret = phase; in __clk_core_init()
3502 pr_warn("%s: Failed to get phase for clk '%s'\n", __func__, in __clk_core_init()
3503 core->name); in __clk_core_init()
3508 * Set clk's duty cycle. in __clk_core_init()
3513 * Set clk's rate. The preferred method is to use .recalc_rate. For in __clk_core_init()
3518 if (core->ops->recalc_rate) in __clk_core_init()
3519 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3522 rate = parent->rate; in __clk_core_init()
3525 core->rate = core->req_rate = rate; in __clk_core_init()
3532 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3537 pr_warn("%s: critical clk '%s' failed to prepare\n", in __clk_core_init()
3538 __func__, core->name); in __clk_core_init()
3546 pr_warn("%s: critical clk '%s' failed to enable\n", in __clk_core_init()
3547 __func__, core->name); in __clk_core_init()
3556 kref_init(&core->ref); in __clk_core_init()
3561 hlist_del_init(&core->child_node); in __clk_core_init()
3572 * clk_core_link_consumer - Add a clk consumer to the list of consumers in a clk_core
3573 * @core: clk to add consumer to
3574 * @clk: consumer to link to a clk
3576 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
3579 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3584 * clk_core_unlink_consumer - Remove a clk consumer from the list of consumers in a clk_core
3585 * @clk: consumer to unlink
3587 static void clk_core_unlink_consumer(struct clk *clk) in clk_core_unlink_consumer() argument
3590 hlist_del(&clk->clks_node); in clk_core_unlink_consumer()
3594 * alloc_clk - Allocate a clk consumer, but leave it unlinked to the clk_core
3595 * @core: clk to allocate a consumer for
3599 * Returns: clk consumer left unlinked from the consumer list
3601 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk()
3604 struct clk *clk; in alloc_clk() local
3606 clk = kzalloc(sizeof(*clk), GFP_KERNEL); in alloc_clk()
3607 if (!clk) in alloc_clk()
3608 return ERR_PTR(-ENOMEM); in alloc_clk()
3610 clk->core = core; in alloc_clk()
3611 clk->dev_id = dev_id; in alloc_clk()
3612 clk->con_id = kstrdup_const(con_id, GFP_KERNEL); in alloc_clk()
3613 clk->max_rate = ULONG_MAX; in alloc_clk()
3615 return clk; in alloc_clk()
3619 * free_clk - Free a clk consumer
3620 * @clk: clk consumer to free
3622 * Note, this assumes the clk has been unlinked from the clk_core consumer
3625 static void free_clk(struct clk *clk) in free_clk() argument
3627 kfree_const(clk->con_id); in free_clk()
3628 kfree(clk); in free_clk()
3632 * clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given
3634 * @dev: clk consumer device
3635 * @hw: clk_hw associated with the clk being consumed
3639 * This is the main function used to create a clk pointer for use by clk
3641 * used by the framework and clk provider respectively.
3643 struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, in clk_hw_create_clk()
3646 struct clk *clk; in clk_hw_create_clk() local
3653 core = hw->core; in clk_hw_create_clk()
3654 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
3655 if (IS_ERR(clk)) in clk_hw_create_clk()
3656 return clk; in clk_hw_create_clk()
3657 clk->dev = dev; in clk_hw_create_clk()
3659 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
3660 free_clk(clk); in clk_hw_create_clk()
3661 return ERR_PTR(-ENOENT); in clk_hw_create_clk()
3664 kref_get(&core->ref); in clk_hw_create_clk()
3665 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
3667 return clk; in clk_hw_create_clk()
3676 return -EINVAL; in clk_cpy_name()
3682 return -ENOMEM; in clk_cpy_name()
3690 u8 num_parents = init->num_parents; in clk_core_populate_parent_map()
3691 const char * const *parent_names = init->parent_names; in clk_core_populate_parent_map()
3692 const struct clk_hw **parent_hws = init->parent_hws; in clk_core_populate_parent_map()
3693 const struct clk_parent_data *parent_data = init->parent_data; in clk_core_populate_parent_map()
3701 * Avoid unnecessary string look-ups of clk_core's possible parents by in clk_core_populate_parent_map()
3705 core->parents = parents; in clk_core_populate_parent_map()
3707 return -ENOMEM; in clk_core_populate_parent_map()
3711 parent->index = -1; in clk_core_populate_parent_map()
3716 __func__, core->name); in clk_core_populate_parent_map()
3717 ret = clk_cpy_name(&parent->name, parent_names[i], in clk_core_populate_parent_map()
3720 parent->hw = parent_data[i].hw; in clk_core_populate_parent_map()
3721 parent->index = parent_data[i].index; in clk_core_populate_parent_map()
3722 ret = clk_cpy_name(&parent->fw_name, in clk_core_populate_parent_map()
3725 ret = clk_cpy_name(&parent->name, in clk_core_populate_parent_map()
3729 parent->hw = parent_hws[i]; in clk_core_populate_parent_map()
3731 ret = -EINVAL; in clk_core_populate_parent_map()
3739 } while (--i >= 0); in clk_core_populate_parent_map()
3751 int i = core->num_parents; in clk_core_free_parent_map()
3753 if (!core->num_parents) in clk_core_free_parent_map()
3756 while (--i >= 0) { in clk_core_free_parent_map()
3757 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
3758 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
3761 kfree(core->parents); in clk_core_free_parent_map()
3764 static struct clk *
3769 const struct clk_init_data *init = hw->init; in __clk_register()
3774 * we catch use of hw->init early on in the core. in __clk_register()
3776 hw->init = NULL; in __clk_register()
3780 ret = -ENOMEM; in __clk_register()
3784 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
3785 if (!core->name) { in __clk_register()
3786 ret = -ENOMEM; in __clk_register()
3790 if (WARN_ON(!init->ops)) { in __clk_register()
3791 ret = -EINVAL; in __clk_register()
3794 core->ops = init->ops; in __clk_register()
3797 core->rpm_enabled = true; in __clk_register()
3798 core->dev = dev; in __clk_register()
3799 core->of_node = np; in __clk_register()
3800 if (dev && dev->driver) in __clk_register()
3801 core->owner = dev->driver->owner; in __clk_register()
3802 core->hw = hw; in __clk_register()
3803 core->flags = init->flags; in __clk_register()
3804 core->num_parents = init->num_parents; in __clk_register()
3805 core->min_rate = 0; in __clk_register()
3806 core->max_rate = ULONG_MAX; in __clk_register()
3807 hw->core = core; in __clk_register()
3813 INIT_HLIST_HEAD(&core->clks); in __clk_register()
3819 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
3820 if (IS_ERR(hw->clk)) { in __clk_register()
3821 ret = PTR_ERR(hw->clk); in __clk_register()
3825 clk_core_link_consumer(hw->core, hw->clk); in __clk_register()
3829 return hw->clk; in __clk_register()
3832 clk_core_unlink_consumer(hw->clk); in __clk_register()
3835 free_clk(hw->clk); in __clk_register()
3836 hw->clk = NULL; in __clk_register()
3842 kfree_const(core->name); in __clk_register()
3850 * dev_or_parent_of_node() - Get device node of @dev or @dev's parent
3854 * @dev->parent if dev doesn't have a device node, or NULL if neither
3855 * @dev or @dev->parent have a device node.
3866 np = dev_of_node(dev->parent); in dev_or_parent_of_node()
3872 * clk_register - allocate a new clock, register it and return an opaque cookie
3874 * @hw: link to hardware-specific clock data
3879 * Returns: a pointer to the newly allocated struct clk which
3884 struct clk *clk_register(struct device *dev, struct clk_hw *hw) in clk_register()
3891 * clk_hw_register - register a clk_hw and return an error code
3893 * @hw: link to hardware-specific clock data
3908 * of_clk_hw_register - register a clk_hw and return an error code
3910 * @hw: link to hardware-specific clock data
3932 kfree_const(core->name); in __clk_release()
3939 * consumer calls clk_put() and the struct clk object is freed.
3943 return -ENXIO; in clk_nodrv_prepare_enable()
3954 return -ENXIO; in clk_nodrv_set_rate()
3959 return -ENXIO; in clk_nodrv_set_parent()
3977 for (i = 0; i < root->num_parents; i++) in clk_core_evict_parent_cache_subtree()
3978 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
3979 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
3981 hlist_for_each_entry(child, &root->children, child_node) in clk_core_evict_parent_cache_subtree()
3985 /* Remove this clk from all parent caches */
4000 * clk_unregister - unregister a currently registered clock
4001 * @clk: clock to unregister
4003 void clk_unregister(struct clk *clk) in clk_unregister() argument
4008 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in clk_unregister()
4011 clk_debug_unregister(clk->core); in clk_unregister()
4015 ops = clk->core->ops; in clk_unregister()
4018 clk->core->name); in clk_unregister()
4026 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4029 if (ops->terminate) in clk_unregister()
4030 ops->terminate(clk->core->hw); in clk_unregister()
4032 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4037 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4042 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4044 hlist_del_init(&clk->core->child_node); in clk_unregister()
4046 if (clk->core->prepare_count) in clk_unregister()
4048 __func__, clk->core->name); in clk_unregister()
4050 if (clk->core->protect_count) in clk_unregister()
4052 __func__, clk->core->name); in clk_unregister()
4054 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4055 free_clk(clk); in clk_unregister()
4062 * clk_hw_unregister - unregister a currently registered clk_hw
4063 * @hw: hardware-specific clock data to unregister
4067 clk_unregister(hw->clk); in clk_hw_unregister()
4073 clk_unregister(*(struct clk **)res); in devm_clk_release()
4082 * devm_clk_register - resource managed clk_register()
4084 * @hw: link to hardware-specific clock data
4091 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw) in devm_clk_register()
4093 struct clk *clk; in devm_clk_register() local
4094 struct clk **clkp; in devm_clk_register()
4098 return ERR_PTR(-ENOMEM); in devm_clk_register()
4100 clk = clk_register(dev, hw); in devm_clk_register()
4101 if (!IS_ERR(clk)) { in devm_clk_register()
4102 *clkp = clk; in devm_clk_register()
4108 return clk; in devm_clk_register()
4113 * devm_clk_hw_register - resource managed clk_hw_register()
4115 * @hw: link to hardware-specific clock data
4128 return -ENOMEM; in devm_clk_hw_register()
4144 struct clk *c = res; in devm_clk_match()
4160 * devm_clk_unregister - resource managed clk_unregister()
4162 * @clk: clock to unregister
4168 void devm_clk_unregister(struct device *dev, struct clk *clk) in devm_clk_unregister() argument
4170 WARN_ON(devres_release(dev, devm_clk_release, devm_clk_match, clk)); in devm_clk_unregister()
4175 * devm_clk_hw_unregister - resource managed clk_hw_unregister()
4176 * @dev: device that is unregistering the hardware-specific clock data
4177 * @hw: link to hardware-specific clock data
4194 void __clk_put(struct clk *clk) in __clk_put() argument
4198 if (!clk || WARN_ON_ONCE(IS_ERR(clk))) in __clk_put()
4208 if (WARN_ON(clk->exclusive_count)) { in __clk_put()
4210 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4211 clk_core_rate_unprotect(clk->core); in __clk_put()
4212 clk->exclusive_count = 0; in __clk_put()
4215 hlist_del(&clk->clks_node); in __clk_put()
4216 if (clk->min_rate > clk->core->req_rate || in __clk_put()
4217 clk->max_rate < clk->core->req_rate) in __clk_put()
4218 clk_core_set_rate_nolock(clk->core, clk->core->req_rate); in __clk_put()
4220 owner = clk->core->owner; in __clk_put()
4221 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4227 free_clk(clk); in __clk_put()
4230 /*** clk rate change notifiers ***/
4233 * clk_notifier_register - add a clk rate change notifier
4234 * @clk: struct clk * to watch
4237 * Request notification when clk's rate changes. This uses an SRCU
4240 * re-enter into the clk framework by calling any top-level clk APIs;
4247 * clk_notifier_register() must be called from non-atomic context.
4248 * Returns -EINVAL if called with null arguments, -ENOMEM upon
4252 int clk_notifier_register(struct clk *clk, struct notifier_block *nb) in clk_notifier_register() argument
4255 int ret = -ENOMEM; in clk_notifier_register()
4257 if (!clk || !nb) in clk_notifier_register()
4258 return -EINVAL; in clk_notifier_register()
4262 /* search the list of notifiers for this clk */ in clk_notifier_register()
4264 if (cn->clk == clk) in clk_notifier_register()
4267 /* if clk wasn't in the notifier list, allocate new clk_notifier */ in clk_notifier_register()
4268 if (cn->clk != clk) { in clk_notifier_register()
4273 cn->clk = clk; in clk_notifier_register()
4274 srcu_init_notifier_head(&cn->notifier_head); in clk_notifier_register()
4276 list_add(&cn->node, &clk_notifier_list); in clk_notifier_register()
4279 ret = srcu_notifier_chain_register(&cn->notifier_head, nb); in clk_notifier_register()
4281 clk->core->notifier_count++; in clk_notifier_register()
4291 * clk_notifier_unregister - remove a clk rate change notifier
4292 * @clk: struct clk *
4295 * Request no further notification for changes to 'clk' and frees memory
4298 * Returns -EINVAL if called with null arguments; otherwise, passes
4301 int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb) in clk_notifier_unregister() argument
4304 int ret = -EINVAL; in clk_notifier_unregister()
4306 if (!clk || !nb) in clk_notifier_unregister()
4307 return -EINVAL; in clk_notifier_unregister()
4312 if (cn->clk == clk) in clk_notifier_unregister()
4315 if (cn->clk == clk) { in clk_notifier_unregister()
4316 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb); in clk_notifier_unregister()
4318 clk->core->notifier_count--; in clk_notifier_unregister()
4321 if (!cn->notifier_head.head) { in clk_notifier_unregister()
4322 srcu_cleanup_notifier_head(&cn->notifier_head); in clk_notifier_unregister()
4323 list_del(&cn->node); in clk_notifier_unregister()
4328 ret = -ENOENT; in clk_notifier_unregister()
4346 * struct of_clk_provider - Clock provider registration structure
4349 * @get: Get clock callback. Returns NULL or a struct clk for the
4359 struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
4371 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec, in of_clk_src_simple_get()
4384 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) in of_clk_src_onecell_get()
4387 unsigned int idx = clkspec->args[0]; in of_clk_src_onecell_get()
4389 if (idx >= clk_data->clk_num) { in of_clk_src_onecell_get()
4391 return ERR_PTR(-EINVAL); in of_clk_src_onecell_get()
4394 return clk_data->clks[idx]; in of_clk_src_onecell_get()
4402 unsigned int idx = clkspec->args[0]; in of_clk_hw_onecell_get()
4404 if (idx >= hw_data->num) { in of_clk_hw_onecell_get()
4406 return ERR_PTR(-EINVAL); in of_clk_hw_onecell_get()
4409 return hw_data->hws[idx]; in of_clk_hw_onecell_get()
4414 * of_clk_add_provider() - Register a clock provider for a node
4422 struct clk *(*clk_src_get)(struct of_phandle_args *clkspec, in of_clk_add_provider()
4431 return -ENOMEM; in of_clk_add_provider()
4433 cp->node = of_node_get(np); in of_clk_add_provider()
4434 cp->data = data; in of_clk_add_provider()
4435 cp->get = clk_src_get; in of_clk_add_provider()
4438 list_add(&cp->link, &of_clk_providers); in of_clk_add_provider()
4453 * of_clk_add_hw_provider() - Register a clock provider for a node
4468 return -ENOMEM; in of_clk_add_hw_provider()
4470 cp->node = of_node_get(np); in of_clk_add_hw_provider()
4471 cp->data = data; in of_clk_add_hw_provider()
4472 cp->get_hw = get; in of_clk_add_hw_provider()
4475 list_add(&cp->link, &of_clk_providers); in of_clk_add_hw_provider()
4496 * for cases like MFD sub-devices where the child device driver wants to use
4497 * devm_*() APIs but not list the device in DT as a sub-node.
4503 np = dev->of_node; in get_clk_provider_node()
4504 parent_np = dev->parent ? dev->parent->of_node : NULL; in get_clk_provider_node()
4506 if (!of_find_property(np, "#clock-cells", NULL)) in get_clk_provider_node()
4507 if (of_find_property(parent_np, "#clock-cells", NULL)) in get_clk_provider_node()
4514 * devm_of_clk_add_hw_provider() - Managed clk provider node registration
4520 * node or if the device node lacks of clock provider information (#clock-cells)
4522 * has the #clock-cells then it is used in registration. Provider is
4538 return -ENOMEM; in devm_of_clk_add_hw_provider()
4554 * of_clk_del_provider() - Remove a previously registered clock provider
4563 if (cp->node == np) { in of_clk_del_provider()
4564 list_del(&cp->link); in of_clk_del_provider()
4565 of_node_put(cp->node); in of_clk_del_provider()
4585 * devm_of_clk_del_provider() - Remove clock provider registered using devm
4601 * of_parse_clkspec() - Parse a DT clock specifier for a given device node
4607 * Parses a device node's "clocks" and "clock-names" properties to find the
4610 * parsing error. The @index argument is ignored if @name is non-NULL.
4614 * phandle1: clock-controller@1 {
4615 * #clock-cells = <2>;
4618 * phandle2: clock-controller@2 {
4619 * #clock-cells = <1>;
4622 * clock-consumer@3 {
4624 * clock-names = "name1", "name2";
4627 * To get a device_node for `clock-controller@2' node you may call this
4630 * of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
4631 * of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
4632 * of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
4634 * Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
4635 * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
4636 * the "clock-names" property of @np.
4641 int ret = -ENOENT; in of_parse_clkspec()
4647 * "clock-names" property. If it cannot be found, then index in of_parse_clkspec()
4649 * return -EINVAL. in of_parse_clkspec()
4652 index = of_property_match_string(np, "clock-names", name); in of_parse_clkspec()
4653 ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", in of_parse_clkspec()
4662 * has a "clock-ranges" property, then we can try one of its in of_parse_clkspec()
4665 np = np->parent; in of_parse_clkspec()
4666 if (np && !of_get_property(np, "clock-ranges", NULL)) in of_parse_clkspec()
4678 struct clk *clk; in __of_clk_get_hw_from_provider() local
4680 if (provider->get_hw) in __of_clk_get_hw_from_provider()
4681 return provider->get_hw(clkspec, provider->data); in __of_clk_get_hw_from_provider()
4683 clk = provider->get(clkspec, provider->data); in __of_clk_get_hw_from_provider()
4684 if (IS_ERR(clk)) in __of_clk_get_hw_from_provider()
4685 return ERR_CAST(clk); in __of_clk_get_hw_from_provider()
4686 return __clk_get_hw(clk); in __of_clk_get_hw_from_provider()
4693 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); in of_clk_get_hw_from_clkspec()
4696 return ERR_PTR(-EINVAL); in of_clk_get_hw_from_clkspec()
4700 if (provider->node == clkspec->np) { in of_clk_get_hw_from_clkspec()
4712 * of_clk_get_from_provider() - Lookup a clock from a clock provider
4715 * This function looks up a struct clk from the registered list of clock
4719 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) in of_clk_get_from_provider()
4744 static struct clk *__of_clk_get(struct device_node *np, in __of_clk_get()
4753 struct clk *of_clk_get(struct device_node *np, int index) in of_clk_get()
4755 return __of_clk_get(np, index, np->full_name, NULL); in of_clk_get()
4760 * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
4764 * This function parses the clocks and clock-names properties,
4765 * and uses them to look up the struct clk from the registered list of clock
4768 struct clk *of_clk_get_by_name(struct device_node *np, const char *name) in of_clk_get_by_name()
4771 return ERR_PTR(-ENOENT); in of_clk_get_by_name()
4773 return __of_clk_get(np, 0, np->full_name, name); in of_clk_get_by_name()
4778 * of_clk_get_parent_count() - Count the number of clocks a device node has
4787 count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); in of_clk_get_parent_count()
4804 struct clk *clk; in of_clk_get_parent_name() local
4806 rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, in of_clk_get_parent_name()
4815 * specified into an array offset for the clock-output-names property. in of_clk_get_parent_name()
4817 of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) { in of_clk_get_parent_name()
4824 /* We went off the end of 'clock-indices' without finding it */ in of_clk_get_parent_name()
4828 if (of_property_read_string_index(clkspec.np, "clock-output-names", in of_clk_get_parent_name()
4835 * the clock as long as #clock-cells = 0. in of_clk_get_parent_name()
4837 clk = of_clk_get_from_provider(&clkspec); in of_clk_get_parent_name()
4838 if (IS_ERR(clk)) { in of_clk_get_parent_name()
4840 clk_name = clkspec.np->name; in of_clk_get_parent_name()
4844 clk_name = __clk_get_name(clk); in of_clk_get_parent_name()
4845 clk_put(clk); in of_clk_get_parent_name()
4856 * of_clk_parent_fill() - Fill @parents with names of @np's parents and return
4892 struct clk *clk = of_clk_get(np, i); in parent_ready() local
4895 if (!IS_ERR(clk)) { in parent_ready()
4896 clk_put(clk); in parent_ready()
4902 if (PTR_ERR(clk) == -EPROBE_DEFER) in parent_ready()
4918 * of_clk_detect_critical() - set CLK_IS_CRITICAL flag from Device Tree
4921 * @flags: pointer to top-level framework flags
4923 * Detects if the clock-critical property exists and, if so, sets the
4927 * bindings, such as the one-clock-per-node style that are outdated.
4943 return -EINVAL; in of_clk_detect_critical()
4945 of_property_for_each_u32(np, "clock-critical", prop, cur, idx) in of_clk_detect_critical()
4953 * of_clk_init() - Scan and init clock providers from the DT
4983 list_del(&clk_provider->node); in of_clk_init()
4984 of_node_put(clk_provider->np); in of_clk_init()
4991 parent->clk_init_cb = match->data; in of_clk_init()
4992 parent->np = of_node_get(np); in of_clk_init()
4993 list_add_tail(&parent->node, &clk_provider_list); in of_clk_init()
5000 if (force || parent_ready(clk_provider->np)) { in of_clk_init()
5003 of_node_set_flag(clk_provider->np, in of_clk_init()
5006 clk_provider->clk_init_cb(clk_provider->np); in of_clk_init()
5007 of_clk_set_defaults(clk_provider->np, true); in of_clk_init()
5009 list_del(&clk_provider->node); in of_clk_init()
5010 of_node_put(clk_provider->np); in of_clk_init()