Lines Matching refs:core

50 	struct clk_core		*core;  member
98 struct clk_core *core; member
109 static int clk_pm_runtime_get(struct clk_core *core) in clk_pm_runtime_get() argument
111 if (!core->rpm_enabled) in clk_pm_runtime_get()
114 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
117 static void clk_pm_runtime_put(struct clk_core *core) in clk_pm_runtime_put() argument
119 if (!core->rpm_enabled) in clk_pm_runtime_put()
122 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
194 static bool clk_core_rate_is_protected(struct clk_core *core) in clk_core_rate_is_protected() argument
196 return core->protect_count; in clk_core_rate_is_protected()
199 static bool clk_core_is_prepared(struct clk_core *core) in clk_core_is_prepared() argument
207 if (!core->ops->is_prepared) in clk_core_is_prepared()
208 return core->prepare_count; in clk_core_is_prepared()
210 if (!clk_pm_runtime_get(core)) { in clk_core_is_prepared()
211 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
212 clk_pm_runtime_put(core); in clk_core_is_prepared()
218 static bool clk_core_is_enabled(struct clk_core *core) in clk_core_is_enabled() argument
226 if (!core->ops->is_enabled) in clk_core_is_enabled()
227 return core->enable_count; in clk_core_is_enabled()
239 if (core->rpm_enabled) { in clk_core_is_enabled()
240 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
241 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
252 if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) in clk_core_is_enabled()
253 if (!clk_core_is_enabled(core->parent)) { in clk_core_is_enabled()
258 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
260 if (core->rpm_enabled) in clk_core_is_enabled()
261 pm_runtime_put(core->dev); in clk_core_is_enabled()
270 return !clk ? NULL : clk->core->name; in __clk_get_name()
276 return hw->core->name; in clk_hw_get_name()
282 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
288 return hw->core->num_parents; in clk_hw_get_num_parents()
294 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
299 struct clk_core *core) in __clk_lookup_subtree() argument
304 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
305 return core; in __clk_lookup_subtree()
307 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
396 static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index) in clk_core_get() argument
398 const char *name = core->parents[p_index].fw_name; in clk_core_get()
399 int index = core->parents[p_index].index; in clk_core_get()
401 struct device *dev = core->dev; in clk_core_get()
403 struct device_node *np = core->of_node; in clk_core_get()
421 return hw->core; in clk_core_get()
424 static void clk_core_fill_parent_index(struct clk_core *core, u8 index) in clk_core_fill_parent_index() argument
426 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
430 parent = entry->hw->core; in clk_core_fill_parent_index()
432 parent = clk_core_get(core, index); in clk_core_fill_parent_index()
447 entry->core = parent; in clk_core_fill_parent_index()
450 static struct clk_core *clk_core_get_parent_by_index(struct clk_core *core, in clk_core_get_parent_by_index() argument
453 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
456 if (!core->parents[index].core) in clk_core_get_parent_by_index()
457 clk_core_fill_parent_index(core, index); in clk_core_get_parent_by_index()
459 return core->parents[index].core; in clk_core_get_parent_by_index()
467 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
475 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
478 static unsigned long clk_core_get_rate_nolock(struct clk_core *core) in clk_core_get_rate_nolock() argument
480 if (!core) in clk_core_get_rate_nolock()
483 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
484 return core->rate; in clk_core_get_rate_nolock()
496 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
500 static unsigned long clk_core_get_accuracy_no_lock(struct clk_core *core) in clk_core_get_accuracy_no_lock() argument
502 if (!core) in clk_core_get_accuracy_no_lock()
505 return core->accuracy; in clk_core_get_accuracy_no_lock()
510 return hw->core->flags; in clk_hw_get_flags()
516 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
522 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
528 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
537 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
550 static void clk_core_init_rate_req(struct clk_core * const core,
554 static int clk_core_round_rate_nolock(struct clk_core *core,
557 static bool clk_core_has_parent(struct clk_core *core, const struct clk_core *parent) in clk_core_has_parent() argument
563 if (core->parent == parent) in clk_core_has_parent()
566 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
567 tmp = clk_core_get_parent_by_index(core, i); in clk_core_has_parent()
579 clk_core_forward_rate_req(struct clk_core *core, in clk_core_forward_rate_req() argument
585 if (WARN_ON(!clk_core_has_parent(core, parent))) in clk_core_forward_rate_req()
601 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
606 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
607 parent = core->parent; in clk_mux_determine_rate_flags()
608 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
616 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
630 best = clk_core_get_rate_nolock(core); in clk_mux_determine_rate_flags()
637 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
641 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
645 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
648 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
685 struct clk_core *core = clk_core_lookup(name); in __clk_lookup() local
687 return !core ? NULL : core->hw->clk; in __clk_lookup()
690 static void clk_core_get_boundaries(struct clk_core *core, in clk_core_get_boundaries() argument
698 *min_rate = core->min_rate; in clk_core_get_boundaries()
699 *max_rate = core->max_rate; in clk_core_get_boundaries()
701 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
704 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
720 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
724 static bool clk_core_check_boundaries(struct clk_core *core, in clk_core_check_boundaries() argument
732 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
735 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
745 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
746 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
777 static void clk_core_rate_unprotect(struct clk_core *core) in clk_core_rate_unprotect() argument
781 if (!core) in clk_core_rate_unprotect()
784 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
785 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
788 if (--core->protect_count > 0) in clk_core_rate_unprotect()
791 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
794 static int clk_core_rate_nuke_protect(struct clk_core *core) in clk_core_rate_nuke_protect() argument
800 if (!core) in clk_core_rate_nuke_protect()
803 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
806 ret = core->protect_count; in clk_core_rate_nuke_protect()
807 core->protect_count = 1; in clk_core_rate_nuke_protect()
808 clk_core_rate_unprotect(core); in clk_core_rate_nuke_protect()
845 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
852 static void clk_core_rate_protect(struct clk_core *core) in clk_core_rate_protect() argument
856 if (!core) in clk_core_rate_protect()
859 if (core->protect_count == 0) in clk_core_rate_protect()
860 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
862 core->protect_count++; in clk_core_rate_protect()
865 static void clk_core_rate_restore_protect(struct clk_core *core, int count) in clk_core_rate_restore_protect() argument
869 if (!core) in clk_core_rate_restore_protect()
875 clk_core_rate_protect(core); in clk_core_rate_restore_protect()
876 core->protect_count = count; in clk_core_rate_restore_protect()
903 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
911 static void clk_core_unprepare(struct clk_core *core) in clk_core_unprepare() argument
915 if (!core) in clk_core_unprepare()
918 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
919 "%s already unprepared\n", core->name)) in clk_core_unprepare()
922 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
923 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
926 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
927 clk_core_rate_unprotect(core); in clk_core_unprepare()
929 if (--core->prepare_count > 0) in clk_core_unprepare()
932 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
934 trace_clk_unprepare(core); in clk_core_unprepare()
936 if (core->ops->unprepare) in clk_core_unprepare()
937 core->ops->unprepare(core->hw); in clk_core_unprepare()
939 trace_clk_unprepare_complete(core); in clk_core_unprepare()
940 clk_core_unprepare(core->parent); in clk_core_unprepare()
941 clk_pm_runtime_put(core); in clk_core_unprepare()
944 static void clk_core_unprepare_lock(struct clk_core *core) in clk_core_unprepare_lock() argument
947 clk_core_unprepare(core); in clk_core_unprepare_lock()
967 clk_core_unprepare_lock(clk->core); in clk_unprepare()
971 static int clk_core_prepare(struct clk_core *core) in clk_core_prepare() argument
977 if (!core) in clk_core_prepare()
980 if (core->prepare_count == 0) { in clk_core_prepare()
981 ret = clk_pm_runtime_get(core); in clk_core_prepare()
985 ret = clk_core_prepare(core->parent); in clk_core_prepare()
989 trace_clk_prepare(core); in clk_core_prepare()
991 if (core->ops->prepare) in clk_core_prepare()
992 ret = core->ops->prepare(core->hw); in clk_core_prepare()
994 trace_clk_prepare_complete(core); in clk_core_prepare()
1000 core->prepare_count++; in clk_core_prepare()
1009 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1010 clk_core_rate_protect(core); in clk_core_prepare()
1014 clk_core_unprepare(core->parent); in clk_core_prepare()
1016 clk_pm_runtime_put(core); in clk_core_prepare()
1020 static int clk_core_prepare_lock(struct clk_core *core) in clk_core_prepare_lock() argument
1025 ret = clk_core_prepare(core); in clk_core_prepare_lock()
1048 return clk_core_prepare_lock(clk->core); in clk_prepare()
1052 static void clk_core_disable(struct clk_core *core) in clk_core_disable() argument
1056 if (!core) in clk_core_disable()
1059 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1062 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1063 "Disabling critical %s\n", core->name)) in clk_core_disable()
1066 if (--core->enable_count > 0) in clk_core_disable()
1069 trace_clk_disable(core); in clk_core_disable()
1071 if (core->ops->disable) in clk_core_disable()
1072 core->ops->disable(core->hw); in clk_core_disable()
1074 trace_clk_disable_complete(core); in clk_core_disable()
1076 clk_core_disable(core->parent); in clk_core_disable()
1079 static void clk_core_disable_lock(struct clk_core *core) in clk_core_disable_lock() argument
1084 clk_core_disable(core); in clk_core_disable_lock()
1105 clk_core_disable_lock(clk->core); in clk_disable()
1109 static int clk_core_enable(struct clk_core *core) in clk_core_enable() argument
1115 if (!core) in clk_core_enable()
1118 if (WARN(core->prepare_count == 0, in clk_core_enable()
1119 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1122 if (core->enable_count == 0) { in clk_core_enable()
1123 ret = clk_core_enable(core->parent); in clk_core_enable()
1128 trace_clk_enable(core); in clk_core_enable()
1130 if (core->ops->enable) in clk_core_enable()
1131 ret = core->ops->enable(core->hw); in clk_core_enable()
1133 trace_clk_enable_complete(core); in clk_core_enable()
1136 clk_core_disable(core->parent); in clk_core_enable()
1141 core->enable_count++; in clk_core_enable()
1145 static int clk_core_enable_lock(struct clk_core *core) in clk_core_enable_lock() argument
1151 ret = clk_core_enable(core); in clk_core_enable_lock()
1169 struct clk_core *core = hw->core; in clk_gate_restore_context() local
1171 if (core->enable_count) in clk_gate_restore_context()
1172 core->ops->enable(hw); in clk_gate_restore_context()
1174 core->ops->disable(hw); in clk_gate_restore_context()
1178 static int clk_core_save_context(struct clk_core *core) in clk_core_save_context() argument
1183 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1189 if (core->ops && core->ops->save_context) in clk_core_save_context()
1190 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1195 static void clk_core_restore_context(struct clk_core *core) in clk_core_restore_context() argument
1199 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1200 core->ops->restore_context(core->hw); in clk_core_restore_context()
1202 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1242 struct clk_core *core; in clk_restore_context() local
1244 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_restore_context()
1245 clk_core_restore_context(core); in clk_restore_context()
1247 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_restore_context()
1248 clk_core_restore_context(core); in clk_restore_context()
1270 return clk_core_enable_lock(clk->core); in clk_enable()
1291 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1295 static int clk_core_prepare_enable(struct clk_core *core) in clk_core_prepare_enable() argument
1299 ret = clk_core_prepare_lock(core); in clk_core_prepare_enable()
1303 ret = clk_core_enable_lock(core); in clk_core_prepare_enable()
1305 clk_core_unprepare_lock(core); in clk_core_prepare_enable()
1310 static void clk_core_disable_unprepare(struct clk_core *core) in clk_core_disable_unprepare() argument
1312 clk_core_disable_lock(core); in clk_core_disable_unprepare()
1313 clk_core_unprepare_lock(core); in clk_core_disable_unprepare()
1316 static void __init clk_unprepare_unused_subtree(struct clk_core *core) in clk_unprepare_unused_subtree() argument
1322 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1325 if (core->prepare_count) in clk_unprepare_unused_subtree()
1328 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1331 if (clk_pm_runtime_get(core)) in clk_unprepare_unused_subtree()
1334 if (clk_core_is_prepared(core)) { in clk_unprepare_unused_subtree()
1335 trace_clk_unprepare(core); in clk_unprepare_unused_subtree()
1336 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1337 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1338 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1339 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1340 trace_clk_unprepare_complete(core); in clk_unprepare_unused_subtree()
1343 clk_pm_runtime_put(core); in clk_unprepare_unused_subtree()
1346 static void __init clk_disable_unused_subtree(struct clk_core *core) in clk_disable_unused_subtree() argument
1353 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1356 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1357 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1359 if (clk_pm_runtime_get(core)) in clk_disable_unused_subtree()
1364 if (core->enable_count) in clk_disable_unused_subtree()
1367 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1375 if (clk_core_is_enabled(core)) { in clk_disable_unused_subtree()
1376 trace_clk_disable(core); in clk_disable_unused_subtree()
1377 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1378 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1379 else if (core->ops->disable) in clk_disable_unused_subtree()
1380 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1381 trace_clk_disable_complete(core); in clk_disable_unused_subtree()
1386 clk_pm_runtime_put(core); in clk_disable_unused_subtree()
1388 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1389 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1402 struct clk_core *core; in clk_disable_unused() local
1411 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1412 clk_disable_unused_subtree(core); in clk_disable_unused()
1414 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1415 clk_disable_unused_subtree(core); in clk_disable_unused()
1417 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1418 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1420 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1421 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1429 static int clk_core_determine_round_nolock(struct clk_core *core, in clk_core_determine_round_nolock() argument
1436 if (!core) in clk_core_determine_round_nolock()
1449 __func__, core->name); in clk_core_determine_round_nolock()
1459 if (clk_core_rate_is_protected(core)) { in clk_core_determine_round_nolock()
1460 req->rate = core->rate; in clk_core_determine_round_nolock()
1461 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1462 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1463 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1464 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1477 static void clk_core_init_rate_req(struct clk_core * const core, in clk_core_init_rate_req() argument
1489 if (!core) in clk_core_init_rate_req()
1492 req->core = core; in clk_core_init_rate_req()
1494 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1496 parent = core->parent; in clk_core_init_rate_req()
1522 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1546 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1547 parent->core, req, in clk_hw_forward_rate_request()
1551 static bool clk_core_can_round(struct clk_core * const core) in clk_core_can_round() argument
1553 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1556 static int clk_core_round_rate_nolock(struct clk_core *core, in clk_core_round_rate_nolock() argument
1563 if (!core) { in clk_core_round_rate_nolock()
1568 if (clk_core_can_round(core)) in clk_core_round_rate_nolock()
1569 return clk_core_determine_round_nolock(core, req); in clk_core_round_rate_nolock()
1571 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1574 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1578 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1590 req->rate = core->rate; in clk_core_round_rate_nolock()
1608 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1632 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1636 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1666 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1668 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1672 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1677 clk_core_rate_protect(clk->core); in clk_round_rate()
1702 static int __clk_notify(struct clk_core *core, unsigned long msg, in __clk_notify() argument
1713 if (cn->clk->core == core) { in __clk_notify()
1734 static void __clk_recalc_accuracies(struct clk_core *core) in __clk_recalc_accuracies() argument
1741 if (core->parent) in __clk_recalc_accuracies()
1742 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1744 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1745 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1748 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1750 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1754 static long clk_core_get_accuracy_recalc(struct clk_core *core) in clk_core_get_accuracy_recalc() argument
1756 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1757 __clk_recalc_accuracies(core); in clk_core_get_accuracy_recalc()
1759 return clk_core_get_accuracy_no_lock(core); in clk_core_get_accuracy_recalc()
1779 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1786 static unsigned long clk_recalc(struct clk_core *core, in clk_recalc() argument
1791 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1792 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1793 clk_pm_runtime_put(core); in clk_recalc()
1811 static void __clk_recalc_rates(struct clk_core *core, bool update_req, in __clk_recalc_rates() argument
1820 old_rate = core->rate; in __clk_recalc_rates()
1822 if (core->parent) in __clk_recalc_rates()
1823 parent_rate = core->parent->rate; in __clk_recalc_rates()
1825 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1827 core->req_rate = core->rate; in __clk_recalc_rates()
1833 if (core->notifier_count && msg) in __clk_recalc_rates()
1834 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1836 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1840 static unsigned long clk_core_get_rate_recalc(struct clk_core *core) in clk_core_get_rate_recalc() argument
1842 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1843 __clk_recalc_rates(core, false, 0); in clk_core_get_rate_recalc()
1845 return clk_core_get_rate_nolock(core); in clk_core_get_rate_recalc()
1865 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1872 static int clk_fetch_parent_index(struct clk_core *core, in clk_fetch_parent_index() argument
1880 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1882 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1886 if (core->parents[i].core) in clk_fetch_parent_index()
1890 if (core->parents[i].hw) { in clk_fetch_parent_index()
1891 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1899 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
1903 if (core->parents[i].name && in clk_fetch_parent_index()
1904 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1908 if (i == core->num_parents) in clk_fetch_parent_index()
1911 core->parents[i].core = parent; in clk_fetch_parent_index()
1929 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
1936 static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan) in clk_core_update_orphan_status() argument
1940 core->orphan = is_orphan; in clk_core_update_orphan_status()
1942 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1946 static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) in clk_reparent() argument
1948 bool was_orphan = core->orphan; in clk_reparent()
1950 hlist_del(&core->child_node); in clk_reparent()
1956 if (new_parent->new_child == core) in clk_reparent()
1959 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1962 clk_core_update_orphan_status(core, becomes_orphan); in clk_reparent()
1964 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1966 clk_core_update_orphan_status(core, true); in clk_reparent()
1969 core->parent = new_parent; in clk_reparent()
1972 static struct clk_core *__clk_set_parent_before(struct clk_core *core, in __clk_set_parent_before() argument
1976 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1999 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2005 if (core->prepare_count) { in __clk_set_parent_before()
2007 clk_core_enable_lock(core); in __clk_set_parent_before()
2012 clk_reparent(core, parent); in __clk_set_parent_before()
2018 static void __clk_set_parent_after(struct clk_core *core, in __clk_set_parent_after() argument
2026 if (core->prepare_count) { in __clk_set_parent_after()
2027 clk_core_disable_lock(core); in __clk_set_parent_after()
2032 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2038 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
2045 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
2047 trace_clk_set_parent(core, parent); in __clk_set_parent()
2050 if (parent && core->ops->set_parent) in __clk_set_parent()
2051 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2053 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
2057 clk_reparent(core, old_parent); in __clk_set_parent()
2060 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
2065 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
2084 static int __clk_speculate_rates(struct clk_core *core, in __clk_speculate_rates() argument
2093 new_rate = clk_recalc(core, parent_rate); in __clk_speculate_rates()
2096 if (core->notifier_count) in __clk_speculate_rates()
2097 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2101 __func__, core->name, ret); in __clk_speculate_rates()
2105 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2115 static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, in clk_calc_subtree() argument
2120 core->new_rate = new_rate; in clk_calc_subtree()
2121 core->new_parent = new_parent; in clk_calc_subtree()
2122 core->new_parent_index = p_index; in clk_calc_subtree()
2124 core->new_child = NULL; in clk_calc_subtree()
2125 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2126 new_parent->new_child = core; in clk_calc_subtree()
2128 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2138 static struct clk_core *clk_calc_new_rates(struct clk_core *core, in clk_calc_new_rates() argument
2141 struct clk_core *top = core; in clk_calc_new_rates()
2151 if (IS_ERR_OR_NULL(core)) in clk_calc_new_rates()
2155 parent = old_parent = core->parent; in clk_calc_new_rates()
2159 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_calc_new_rates()
2162 if (clk_core_can_round(core)) { in clk_calc_new_rates()
2165 clk_core_init_rate_req(core, &req, rate); in clk_calc_new_rates()
2169 ret = clk_core_determine_round_nolock(core, &req); in clk_calc_new_rates()
2177 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2181 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2183 core->new_rate = core->rate; in clk_calc_new_rates()
2194 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2196 __func__, core->name); in clk_calc_new_rates()
2201 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2202 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
2205 __func__, parent->name, core->name); in clk_calc_new_rates()
2210 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2215 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
2225 static struct clk_core *clk_propagate_rate_change(struct clk_core *core, in clk_propagate_rate_change() argument
2231 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2234 if (core->notifier_count) { in clk_propagate_rate_change()
2235 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2237 fail_clk = core; in clk_propagate_rate_change()
2240 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2242 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2250 if (core->new_child) { in clk_propagate_rate_change()
2251 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2263 static void clk_change_rate(struct clk_core *core) in clk_change_rate() argument
2273 old_rate = core->rate; in clk_change_rate()
2275 if (core->new_parent) { in clk_change_rate()
2276 parent = core->new_parent; in clk_change_rate()
2277 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2278 } else if (core->parent) { in clk_change_rate()
2279 parent = core->parent; in clk_change_rate()
2280 best_parent_rate = core->parent->rate; in clk_change_rate()
2283 if (clk_pm_runtime_get(core)) in clk_change_rate()
2286 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2287 clk_core_prepare(core); in clk_change_rate()
2288 clk_core_enable_lock(core); in clk_change_rate()
2291 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2292 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2293 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2295 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2297 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2299 core->new_parent_index); in clk_change_rate()
2300 } else if (core->ops->set_parent) { in clk_change_rate()
2301 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2304 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2305 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2308 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2311 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2313 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2314 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2316 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2318 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2320 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2321 clk_core_disable_lock(core); in clk_change_rate()
2322 clk_core_unprepare(core); in clk_change_rate()
2325 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2328 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2329 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2331 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2332 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2338 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2340 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2346 if (core->new_child) in clk_change_rate()
2347 clk_change_rate(core->new_child); in clk_change_rate()
2349 clk_pm_runtime_put(core); in clk_change_rate()
2352 static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, in clk_core_req_round_rate_nolock() argument
2360 if (!core) in clk_core_req_round_rate_nolock()
2364 cnt = clk_core_rate_nuke_protect(core); in clk_core_req_round_rate_nolock()
2368 clk_core_init_rate_req(core, &req, req_rate); in clk_core_req_round_rate_nolock()
2372 ret = clk_core_round_rate_nolock(core, &req); in clk_core_req_round_rate_nolock()
2377 clk_core_rate_restore_protect(core, cnt); in clk_core_req_round_rate_nolock()
2382 static int clk_core_set_rate_nolock(struct clk_core *core, in clk_core_set_rate_nolock() argument
2389 if (!core) in clk_core_set_rate_nolock()
2392 rate = clk_core_req_round_rate_nolock(core, req_rate); in clk_core_set_rate_nolock()
2395 if (rate == clk_core_get_rate_nolock(core)) in clk_core_set_rate_nolock()
2399 if (clk_core_rate_is_protected(core)) in clk_core_set_rate_nolock()
2403 top = clk_calc_new_rates(core, req_rate); in clk_core_set_rate_nolock()
2407 ret = clk_pm_runtime_get(core); in clk_core_set_rate_nolock()
2424 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2426 clk_pm_runtime_put(core); in clk_core_set_rate_nolock()
2463 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2465 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2468 clk_core_rate_protect(clk->core); in clk_set_rate()
2511 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2513 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2535 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2539 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2545 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2553 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2558 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2559 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2560 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2580 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2589 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2631 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2649 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2670 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2677 static struct clk_core *__clk_init_parent(struct clk_core *core) in __clk_init_parent() argument
2681 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2682 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2684 return clk_core_get_parent_by_index(core, index); in __clk_init_parent()
2687 static void clk_core_reparent(struct clk_core *core, in clk_core_reparent() argument
2690 clk_reparent(core, new_parent); in clk_core_reparent()
2691 __clk_recalc_accuracies(core); in clk_core_reparent()
2692 __clk_recalc_rates(core, true, POST_RATE_CHANGE); in clk_core_reparent()
2700 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2719 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2723 static int clk_core_set_parent_nolock(struct clk_core *core, in clk_core_set_parent_nolock() argument
2732 if (!core) in clk_core_set_parent_nolock()
2735 if (core->parent == parent) in clk_core_set_parent_nolock()
2739 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2743 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2746 if (clk_core_rate_is_protected(core)) in clk_core_set_parent_nolock()
2751 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2754 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2760 ret = clk_pm_runtime_get(core); in clk_core_set_parent_nolock()
2765 ret = __clk_speculate_rates(core, p_rate); in clk_core_set_parent_nolock()
2772 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2776 __clk_recalc_rates(core, true, ABORT_RATE_CHANGE); in clk_core_set_parent_nolock()
2778 __clk_recalc_rates(core, true, POST_RATE_CHANGE); in clk_core_set_parent_nolock()
2779 __clk_recalc_accuracies(core); in clk_core_set_parent_nolock()
2783 clk_pm_runtime_put(core); in clk_core_set_parent_nolock()
2790 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2821 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2823 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2824 parent ? parent->core : NULL); in clk_set_parent()
2827 clk_core_rate_protect(clk->core); in clk_set_parent()
2835 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) in clk_core_set_phase_nolock() argument
2841 if (!core) in clk_core_set_phase_nolock()
2844 if (clk_core_rate_is_protected(core)) in clk_core_set_phase_nolock()
2847 trace_clk_set_phase(core, degrees); in clk_core_set_phase_nolock()
2849 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2850 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2852 core->phase = degrees; in clk_core_set_phase_nolock()
2855 trace_clk_set_phase_complete(core, degrees); in clk_core_set_phase_nolock()
2895 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2897 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2900 clk_core_rate_protect(clk->core); in clk_set_phase()
2908 static int clk_core_get_phase(struct clk_core *core) in clk_core_get_phase() argument
2913 if (!core->ops->get_phase) in clk_core_get_phase()
2917 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
2919 core->phase = ret; in clk_core_get_phase()
2939 ret = clk_core_get_phase(clk->core); in clk_get_phase()
2946 static void clk_core_reset_duty_cycle_nolock(struct clk_core *core) in clk_core_reset_duty_cycle_nolock() argument
2949 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2950 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2953 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core);
2955 static int clk_core_update_duty_cycle_nolock(struct clk_core *core) in clk_core_update_duty_cycle_nolock() argument
2957 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2960 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2961 return clk_core_update_duty_cycle_parent_nolock(core); in clk_core_update_duty_cycle_nolock()
2963 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2976 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_nolock()
2980 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core) in clk_core_update_duty_cycle_parent_nolock() argument
2984 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2985 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2986 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2987 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2989 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_parent_nolock()
2995 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core,
2998 static int clk_core_set_duty_cycle_nolock(struct clk_core *core, in clk_core_set_duty_cycle_nolock() argument
3005 if (clk_core_rate_is_protected(core)) in clk_core_set_duty_cycle_nolock()
3008 trace_clk_set_duty_cycle(core, duty); in clk_core_set_duty_cycle_nolock()
3010 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3011 return clk_core_set_duty_cycle_parent_nolock(core, duty); in clk_core_set_duty_cycle_nolock()
3013 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3015 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3017 trace_clk_set_duty_cycle_complete(core, duty); in clk_core_set_duty_cycle_nolock()
3022 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core, in clk_core_set_duty_cycle_parent_nolock() argument
3027 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3028 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3029 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3030 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3065 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3067 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3070 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3078 static int clk_core_get_scaled_duty_cycle(struct clk_core *core, in clk_core_get_scaled_duty_cycle() argument
3081 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3086 ret = clk_core_update_duty_cycle_nolock(core); in clk_core_get_scaled_duty_cycle()
3108 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3131 if (p->core == q->core) in clk_is_match()
3286 struct clk_core *core = data; in clk_rate_set() local
3290 ret = clk_core_set_rate_nolock(core, val); in clk_rate_set()
3300 struct clk_core *core = data; in clk_prepare_enable_set() local
3304 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3306 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3313 struct clk_core *core = data; in clk_prepare_enable_get() local
3315 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3329 struct clk_core *core = data; in clk_rate_get() local
3332 *val = clk_core_get_rate_recalc(core); in clk_rate_get()
3362 struct clk_core *core = s->private; in clk_flags_show() local
3363 unsigned long flags = core->flags; in clk_flags_show()
3381 static void possible_parent_show(struct seq_file *s, struct clk_core *core, in possible_parent_show() argument
3398 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3401 else if (core->parents[i].name) in possible_parent_show()
3402 seq_puts(s, core->parents[i].name); in possible_parent_show()
3403 else if (core->parents[i].fw_name) in possible_parent_show()
3404 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3405 else if (core->parents[i].index >= 0) in possible_parent_show()
3407 of_clk_get_parent_name(core->of_node, in possible_parent_show()
3408 core->parents[i].index)); in possible_parent_show()
3417 struct clk_core *core = s->private; in possible_parents_show() local
3420 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3421 possible_parent_show(s, core, i, ' '); in possible_parents_show()
3423 possible_parent_show(s, core, i, '\n'); in possible_parents_show()
3431 struct clk_core *core = s->private; in current_parent_show() local
3433 if (core->parent) in current_parent_show()
3434 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3445 struct clk_core *core = s->private; in current_parent_write() local
3454 parent = clk_core_get_parent_by_index(core, idx); in current_parent_write()
3459 err = clk_core_set_parent_nolock(core, parent); in current_parent_write()
3478 struct clk_core *core = s->private; in clk_duty_cycle_show() local
3479 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3489 struct clk_core *core = s->private; in clk_min_rate_show() local
3493 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_min_rate_show()
3503 struct clk_core *core = s->private; in clk_max_rate_show() local
3507 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_max_rate_show()
3515 static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) in clk_debug_create_one() argument
3519 if (!core || !pdentry) in clk_debug_create_one()
3522 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3523 core->dentry = root; in clk_debug_create_one()
3525 debugfs_create_file("clk_rate", clk_rate_mode, root, core, in clk_debug_create_one()
3527 debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops); in clk_debug_create_one()
3528 debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops); in clk_debug_create_one()
3529 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3530 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3531 debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops); in clk_debug_create_one()
3532 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3533 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3534 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3535 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3536 debugfs_create_file("clk_duty_cycle", 0444, root, core, in clk_debug_create_one()
3539 debugfs_create_file("clk_prepare_enable", 0644, root, core, in clk_debug_create_one()
3542 if (core->num_parents > 1) in clk_debug_create_one()
3543 debugfs_create_file("clk_parent", 0644, root, core, in clk_debug_create_one()
3547 if (core->num_parents > 0) in clk_debug_create_one()
3548 debugfs_create_file("clk_parent", 0444, root, core, in clk_debug_create_one()
3551 if (core->num_parents > 1) in clk_debug_create_one()
3552 debugfs_create_file("clk_possible_parents", 0444, root, core, in clk_debug_create_one()
3555 if (core->ops->debug_init) in clk_debug_create_one()
3556 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3567 static void clk_debug_register(struct clk_core *core) in clk_debug_register() argument
3570 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3572 clk_debug_create_one(core, rootdir); in clk_debug_register()
3584 static void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3587 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3588 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3589 core->dentry = NULL; in clk_debug_unregister()
3604 struct clk_core *core; in clk_debug_init() local
3636 hlist_for_each_entry(core, &clk_debug_list, debug_node) in clk_debug_init()
3637 clk_debug_create_one(core, rootdir); in clk_debug_init()
3646 static inline void clk_debug_register(struct clk_core *core) { } in clk_debug_register() argument
3647 static inline void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3700 static int __clk_core_init(struct clk_core *core) in __clk_core_init() argument
3715 core->hw->core = core; in __clk_core_init()
3717 ret = clk_pm_runtime_get(core); in __clk_core_init()
3722 if (clk_core_lookup(core->name)) { in __clk_core_init()
3724 __func__, core->name); in __clk_core_init()
3730 if (core->ops->set_rate && in __clk_core_init()
3731 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3732 core->ops->recalc_rate)) { in __clk_core_init()
3734 __func__, core->name); in __clk_core_init()
3739 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3741 __func__, core->name); in __clk_core_init()
3746 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3748 __func__, core->name); in __clk_core_init()
3753 if (core->ops->set_rate_and_parent && in __clk_core_init()
3754 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3756 __func__, core->name); in __clk_core_init()
3775 if (core->ops->init) { in __clk_core_init()
3776 ret = core->ops->init(core->hw); in __clk_core_init()
3781 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3794 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3795 core->orphan = parent->orphan; in __clk_core_init()
3796 } else if (!core->num_parents) { in __clk_core_init()
3797 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3798 core->orphan = false; in __clk_core_init()
3800 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3801 core->orphan = true; in __clk_core_init()
3811 if (core->ops->recalc_accuracy) in __clk_core_init()
3812 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3815 core->accuracy = parent->accuracy; in __clk_core_init()
3817 core->accuracy = 0; in __clk_core_init()
3824 phase = clk_core_get_phase(core); in __clk_core_init()
3828 core->name); in __clk_core_init()
3835 clk_core_update_duty_cycle_nolock(core); in __clk_core_init()
3843 if (core->ops->recalc_rate) in __clk_core_init()
3844 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3850 core->rate = core->req_rate = rate; in __clk_core_init()
3857 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3858 ret = clk_core_prepare(core); in __clk_core_init()
3861 __func__, core->name); in __clk_core_init()
3865 ret = clk_core_enable_lock(core); in __clk_core_init()
3868 __func__, core->name); in __clk_core_init()
3869 clk_core_unprepare(core); in __clk_core_init()
3876 kref_init(&core->ref); in __clk_core_init()
3878 clk_pm_runtime_put(core); in __clk_core_init()
3881 hlist_del_init(&core->child_node); in __clk_core_init()
3882 core->hw->core = NULL; in __clk_core_init()
3888 clk_debug_register(core); in __clk_core_init()
3898 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
3901 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3923 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk() argument
3932 clk->core = core; in alloc_clk()
3969 struct clk_core *core; in clk_hw_create_clk() local
3975 core = hw->core; in clk_hw_create_clk()
3976 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
3981 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
3986 kref_get(&core->ref); in clk_hw_create_clk()
3987 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
4004 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4028 static int clk_core_populate_parent_map(struct clk_core *core, in clk_core_populate_parent_map() argument
4046 core->parents = parents; in clk_core_populate_parent_map()
4057 __func__, core->name); in clk_core_populate_parent_map()
4090 static void clk_core_free_parent_map(struct clk_core *core) in clk_core_free_parent_map() argument
4092 int i = core->num_parents; in clk_core_free_parent_map()
4094 if (!core->num_parents) in clk_core_free_parent_map()
4098 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4099 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4102 kfree(core->parents); in clk_core_free_parent_map()
4109 struct clk_core *core; in __clk_register() local
4119 core = kzalloc(sizeof(*core), GFP_KERNEL); in __clk_register()
4120 if (!core) { in __clk_register()
4125 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4126 if (!core->name) { in __clk_register()
4135 core->ops = init->ops; in __clk_register()
4138 core->rpm_enabled = true; in __clk_register()
4139 core->dev = dev; in __clk_register()
4140 core->of_node = np; in __clk_register()
4142 core->owner = dev->driver->owner; in __clk_register()
4143 core->hw = hw; in __clk_register()
4144 core->flags = init->flags; in __clk_register()
4145 core->num_parents = init->num_parents; in __clk_register()
4146 core->min_rate = 0; in __clk_register()
4147 core->max_rate = ULONG_MAX; in __clk_register()
4149 ret = clk_core_populate_parent_map(core, init); in __clk_register()
4153 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4159 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4165 clk_core_link_consumer(core, hw->clk); in __clk_register()
4167 ret = __clk_core_init(core); in __clk_register()
4179 clk_core_free_parent_map(core); in __clk_register()
4182 kfree_const(core->name); in __clk_register()
4184 kfree(core); in __clk_register()
4267 struct clk_core *core = container_of(ref, struct clk_core, ref); in __clk_release() local
4271 clk_core_free_parent_map(core); in __clk_release()
4272 kfree_const(core->name); in __clk_release()
4273 kfree(core); in __clk_release()
4318 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4319 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4326 static void clk_core_evict_parent_cache(struct clk_core *core) in clk_core_evict_parent_cache() argument
4335 clk_core_evict_parent_cache_subtree(root, core); in clk_core_evict_parent_cache()
4351 clk_debug_unregister(clk->core); in clk_unregister()
4355 ops = clk->core->ops; in clk_unregister()
4358 clk->core->name); in clk_unregister()
4366 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4370 ops->terminate(clk->core->hw); in clk_unregister()
4372 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4377 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4382 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4384 hlist_del_init(&clk->core->child_node); in clk_unregister()
4386 if (clk->core->prepare_count) in clk_unregister()
4388 __func__, clk->core->name); in clk_unregister()
4390 if (clk->core->protect_count) in clk_unregister()
4392 __func__, clk->core->name); in clk_unregister()
4394 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4507 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4545 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4546 clk_core_rate_unprotect(clk->core); in __clk_put()
4556 owner = clk->core->owner; in __clk_put()
4557 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4616 clk->core->notifier_count++; in clk_notifier_register()
4650 clk->core->notifier_count--; in clk_notifier_unregister()