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
113 if (!core->rpm_enabled) in clk_pm_runtime_get()
116 ret = pm_runtime_get_sync(core->dev); in clk_pm_runtime_get()
120 static void clk_pm_runtime_put(struct clk_core *core) in clk_pm_runtime_put() argument
122 if (!core->rpm_enabled) in clk_pm_runtime_put()
125 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
197 static bool clk_core_rate_is_protected(struct clk_core *core) in clk_core_rate_is_protected() argument
199 return core->protect_count; in clk_core_rate_is_protected()
202 static bool clk_core_is_prepared(struct clk_core *core) in clk_core_is_prepared() argument
210 if (!core->ops->is_prepared) in clk_core_is_prepared()
211 return core->prepare_count; in clk_core_is_prepared()
213 if (!clk_pm_runtime_get(core)) { in clk_core_is_prepared()
214 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
215 clk_pm_runtime_put(core); in clk_core_is_prepared()
221 static bool clk_core_is_enabled(struct clk_core *core) in clk_core_is_enabled() argument
229 if (!core->ops->is_enabled) in clk_core_is_enabled()
230 return core->enable_count; in clk_core_is_enabled()
242 if (core->rpm_enabled) { in clk_core_is_enabled()
243 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
244 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
250 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
252 if (core->rpm_enabled) in clk_core_is_enabled()
253 pm_runtime_put(core->dev); in clk_core_is_enabled()
262 return !clk ? NULL : clk->core->name; in __clk_get_name()
268 return hw->core->name; in clk_hw_get_name()
274 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
280 return hw->core->num_parents; in clk_hw_get_num_parents()
286 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
291 struct clk_core *core) in __clk_lookup_subtree() argument
296 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
297 return core; in __clk_lookup_subtree()
299 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
388 static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index) in clk_core_get() argument
390 const char *name = core->parents[p_index].fw_name; in clk_core_get()
391 int index = core->parents[p_index].index; in clk_core_get()
393 struct device *dev = core->dev; in clk_core_get()
395 struct device_node *np = core->of_node; in clk_core_get()
413 return hw->core; in clk_core_get()
416 static void clk_core_fill_parent_index(struct clk_core *core, u8 index) in clk_core_fill_parent_index() argument
418 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
422 parent = entry->hw->core; in clk_core_fill_parent_index()
431 parent = clk_core_get(core, index); in clk_core_fill_parent_index()
438 entry->core = parent; in clk_core_fill_parent_index()
441 static struct clk_core *clk_core_get_parent_by_index(struct clk_core *core, in clk_core_get_parent_by_index() argument
444 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
447 if (!core->parents[index].core) in clk_core_get_parent_by_index()
448 clk_core_fill_parent_index(core, index); in clk_core_get_parent_by_index()
450 return core->parents[index].core; in clk_core_get_parent_by_index()
458 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
466 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
469 static unsigned long clk_core_get_rate_nolock(struct clk_core *core) in clk_core_get_rate_nolock() argument
471 if (!core) in clk_core_get_rate_nolock()
474 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
475 return core->rate; in clk_core_get_rate_nolock()
487 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
491 static unsigned long __clk_get_accuracy(struct clk_core *core) in __clk_get_accuracy() argument
493 if (!core) in __clk_get_accuracy()
496 return core->accuracy; in __clk_get_accuracy()
501 return !clk ? 0 : clk->core->flags; in __clk_get_flags()
507 return hw->core->flags; in clk_hw_get_flags()
513 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
519 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
525 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
534 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
551 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
557 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
558 parent = core->parent; in clk_mux_determine_rate_flags()
559 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
569 best = clk_core_get_rate_nolock(core); in clk_mux_determine_rate_flags()
576 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
578 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
582 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
613 struct clk_core *core = clk_core_lookup(name); in __clk_lookup() local
615 return !core ? NULL : core->hw->clk; in __clk_lookup()
618 static void clk_core_get_boundaries(struct clk_core *core, in clk_core_get_boundaries() argument
626 *min_rate = core->min_rate; in clk_core_get_boundaries()
627 *max_rate = core->max_rate; in clk_core_get_boundaries()
629 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
632 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
639 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
640 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
671 static void clk_core_rate_unprotect(struct clk_core *core) in clk_core_rate_unprotect() argument
675 if (!core) in clk_core_rate_unprotect()
678 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
679 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
682 if (--core->protect_count > 0) in clk_core_rate_unprotect()
685 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
688 static int clk_core_rate_nuke_protect(struct clk_core *core) in clk_core_rate_nuke_protect() argument
694 if (!core) in clk_core_rate_nuke_protect()
697 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
700 ret = core->protect_count; in clk_core_rate_nuke_protect()
701 core->protect_count = 1; in clk_core_rate_nuke_protect()
702 clk_core_rate_unprotect(core); in clk_core_rate_nuke_protect()
739 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
746 static void clk_core_rate_protect(struct clk_core *core) in clk_core_rate_protect() argument
750 if (!core) in clk_core_rate_protect()
753 if (core->protect_count == 0) in clk_core_rate_protect()
754 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
756 core->protect_count++; in clk_core_rate_protect()
759 static void clk_core_rate_restore_protect(struct clk_core *core, int count) in clk_core_rate_restore_protect() argument
763 if (!core) in clk_core_rate_restore_protect()
769 clk_core_rate_protect(core); in clk_core_rate_restore_protect()
770 core->protect_count = count; in clk_core_rate_restore_protect()
797 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
805 static void clk_core_unprepare(struct clk_core *core) in clk_core_unprepare() argument
809 if (!core) in clk_core_unprepare()
812 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
813 "%s already unprepared\n", core->name)) in clk_core_unprepare()
816 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
817 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
820 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
821 clk_core_rate_unprotect(core); in clk_core_unprepare()
823 if (--core->prepare_count > 0) in clk_core_unprepare()
826 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
828 trace_clk_unprepare(core); in clk_core_unprepare()
830 if (core->ops->unprepare) in clk_core_unprepare()
831 core->ops->unprepare(core->hw); in clk_core_unprepare()
833 clk_pm_runtime_put(core); in clk_core_unprepare()
835 trace_clk_unprepare_complete(core); in clk_core_unprepare()
836 clk_core_unprepare(core->parent); in clk_core_unprepare()
839 static void clk_core_unprepare_lock(struct clk_core *core) in clk_core_unprepare_lock() argument
842 clk_core_unprepare(core); in clk_core_unprepare_lock()
862 clk_core_unprepare_lock(clk->core); in clk_unprepare()
866 static int clk_core_prepare(struct clk_core *core) in clk_core_prepare() argument
872 if (!core) in clk_core_prepare()
875 if (core->prepare_count == 0) { in clk_core_prepare()
876 ret = clk_pm_runtime_get(core); in clk_core_prepare()
880 ret = clk_core_prepare(core->parent); in clk_core_prepare()
884 trace_clk_prepare(core); in clk_core_prepare()
886 if (core->ops->prepare) in clk_core_prepare()
887 ret = core->ops->prepare(core->hw); in clk_core_prepare()
889 trace_clk_prepare_complete(core); in clk_core_prepare()
895 core->prepare_count++; in clk_core_prepare()
904 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
905 clk_core_rate_protect(core); in clk_core_prepare()
909 clk_core_unprepare(core->parent); in clk_core_prepare()
911 clk_pm_runtime_put(core); in clk_core_prepare()
915 static int clk_core_prepare_lock(struct clk_core *core) in clk_core_prepare_lock() argument
920 ret = clk_core_prepare(core); in clk_core_prepare_lock()
943 return clk_core_prepare_lock(clk->core); in clk_prepare()
947 static void clk_core_disable(struct clk_core *core) in clk_core_disable() argument
951 if (!core) in clk_core_disable()
954 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
957 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
958 "Disabling critical %s\n", core->name)) in clk_core_disable()
961 if (--core->enable_count > 0) in clk_core_disable()
964 trace_clk_disable_rcuidle(core); in clk_core_disable()
966 if (core->ops->disable) in clk_core_disable()
967 core->ops->disable(core->hw); in clk_core_disable()
969 trace_clk_disable_complete_rcuidle(core); in clk_core_disable()
971 clk_core_disable(core->parent); in clk_core_disable()
974 static void clk_core_disable_lock(struct clk_core *core) in clk_core_disable_lock() argument
979 clk_core_disable(core); in clk_core_disable_lock()
1000 clk_core_disable_lock(clk->core); in clk_disable()
1004 static int clk_core_enable(struct clk_core *core) in clk_core_enable() argument
1010 if (!core) in clk_core_enable()
1013 if (WARN(core->prepare_count == 0, in clk_core_enable()
1014 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1017 if (core->enable_count == 0) { in clk_core_enable()
1018 ret = clk_core_enable(core->parent); in clk_core_enable()
1023 trace_clk_enable_rcuidle(core); in clk_core_enable()
1025 if (core->ops->enable) in clk_core_enable()
1026 ret = core->ops->enable(core->hw); in clk_core_enable()
1028 trace_clk_enable_complete_rcuidle(core); in clk_core_enable()
1031 clk_core_disable(core->parent); in clk_core_enable()
1036 core->enable_count++; in clk_core_enable()
1040 static int clk_core_enable_lock(struct clk_core *core) in clk_core_enable_lock() argument
1046 ret = clk_core_enable(core); in clk_core_enable_lock()
1064 struct clk_core *core = hw->core; in clk_gate_restore_context() local
1066 if (core->enable_count) in clk_gate_restore_context()
1067 core->ops->enable(hw); in clk_gate_restore_context()
1069 core->ops->disable(hw); in clk_gate_restore_context()
1073 static int clk_core_save_context(struct clk_core *core) in clk_core_save_context() argument
1078 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1084 if (core->ops && core->ops->save_context) in clk_core_save_context()
1085 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1090 static void clk_core_restore_context(struct clk_core *core) in clk_core_restore_context() argument
1094 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1095 core->ops->restore_context(core->hw); in clk_core_restore_context()
1097 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1137 struct clk_core *core; in clk_restore_context() local
1139 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_restore_context()
1140 clk_core_restore_context(core); in clk_restore_context()
1142 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_restore_context()
1143 clk_core_restore_context(core); in clk_restore_context()
1165 return clk_core_enable_lock(clk->core); in clk_enable()
1169 static int clk_core_prepare_enable(struct clk_core *core) in clk_core_prepare_enable() argument
1173 ret = clk_core_prepare_lock(core); in clk_core_prepare_enable()
1177 ret = clk_core_enable_lock(core); in clk_core_prepare_enable()
1179 clk_core_unprepare_lock(core); in clk_core_prepare_enable()
1184 static void clk_core_disable_unprepare(struct clk_core *core) in clk_core_disable_unprepare() argument
1186 clk_core_disable_lock(core); in clk_core_disable_unprepare()
1187 clk_core_unprepare_lock(core); in clk_core_disable_unprepare()
1190 static void clk_unprepare_unused_subtree(struct clk_core *core) in clk_unprepare_unused_subtree() argument
1196 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1199 if (core->prepare_count) in clk_unprepare_unused_subtree()
1202 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1205 if (clk_pm_runtime_get(core)) in clk_unprepare_unused_subtree()
1208 if (clk_core_is_prepared(core)) { in clk_unprepare_unused_subtree()
1209 trace_clk_unprepare(core); in clk_unprepare_unused_subtree()
1210 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1211 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1212 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1213 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1214 trace_clk_unprepare_complete(core); in clk_unprepare_unused_subtree()
1217 clk_pm_runtime_put(core); in clk_unprepare_unused_subtree()
1220 static void clk_disable_unused_subtree(struct clk_core *core) in clk_disable_unused_subtree() argument
1227 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1230 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1231 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1233 if (clk_pm_runtime_get(core)) in clk_disable_unused_subtree()
1238 if (core->enable_count) in clk_disable_unused_subtree()
1241 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1249 if (clk_core_is_enabled(core)) { in clk_disable_unused_subtree()
1250 trace_clk_disable(core); in clk_disable_unused_subtree()
1251 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1252 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1253 else if (core->ops->disable) in clk_disable_unused_subtree()
1254 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1255 trace_clk_disable_complete(core); in clk_disable_unused_subtree()
1260 clk_pm_runtime_put(core); in clk_disable_unused_subtree()
1262 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1263 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1276 struct clk_core *core; in clk_disable_unused() local
1285 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1286 clk_disable_unused_subtree(core); in clk_disable_unused()
1288 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1289 clk_disable_unused_subtree(core); in clk_disable_unused()
1291 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1292 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1294 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1295 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1303 static int clk_core_determine_round_nolock(struct clk_core *core, in clk_core_determine_round_nolock() argument
1310 if (!core) in clk_core_determine_round_nolock()
1319 if (clk_core_rate_is_protected(core)) { in clk_core_determine_round_nolock()
1320 req->rate = core->rate; in clk_core_determine_round_nolock()
1321 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1322 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1323 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1324 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1337 static void clk_core_init_rate_req(struct clk_core * const core, in clk_core_init_rate_req() argument
1342 if (WARN_ON(!core || !req)) in clk_core_init_rate_req()
1345 parent = core->parent; in clk_core_init_rate_req()
1355 static bool clk_core_can_round(struct clk_core * const core) in clk_core_can_round() argument
1357 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1360 static int clk_core_round_rate_nolock(struct clk_core *core, in clk_core_round_rate_nolock() argument
1365 if (!core) { in clk_core_round_rate_nolock()
1370 clk_core_init_rate_req(core, req); in clk_core_round_rate_nolock()
1372 if (clk_core_can_round(core)) in clk_core_round_rate_nolock()
1373 return clk_core_determine_round_nolock(core, req); in clk_core_round_rate_nolock()
1374 else if (core->flags & CLK_SET_RATE_PARENT) in clk_core_round_rate_nolock()
1375 return clk_core_round_rate_nolock(core->parent, req); in clk_core_round_rate_nolock()
1377 req->rate = core->rate; in clk_core_round_rate_nolock()
1395 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1404 clk_core_get_boundaries(hw->core, &req.min_rate, &req.max_rate); in clk_hw_round_rate()
1407 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1435 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1437 clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate); in clk_round_rate()
1440 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1443 clk_core_rate_protect(clk->core); in clk_round_rate()
1468 static int __clk_notify(struct clk_core *core, unsigned long msg, in __clk_notify() argument
1479 if (cn->clk->core == core) { in __clk_notify()
1500 static void __clk_recalc_accuracies(struct clk_core *core) in __clk_recalc_accuracies() argument
1507 if (core->parent) in __clk_recalc_accuracies()
1508 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1510 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1511 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1514 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1516 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1520 static long clk_core_get_accuracy(struct clk_core *core) in clk_core_get_accuracy() argument
1525 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy()
1526 __clk_recalc_accuracies(core); in clk_core_get_accuracy()
1528 accuracy = __clk_get_accuracy(core); in clk_core_get_accuracy()
1548 return clk_core_get_accuracy(clk->core); in clk_get_accuracy()
1552 static unsigned long clk_recalc(struct clk_core *core, in clk_recalc() argument
1557 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1558 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1559 clk_pm_runtime_put(core); in clk_recalc()
1576 static void __clk_recalc_rates(struct clk_core *core, unsigned long msg) in __clk_recalc_rates() argument
1584 old_rate = core->rate; in __clk_recalc_rates()
1586 if (core->parent) in __clk_recalc_rates()
1587 parent_rate = core->parent->rate; in __clk_recalc_rates()
1589 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1595 if (core->notifier_count && msg) in __clk_recalc_rates()
1596 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1598 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1602 static unsigned long clk_core_get_rate(struct clk_core *core) in clk_core_get_rate() argument
1608 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate()
1609 __clk_recalc_rates(core, 0); in clk_core_get_rate()
1611 rate = clk_core_get_rate_nolock(core); in clk_core_get_rate()
1630 return clk_core_get_rate(clk->core); in clk_get_rate()
1634 static int clk_fetch_parent_index(struct clk_core *core, in clk_fetch_parent_index() argument
1642 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1644 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1648 if (core->parents[i].core) in clk_fetch_parent_index()
1652 if (core->parents[i].hw) { in clk_fetch_parent_index()
1653 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1661 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
1665 if (core->parents[i].name && in clk_fetch_parent_index()
1666 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1670 if (i == core->num_parents) in clk_fetch_parent_index()
1673 core->parents[i].core = parent; in clk_fetch_parent_index()
1680 static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan) in clk_core_update_orphan_status() argument
1684 core->orphan = is_orphan; in clk_core_update_orphan_status()
1686 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1690 static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) in clk_reparent() argument
1692 bool was_orphan = core->orphan; in clk_reparent()
1694 hlist_del(&core->child_node); in clk_reparent()
1700 if (new_parent->new_child == core) in clk_reparent()
1703 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1706 clk_core_update_orphan_status(core, becomes_orphan); in clk_reparent()
1708 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1710 clk_core_update_orphan_status(core, true); in clk_reparent()
1713 core->parent = new_parent; in clk_reparent()
1716 static struct clk_core *__clk_set_parent_before(struct clk_core *core, in __clk_set_parent_before() argument
1720 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1743 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
1749 if (core->prepare_count) { in __clk_set_parent_before()
1751 clk_core_enable_lock(core); in __clk_set_parent_before()
1756 clk_reparent(core, parent); in __clk_set_parent_before()
1762 static void __clk_set_parent_after(struct clk_core *core, in __clk_set_parent_after() argument
1770 if (core->prepare_count) { in __clk_set_parent_after()
1771 clk_core_disable_lock(core); in __clk_set_parent_after()
1776 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
1782 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
1789 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
1791 trace_clk_set_parent(core, parent); in __clk_set_parent()
1794 if (parent && core->ops->set_parent) in __clk_set_parent()
1795 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
1797 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
1801 clk_reparent(core, old_parent); in __clk_set_parent()
1803 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
1808 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
1827 static int __clk_speculate_rates(struct clk_core *core, in __clk_speculate_rates() argument
1836 new_rate = clk_recalc(core, parent_rate); in __clk_speculate_rates()
1839 if (core->notifier_count) in __clk_speculate_rates()
1840 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
1844 __func__, core->name, ret); in __clk_speculate_rates()
1848 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
1858 static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, in clk_calc_subtree() argument
1863 core->new_rate = new_rate; in clk_calc_subtree()
1864 core->new_parent = new_parent; in clk_calc_subtree()
1865 core->new_parent_index = p_index; in clk_calc_subtree()
1867 core->new_child = NULL; in clk_calc_subtree()
1868 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
1869 new_parent->new_child = core; in clk_calc_subtree()
1871 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
1881 static struct clk_core *clk_calc_new_rates(struct clk_core *core, in clk_calc_new_rates() argument
1884 struct clk_core *top = core; in clk_calc_new_rates()
1894 if (IS_ERR_OR_NULL(core)) in clk_calc_new_rates()
1898 parent = old_parent = core->parent; in clk_calc_new_rates()
1902 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_calc_new_rates()
1905 if (clk_core_can_round(core)) { in clk_calc_new_rates()
1912 clk_core_init_rate_req(core, &req); in clk_calc_new_rates()
1914 ret = clk_core_determine_round_nolock(core, &req); in clk_calc_new_rates()
1920 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
1924 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
1926 core->new_rate = core->rate; in clk_calc_new_rates()
1937 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
1939 __func__, core->name); in clk_calc_new_rates()
1944 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
1945 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
1948 __func__, parent->name, core->name); in clk_calc_new_rates()
1953 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
1958 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
1968 static struct clk_core *clk_propagate_rate_change(struct clk_core *core, in clk_propagate_rate_change() argument
1974 if (core->rate == core->new_rate) in clk_propagate_rate_change()
1977 if (core->notifier_count) { in clk_propagate_rate_change()
1978 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
1980 fail_clk = core; in clk_propagate_rate_change()
1983 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
1985 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
1993 if (core->new_child) { in clk_propagate_rate_change()
1994 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2006 static void clk_change_rate(struct clk_core *core) in clk_change_rate() argument
2016 old_rate = core->rate; in clk_change_rate()
2018 if (core->new_parent) { in clk_change_rate()
2019 parent = core->new_parent; in clk_change_rate()
2020 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2021 } else if (core->parent) { in clk_change_rate()
2022 parent = core->parent; in clk_change_rate()
2023 best_parent_rate = core->parent->rate; in clk_change_rate()
2026 if (clk_pm_runtime_get(core)) in clk_change_rate()
2029 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2032 clk_core_prepare(core); in clk_change_rate()
2034 clk_core_enable(core); in clk_change_rate()
2038 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2039 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2040 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2042 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2044 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2046 core->new_parent_index); in clk_change_rate()
2047 } else if (core->ops->set_parent) { in clk_change_rate()
2048 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2051 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2052 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2055 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2058 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2060 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2061 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2063 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2065 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2067 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2071 clk_core_disable(core); in clk_change_rate()
2073 clk_core_unprepare(core); in clk_change_rate()
2076 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2079 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2080 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2082 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2083 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2089 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2091 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2097 if (core->new_child) in clk_change_rate()
2098 clk_change_rate(core->new_child); in clk_change_rate()
2100 clk_pm_runtime_put(core); in clk_change_rate()
2103 static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, in clk_core_req_round_rate_nolock() argument
2111 if (!core) in clk_core_req_round_rate_nolock()
2115 cnt = clk_core_rate_nuke_protect(core); in clk_core_req_round_rate_nolock()
2119 clk_core_get_boundaries(core, &req.min_rate, &req.max_rate); in clk_core_req_round_rate_nolock()
2122 ret = clk_core_round_rate_nolock(core, &req); in clk_core_req_round_rate_nolock()
2125 clk_core_rate_restore_protect(core, cnt); in clk_core_req_round_rate_nolock()
2130 static int clk_core_set_rate_nolock(struct clk_core *core, in clk_core_set_rate_nolock() argument
2137 if (!core) in clk_core_set_rate_nolock()
2140 rate = clk_core_req_round_rate_nolock(core, req_rate); in clk_core_set_rate_nolock()
2143 if (rate == clk_core_get_rate_nolock(core)) in clk_core_set_rate_nolock()
2147 if (clk_core_rate_is_protected(core)) in clk_core_set_rate_nolock()
2151 top = clk_calc_new_rates(core, req_rate); in clk_core_set_rate_nolock()
2155 ret = clk_pm_runtime_get(core); in clk_core_set_rate_nolock()
2172 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2174 clk_pm_runtime_put(core); in clk_core_set_rate_nolock()
2211 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2213 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2216 clk_core_rate_protect(clk->core); in clk_set_rate()
2259 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2261 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2289 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range()
2297 clk_core_rate_unprotect(clk->core); in clk_set_rate_range()
2305 rate = clk_core_get_rate_nolock(clk->core); in clk_set_rate_range()
2325 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range()
2334 clk_core_rate_protect(clk->core); in clk_set_rate_range()
2389 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2396 static struct clk_core *__clk_init_parent(struct clk_core *core) in __clk_init_parent() argument
2400 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2401 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2403 return clk_core_get_parent_by_index(core, index); in __clk_init_parent()
2406 static void clk_core_reparent(struct clk_core *core, in clk_core_reparent() argument
2409 clk_reparent(core, new_parent); in clk_core_reparent()
2410 __clk_recalc_accuracies(core); in clk_core_reparent()
2411 __clk_recalc_rates(core, POST_RATE_CHANGE); in clk_core_reparent()
2419 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2434 struct clk_core *core, *parent_core; in clk_has_parent() local
2441 core = clk->core; in clk_has_parent()
2442 parent_core = parent->core; in clk_has_parent()
2445 if (core->parent == parent_core) in clk_has_parent()
2448 for (i = 0; i < core->num_parents; i++) in clk_has_parent()
2449 if (!strcmp(core->parents[i].name, parent_core->name)) in clk_has_parent()
2456 static int clk_core_set_parent_nolock(struct clk_core *core, in clk_core_set_parent_nolock() argument
2465 if (!core) in clk_core_set_parent_nolock()
2468 if (core->parent == parent) in clk_core_set_parent_nolock()
2472 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2476 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2479 if (clk_core_rate_is_protected(core)) in clk_core_set_parent_nolock()
2484 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2487 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2493 ret = clk_pm_runtime_get(core); in clk_core_set_parent_nolock()
2498 ret = __clk_speculate_rates(core, p_rate); in clk_core_set_parent_nolock()
2505 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2509 __clk_recalc_rates(core, ABORT_RATE_CHANGE); in clk_core_set_parent_nolock()
2511 __clk_recalc_rates(core, POST_RATE_CHANGE); in clk_core_set_parent_nolock()
2512 __clk_recalc_accuracies(core); in clk_core_set_parent_nolock()
2516 clk_pm_runtime_put(core); in clk_core_set_parent_nolock()
2523 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2554 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2556 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2557 parent ? parent->core : NULL); in clk_set_parent()
2560 clk_core_rate_protect(clk->core); in clk_set_parent()
2568 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) in clk_core_set_phase_nolock() argument
2574 if (!core) in clk_core_set_phase_nolock()
2577 if (clk_core_rate_is_protected(core)) in clk_core_set_phase_nolock()
2580 trace_clk_set_phase(core, degrees); in clk_core_set_phase_nolock()
2582 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2583 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2585 core->phase = degrees; in clk_core_set_phase_nolock()
2588 trace_clk_set_phase_complete(core, degrees); in clk_core_set_phase_nolock()
2628 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2630 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2633 clk_core_rate_protect(clk->core); in clk_set_phase()
2641 static int clk_core_get_phase(struct clk_core *core) in clk_core_get_phase() argument
2647 if (core->ops->get_phase) in clk_core_get_phase()
2648 core->phase = core->ops->get_phase(core->hw); in clk_core_get_phase()
2649 ret = core->phase; in clk_core_get_phase()
2667 return clk_core_get_phase(clk->core); in clk_get_phase()
2671 static void clk_core_reset_duty_cycle_nolock(struct clk_core *core) in clk_core_reset_duty_cycle_nolock() argument
2674 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2675 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2678 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core);
2680 static int clk_core_update_duty_cycle_nolock(struct clk_core *core) in clk_core_update_duty_cycle_nolock() argument
2682 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2685 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2686 return clk_core_update_duty_cycle_parent_nolock(core); in clk_core_update_duty_cycle_nolock()
2688 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2701 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_nolock()
2705 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core) in clk_core_update_duty_cycle_parent_nolock() argument
2709 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2710 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2711 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2712 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2714 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_parent_nolock()
2720 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core,
2723 static int clk_core_set_duty_cycle_nolock(struct clk_core *core, in clk_core_set_duty_cycle_nolock() argument
2730 if (clk_core_rate_is_protected(core)) in clk_core_set_duty_cycle_nolock()
2733 trace_clk_set_duty_cycle(core, duty); in clk_core_set_duty_cycle_nolock()
2735 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
2736 return clk_core_set_duty_cycle_parent_nolock(core, duty); in clk_core_set_duty_cycle_nolock()
2738 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
2740 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
2742 trace_clk_set_duty_cycle_complete(core, duty); in clk_core_set_duty_cycle_nolock()
2747 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core, in clk_core_set_duty_cycle_parent_nolock() argument
2752 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
2753 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
2754 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
2755 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
2790 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
2792 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
2795 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
2803 static int clk_core_get_scaled_duty_cycle(struct clk_core *core, in clk_core_get_scaled_duty_cycle() argument
2806 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
2811 ret = clk_core_update_duty_cycle_nolock(core); in clk_core_get_scaled_duty_cycle()
2833 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
2856 if (p->core == q->core) in clk_is_match()
3003 struct clk_core *core = s->private; in clk_flags_show() local
3004 unsigned long flags = core->flags; in clk_flags_show()
3022 static void possible_parent_show(struct seq_file *s, struct clk_core *core, in possible_parent_show() argument
3039 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3042 else if (core->parents[i].name) in possible_parent_show()
3043 seq_puts(s, core->parents[i].name); in possible_parent_show()
3044 else if (core->parents[i].fw_name) in possible_parent_show()
3045 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3046 else if (core->parents[i].index >= 0) in possible_parent_show()
3048 of_clk_get_parent_name(core->of_node, in possible_parent_show()
3049 core->parents[i].index)); in possible_parent_show()
3058 struct clk_core *core = s->private; in possible_parents_show() local
3061 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3062 possible_parent_show(s, core, i, ' '); in possible_parents_show()
3064 possible_parent_show(s, core, i, '\n'); in possible_parents_show()
3072 struct clk_core *core = s->private; in current_parent_show() local
3074 if (core->parent) in current_parent_show()
3075 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3083 struct clk_core *core = s->private; in clk_duty_cycle_show() local
3084 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3094 struct clk_core *core = s->private; in clk_min_rate_show() local
3098 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_min_rate_show()
3108 struct clk_core *core = s->private; in clk_max_rate_show() local
3112 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_max_rate_show()
3120 static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) in clk_debug_create_one() argument
3124 if (!core || !pdentry) in clk_debug_create_one()
3127 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3128 core->dentry = root; in clk_debug_create_one()
3130 debugfs_create_ulong("clk_rate", 0444, root, &core->rate); in clk_debug_create_one()
3131 debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops); in clk_debug_create_one()
3132 debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops); in clk_debug_create_one()
3133 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3134 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3135 debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops); in clk_debug_create_one()
3136 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3137 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3138 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3139 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3140 debugfs_create_file("clk_duty_cycle", 0444, root, core, in clk_debug_create_one()
3143 if (core->num_parents > 0) in clk_debug_create_one()
3144 debugfs_create_file("clk_parent", 0444, root, core, in clk_debug_create_one()
3147 if (core->num_parents > 1) in clk_debug_create_one()
3148 debugfs_create_file("clk_possible_parents", 0444, root, core, in clk_debug_create_one()
3151 if (core->ops->debug_init) in clk_debug_create_one()
3152 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3163 static void clk_debug_register(struct clk_core *core) in clk_debug_register() argument
3166 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3168 clk_debug_create_one(core, rootdir); in clk_debug_register()
3180 static void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3183 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3184 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3185 core->dentry = NULL; in clk_debug_unregister()
3200 struct clk_core *core; in clk_debug_init() local
3214 hlist_for_each_entry(core, &clk_debug_list, debug_node) in clk_debug_init()
3215 clk_debug_create_one(core, rootdir); in clk_debug_init()
3224 static inline void clk_debug_register(struct clk_core *core) { } in clk_debug_register() argument
3225 static inline void clk_debug_reparent(struct clk_core *core, in clk_debug_reparent() argument
3229 static inline void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3241 static int __clk_core_init(struct clk_core *core) in __clk_core_init() argument
3248 if (!core) in __clk_core_init()
3253 ret = clk_pm_runtime_get(core); in __clk_core_init()
3258 if (clk_core_lookup(core->name)) { in __clk_core_init()
3260 __func__, core->name); in __clk_core_init()
3266 if (core->ops->set_rate && in __clk_core_init()
3267 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3268 core->ops->recalc_rate)) { in __clk_core_init()
3270 __func__, core->name); in __clk_core_init()
3275 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3277 __func__, core->name); in __clk_core_init()
3282 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3284 __func__, core->name); in __clk_core_init()
3289 if (core->ops->set_rate_and_parent && in __clk_core_init()
3290 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3292 __func__, core->name); in __clk_core_init()
3297 core->parent = __clk_init_parent(core); in __clk_core_init()
3309 if (core->parent) { in __clk_core_init()
3310 hlist_add_head(&core->child_node, in __clk_core_init()
3311 &core->parent->children); in __clk_core_init()
3312 core->orphan = core->parent->orphan; in __clk_core_init()
3313 } else if (!core->num_parents) { in __clk_core_init()
3314 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3315 core->orphan = false; in __clk_core_init()
3317 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3318 core->orphan = true; in __clk_core_init()
3329 if (core->ops->init) in __clk_core_init()
3330 core->ops->init(core->hw); in __clk_core_init()
3339 if (core->ops->recalc_accuracy) in __clk_core_init()
3340 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3341 __clk_get_accuracy(core->parent)); in __clk_core_init()
3342 else if (core->parent) in __clk_core_init()
3343 core->accuracy = core->parent->accuracy; in __clk_core_init()
3345 core->accuracy = 0; in __clk_core_init()
3352 if (core->ops->get_phase) in __clk_core_init()
3353 core->phase = core->ops->get_phase(core->hw); in __clk_core_init()
3355 core->phase = 0; in __clk_core_init()
3360 clk_core_update_duty_cycle_nolock(core); in __clk_core_init()
3368 if (core->ops->recalc_rate) in __clk_core_init()
3369 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3370 clk_core_get_rate_nolock(core->parent)); in __clk_core_init()
3371 else if (core->parent) in __clk_core_init()
3372 rate = core->parent->rate; in __clk_core_init()
3375 core->rate = core->req_rate = rate; in __clk_core_init()
3382 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3385 clk_core_prepare(core); in __clk_core_init()
3388 clk_core_enable(core); in __clk_core_init()
3414 kref_init(&core->ref); in __clk_core_init()
3416 clk_pm_runtime_put(core); in __clk_core_init()
3421 clk_debug_register(core); in __clk_core_init()
3431 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
3434 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3456 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk() argument
3465 clk->core = core; in alloc_clk()
3502 struct clk_core *core; in clk_hw_create_clk() local
3508 core = hw->core; in clk_hw_create_clk()
3509 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
3514 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
3519 kref_get(&core->ref); in clk_hw_create_clk()
3520 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
3542 static int clk_core_populate_parent_map(struct clk_core *core, in clk_core_populate_parent_map() argument
3560 core->parents = parents; in clk_core_populate_parent_map()
3571 __func__, core->name); in clk_core_populate_parent_map()
3604 static void clk_core_free_parent_map(struct clk_core *core) in clk_core_free_parent_map() argument
3606 int i = core->num_parents; in clk_core_free_parent_map()
3608 if (!core->num_parents) in clk_core_free_parent_map()
3612 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
3613 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
3616 kfree(core->parents); in clk_core_free_parent_map()
3623 struct clk_core *core; in __clk_register() local
3633 core = kzalloc(sizeof(*core), GFP_KERNEL); in __clk_register()
3634 if (!core) { in __clk_register()
3639 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
3640 if (!core->name) { in __clk_register()
3649 core->ops = init->ops; in __clk_register()
3652 core->rpm_enabled = true; in __clk_register()
3653 core->dev = dev; in __clk_register()
3654 core->of_node = np; in __clk_register()
3656 core->owner = dev->driver->owner; in __clk_register()
3657 core->hw = hw; in __clk_register()
3658 core->flags = init->flags; in __clk_register()
3659 core->num_parents = init->num_parents; in __clk_register()
3660 core->min_rate = 0; in __clk_register()
3661 core->max_rate = ULONG_MAX; in __clk_register()
3662 hw->core = core; in __clk_register()
3664 ret = clk_core_populate_parent_map(core, init); in __clk_register()
3668 INIT_HLIST_HEAD(&core->clks); in __clk_register()
3674 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
3680 clk_core_link_consumer(hw->core, hw->clk); in __clk_register()
3682 ret = __clk_core_init(core); in __clk_register()
3694 clk_core_free_parent_map(core); in __clk_register()
3697 kfree_const(core->name); in __clk_register()
3699 kfree(core); in __clk_register()
3759 struct clk_core *core = container_of(ref, struct clk_core, ref); in __clk_release() local
3763 clk_core_free_parent_map(core); in __clk_release()
3764 kfree_const(core->name); in __clk_release()
3765 kfree(core); in __clk_release()
3810 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
3811 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
3818 static void clk_core_evict_parent_cache(struct clk_core *core) in clk_core_evict_parent_cache() argument
3827 clk_core_evict_parent_cache_subtree(root, core); in clk_core_evict_parent_cache()
3842 clk_debug_unregister(clk->core); in clk_unregister()
3846 if (clk->core->ops == &clk_nodrv_ops) { in clk_unregister()
3848 clk->core->name); in clk_unregister()
3856 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
3859 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
3864 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
3869 clk_core_evict_parent_cache(clk->core); in clk_unregister()
3871 hlist_del_init(&clk->core->child_node); in clk_unregister()
3873 if (clk->core->prepare_count) in clk_unregister()
3875 __func__, clk->core->name); in clk_unregister()
3877 if (clk->core->protect_count) in clk_unregister()
3879 __func__, clk->core->name); in clk_unregister()
3881 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4035 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4036 clk_core_rate_unprotect(clk->core); in __clk_put()
4041 if (clk->min_rate > clk->core->req_rate || in __clk_put()
4042 clk->max_rate < clk->core->req_rate) in __clk_put()
4043 clk_core_set_rate_nolock(clk->core, clk->core->req_rate); in __clk_put()
4045 owner = clk->core->owner; in __clk_put()
4046 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4106 clk->core->notifier_count++; in clk_notifier_register()
4143 clk->core->notifier_count--; in clk_notifier_unregister()