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; in clk_core_determine_rate_no_reparent() local
602 struct clk_core *parent = core->parent; in clk_core_determine_rate_no_reparent()
606 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_determine_rate_no_reparent()
614 clk_core_forward_rate_req(core, req, parent, &parent_req, in clk_core_determine_rate_no_reparent()
629 best = clk_core_get_rate_nolock(core); in clk_core_determine_rate_no_reparent()
642 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
647 if (core->flags & CLK_SET_RATE_NO_REPARENT) in clk_mux_determine_rate_flags()
651 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
655 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
659 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
662 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
697 struct clk_core *core = clk_core_lookup(name); in __clk_lookup() local
699 return !core ? NULL : core->hw->clk; in __clk_lookup()
702 static void clk_core_get_boundaries(struct clk_core *core, in clk_core_get_boundaries() argument
710 *min_rate = core->min_rate; in clk_core_get_boundaries()
711 *max_rate = core->max_rate; in clk_core_get_boundaries()
713 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
716 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
732 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
736 static bool clk_core_check_boundaries(struct clk_core *core, in clk_core_check_boundaries() argument
744 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
747 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
757 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
758 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
808 static void clk_core_rate_unprotect(struct clk_core *core) in clk_core_rate_unprotect() argument
812 if (!core) in clk_core_rate_unprotect()
815 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
816 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
819 if (--core->protect_count > 0) in clk_core_rate_unprotect()
822 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
825 static int clk_core_rate_nuke_protect(struct clk_core *core) in clk_core_rate_nuke_protect() argument
831 if (!core) in clk_core_rate_nuke_protect()
834 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
837 ret = core->protect_count; in clk_core_rate_nuke_protect()
838 core->protect_count = 1; in clk_core_rate_nuke_protect()
839 clk_core_rate_unprotect(core); in clk_core_rate_nuke_protect()
876 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
883 static void clk_core_rate_protect(struct clk_core *core) in clk_core_rate_protect() argument
887 if (!core) in clk_core_rate_protect()
890 if (core->protect_count == 0) in clk_core_rate_protect()
891 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
893 core->protect_count++; in clk_core_rate_protect()
896 static void clk_core_rate_restore_protect(struct clk_core *core, int count) in clk_core_rate_restore_protect() argument
900 if (!core) in clk_core_rate_restore_protect()
906 clk_core_rate_protect(core); in clk_core_rate_restore_protect()
907 core->protect_count = count; in clk_core_rate_restore_protect()
934 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
942 static void clk_core_unprepare(struct clk_core *core) in clk_core_unprepare() argument
946 if (!core) in clk_core_unprepare()
949 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
950 "%s already unprepared\n", core->name)) in clk_core_unprepare()
953 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
954 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
957 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
958 clk_core_rate_unprotect(core); in clk_core_unprepare()
960 if (--core->prepare_count > 0) in clk_core_unprepare()
963 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
965 trace_clk_unprepare(core); in clk_core_unprepare()
967 if (core->ops->unprepare) in clk_core_unprepare()
968 core->ops->unprepare(core->hw); in clk_core_unprepare()
970 trace_clk_unprepare_complete(core); in clk_core_unprepare()
971 clk_core_unprepare(core->parent); in clk_core_unprepare()
972 clk_pm_runtime_put(core); in clk_core_unprepare()
975 static void clk_core_unprepare_lock(struct clk_core *core) in clk_core_unprepare_lock() argument
978 clk_core_unprepare(core); in clk_core_unprepare_lock()
998 clk_core_unprepare_lock(clk->core); in clk_unprepare()
1002 static int clk_core_prepare(struct clk_core *core) in clk_core_prepare() argument
1008 if (!core) in clk_core_prepare()
1011 if (core->prepare_count == 0) { in clk_core_prepare()
1012 ret = clk_pm_runtime_get(core); in clk_core_prepare()
1016 ret = clk_core_prepare(core->parent); in clk_core_prepare()
1020 trace_clk_prepare(core); in clk_core_prepare()
1022 if (core->ops->prepare) in clk_core_prepare()
1023 ret = core->ops->prepare(core->hw); in clk_core_prepare()
1025 trace_clk_prepare_complete(core); in clk_core_prepare()
1031 core->prepare_count++; in clk_core_prepare()
1040 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1041 clk_core_rate_protect(core); in clk_core_prepare()
1045 clk_core_unprepare(core->parent); in clk_core_prepare()
1047 clk_pm_runtime_put(core); in clk_core_prepare()
1051 static int clk_core_prepare_lock(struct clk_core *core) in clk_core_prepare_lock() argument
1056 ret = clk_core_prepare(core); in clk_core_prepare_lock()
1079 return clk_core_prepare_lock(clk->core); in clk_prepare()
1083 static void clk_core_disable(struct clk_core *core) in clk_core_disable() argument
1087 if (!core) in clk_core_disable()
1090 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1093 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1094 "Disabling critical %s\n", core->name)) in clk_core_disable()
1097 if (--core->enable_count > 0) in clk_core_disable()
1100 trace_clk_disable(core); in clk_core_disable()
1102 if (core->ops->disable) in clk_core_disable()
1103 core->ops->disable(core->hw); in clk_core_disable()
1105 trace_clk_disable_complete(core); in clk_core_disable()
1107 clk_core_disable(core->parent); in clk_core_disable()
1110 static void clk_core_disable_lock(struct clk_core *core) in clk_core_disable_lock() argument
1115 clk_core_disable(core); in clk_core_disable_lock()
1136 clk_core_disable_lock(clk->core); in clk_disable()
1140 static int clk_core_enable(struct clk_core *core) in clk_core_enable() argument
1146 if (!core) in clk_core_enable()
1149 if (WARN(core->prepare_count == 0, in clk_core_enable()
1150 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1153 if (core->enable_count == 0) { in clk_core_enable()
1154 ret = clk_core_enable(core->parent); in clk_core_enable()
1159 trace_clk_enable(core); in clk_core_enable()
1161 if (core->ops->enable) in clk_core_enable()
1162 ret = core->ops->enable(core->hw); in clk_core_enable()
1164 trace_clk_enable_complete(core); in clk_core_enable()
1167 clk_core_disable(core->parent); in clk_core_enable()
1172 core->enable_count++; in clk_core_enable()
1176 static int clk_core_enable_lock(struct clk_core *core) in clk_core_enable_lock() argument
1182 ret = clk_core_enable(core); in clk_core_enable_lock()
1200 struct clk_core *core = hw->core; in clk_gate_restore_context() local
1202 if (core->enable_count) in clk_gate_restore_context()
1203 core->ops->enable(hw); in clk_gate_restore_context()
1205 core->ops->disable(hw); in clk_gate_restore_context()
1209 static int clk_core_save_context(struct clk_core *core) in clk_core_save_context() argument
1214 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1220 if (core->ops && core->ops->save_context) in clk_core_save_context()
1221 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1226 static void clk_core_restore_context(struct clk_core *core) in clk_core_restore_context() argument
1230 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1231 core->ops->restore_context(core->hw); in clk_core_restore_context()
1233 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1273 struct clk_core *core; in clk_restore_context() local
1275 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_restore_context()
1276 clk_core_restore_context(core); in clk_restore_context()
1278 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_restore_context()
1279 clk_core_restore_context(core); in clk_restore_context()
1301 return clk_core_enable_lock(clk->core); in clk_enable()
1322 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1326 static int clk_core_prepare_enable(struct clk_core *core) in clk_core_prepare_enable() argument
1330 ret = clk_core_prepare_lock(core); in clk_core_prepare_enable()
1334 ret = clk_core_enable_lock(core); in clk_core_prepare_enable()
1336 clk_core_unprepare_lock(core); in clk_core_prepare_enable()
1341 static void clk_core_disable_unprepare(struct clk_core *core) in clk_core_disable_unprepare() argument
1343 clk_core_disable_lock(core); in clk_core_disable_unprepare()
1344 clk_core_unprepare_lock(core); in clk_core_disable_unprepare()
1347 static void __init clk_unprepare_unused_subtree(struct clk_core *core) in clk_unprepare_unused_subtree() argument
1353 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1356 if (core->prepare_count) in clk_unprepare_unused_subtree()
1359 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1362 if (clk_pm_runtime_get(core)) in clk_unprepare_unused_subtree()
1365 if (clk_core_is_prepared(core)) { in clk_unprepare_unused_subtree()
1366 trace_clk_unprepare(core); in clk_unprepare_unused_subtree()
1367 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1368 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1369 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1370 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1371 trace_clk_unprepare_complete(core); in clk_unprepare_unused_subtree()
1374 clk_pm_runtime_put(core); in clk_unprepare_unused_subtree()
1377 static void __init clk_disable_unused_subtree(struct clk_core *core) in clk_disable_unused_subtree() argument
1384 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1387 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1388 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1390 if (clk_pm_runtime_get(core)) in clk_disable_unused_subtree()
1395 if (core->enable_count) in clk_disable_unused_subtree()
1398 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1406 if (clk_core_is_enabled(core)) { in clk_disable_unused_subtree()
1407 trace_clk_disable(core); in clk_disable_unused_subtree()
1408 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1409 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1410 else if (core->ops->disable) in clk_disable_unused_subtree()
1411 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1412 trace_clk_disable_complete(core); in clk_disable_unused_subtree()
1417 clk_pm_runtime_put(core); in clk_disable_unused_subtree()
1419 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1420 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1433 struct clk_core *core; in clk_disable_unused() local
1444 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1445 clk_disable_unused_subtree(core); in clk_disable_unused()
1447 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1448 clk_disable_unused_subtree(core); in clk_disable_unused()
1450 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1451 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1453 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1454 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1462 static int clk_core_determine_round_nolock(struct clk_core *core, in clk_core_determine_round_nolock() argument
1469 if (!core) in clk_core_determine_round_nolock()
1482 __func__, core->name); in clk_core_determine_round_nolock()
1492 if (clk_core_rate_is_protected(core)) { in clk_core_determine_round_nolock()
1493 req->rate = core->rate; in clk_core_determine_round_nolock()
1494 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1495 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1496 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1497 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1510 static void clk_core_init_rate_req(struct clk_core * const core, in clk_core_init_rate_req() argument
1522 if (!core) in clk_core_init_rate_req()
1525 req->core = core; in clk_core_init_rate_req()
1527 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1529 parent = core->parent; in clk_core_init_rate_req()
1555 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1579 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1580 parent->core, req, in clk_hw_forward_rate_request()
1585 static bool clk_core_can_round(struct clk_core * const core) in clk_core_can_round() argument
1587 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1590 static int clk_core_round_rate_nolock(struct clk_core *core, in clk_core_round_rate_nolock() argument
1597 if (!core) { in clk_core_round_rate_nolock()
1602 if (clk_core_can_round(core)) in clk_core_round_rate_nolock()
1603 return clk_core_determine_round_nolock(core, req); in clk_core_round_rate_nolock()
1605 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1608 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1612 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1624 req->rate = core->rate; in clk_core_round_rate_nolock()
1642 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1666 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1670 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1700 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1702 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1706 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1711 clk_core_rate_protect(clk->core); in clk_round_rate()
1736 static int __clk_notify(struct clk_core *core, unsigned long msg, in __clk_notify() argument
1747 if (cn->clk->core == core) { in __clk_notify()
1768 static void __clk_recalc_accuracies(struct clk_core *core) in __clk_recalc_accuracies() argument
1775 if (core->parent) in __clk_recalc_accuracies()
1776 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1778 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1779 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1782 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1784 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1788 static long clk_core_get_accuracy_recalc(struct clk_core *core) in clk_core_get_accuracy_recalc() argument
1790 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1791 __clk_recalc_accuracies(core); in clk_core_get_accuracy_recalc()
1793 return clk_core_get_accuracy_no_lock(core); in clk_core_get_accuracy_recalc()
1813 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1820 static unsigned long clk_recalc(struct clk_core *core, in clk_recalc() argument
1825 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1826 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1827 clk_pm_runtime_put(core); in clk_recalc()
1845 static void __clk_recalc_rates(struct clk_core *core, bool update_req, in __clk_recalc_rates() argument
1854 old_rate = core->rate; in __clk_recalc_rates()
1856 if (core->parent) in __clk_recalc_rates()
1857 parent_rate = core->parent->rate; in __clk_recalc_rates()
1859 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1861 core->req_rate = core->rate; in __clk_recalc_rates()
1867 if (core->notifier_count && msg) in __clk_recalc_rates()
1868 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1870 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1874 static unsigned long clk_core_get_rate_recalc(struct clk_core *core) in clk_core_get_rate_recalc() argument
1876 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1877 __clk_recalc_rates(core, false, 0); in clk_core_get_rate_recalc()
1879 return clk_core_get_rate_nolock(core); in clk_core_get_rate_recalc()
1899 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1906 static int clk_fetch_parent_index(struct clk_core *core, in clk_fetch_parent_index() argument
1914 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1916 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1920 if (core->parents[i].core) in clk_fetch_parent_index()
1924 if (core->parents[i].hw) { in clk_fetch_parent_index()
1925 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1933 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
1937 if (core->parents[i].name && in clk_fetch_parent_index()
1938 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1942 if (i == core->num_parents) in clk_fetch_parent_index()
1945 core->parents[i].core = parent; in clk_fetch_parent_index()
1963 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
1970 static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan) in clk_core_update_orphan_status() argument
1974 core->orphan = is_orphan; in clk_core_update_orphan_status()
1976 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1980 static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) in clk_reparent() argument
1982 bool was_orphan = core->orphan; in clk_reparent()
1984 hlist_del(&core->child_node); in clk_reparent()
1990 if (new_parent->new_child == core) in clk_reparent()
1993 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1996 clk_core_update_orphan_status(core, becomes_orphan); in clk_reparent()
1998 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
2000 clk_core_update_orphan_status(core, true); in clk_reparent()
2003 core->parent = new_parent; in clk_reparent()
2006 static struct clk_core *__clk_set_parent_before(struct clk_core *core, in __clk_set_parent_before() argument
2010 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
2033 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2039 if (core->prepare_count) { in __clk_set_parent_before()
2041 clk_core_enable_lock(core); in __clk_set_parent_before()
2046 clk_reparent(core, parent); in __clk_set_parent_before()
2052 static void __clk_set_parent_after(struct clk_core *core, in __clk_set_parent_after() argument
2060 if (core->prepare_count) { in __clk_set_parent_after()
2061 clk_core_disable_lock(core); in __clk_set_parent_after()
2066 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2072 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
2079 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
2081 trace_clk_set_parent(core, parent); in __clk_set_parent()
2084 if (parent && core->ops->set_parent) in __clk_set_parent()
2085 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2087 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
2091 clk_reparent(core, old_parent); in __clk_set_parent()
2094 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
2099 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
2118 static int __clk_speculate_rates(struct clk_core *core, in __clk_speculate_rates() argument
2127 new_rate = clk_recalc(core, parent_rate); in __clk_speculate_rates()
2130 if (core->notifier_count) in __clk_speculate_rates()
2131 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2135 __func__, core->name, ret); in __clk_speculate_rates()
2139 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2149 static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, in clk_calc_subtree() argument
2154 core->new_rate = new_rate; in clk_calc_subtree()
2155 core->new_parent = new_parent; in clk_calc_subtree()
2156 core->new_parent_index = p_index; in clk_calc_subtree()
2158 core->new_child = NULL; in clk_calc_subtree()
2159 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2160 new_parent->new_child = core; in clk_calc_subtree()
2162 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2172 static struct clk_core *clk_calc_new_rates(struct clk_core *core, in clk_calc_new_rates() argument
2175 struct clk_core *top = core; in clk_calc_new_rates()
2185 if (IS_ERR_OR_NULL(core)) in clk_calc_new_rates()
2189 parent = old_parent = core->parent; in clk_calc_new_rates()
2193 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_calc_new_rates()
2196 if (clk_core_can_round(core)) { in clk_calc_new_rates()
2199 clk_core_init_rate_req(core, &req, rate); in clk_calc_new_rates()
2203 ret = clk_core_determine_round_nolock(core, &req); in clk_calc_new_rates()
2211 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2215 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2217 core->new_rate = core->rate; in clk_calc_new_rates()
2228 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2230 __func__, core->name); in clk_calc_new_rates()
2235 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2236 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
2239 __func__, parent->name, core->name); in clk_calc_new_rates()
2244 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2249 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
2259 static struct clk_core *clk_propagate_rate_change(struct clk_core *core, in clk_propagate_rate_change() argument
2265 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2268 if (core->notifier_count) { in clk_propagate_rate_change()
2269 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2271 fail_clk = core; in clk_propagate_rate_change()
2274 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2276 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2284 if (core->new_child) { in clk_propagate_rate_change()
2285 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2297 static void clk_change_rate(struct clk_core *core) in clk_change_rate() argument
2307 old_rate = core->rate; in clk_change_rate()
2309 if (core->new_parent) { in clk_change_rate()
2310 parent = core->new_parent; in clk_change_rate()
2311 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2312 } else if (core->parent) { in clk_change_rate()
2313 parent = core->parent; in clk_change_rate()
2314 best_parent_rate = core->parent->rate; in clk_change_rate()
2317 if (clk_pm_runtime_get(core)) in clk_change_rate()
2320 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2321 clk_core_prepare(core); in clk_change_rate()
2322 clk_core_enable_lock(core); in clk_change_rate()
2325 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2326 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2327 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2329 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2331 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2333 core->new_parent_index); in clk_change_rate()
2334 } else if (core->ops->set_parent) { in clk_change_rate()
2335 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2338 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2339 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2342 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2345 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2347 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2348 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2350 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2352 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2354 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2355 clk_core_disable_lock(core); in clk_change_rate()
2356 clk_core_unprepare(core); in clk_change_rate()
2359 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2362 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2363 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2365 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2366 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2372 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2374 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2380 if (core->new_child) in clk_change_rate()
2381 clk_change_rate(core->new_child); in clk_change_rate()
2383 clk_pm_runtime_put(core); in clk_change_rate()
2386 static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, in clk_core_req_round_rate_nolock() argument
2394 if (!core) in clk_core_req_round_rate_nolock()
2398 cnt = clk_core_rate_nuke_protect(core); in clk_core_req_round_rate_nolock()
2402 clk_core_init_rate_req(core, &req, req_rate); in clk_core_req_round_rate_nolock()
2406 ret = clk_core_round_rate_nolock(core, &req); in clk_core_req_round_rate_nolock()
2411 clk_core_rate_restore_protect(core, cnt); in clk_core_req_round_rate_nolock()
2416 static int clk_core_set_rate_nolock(struct clk_core *core, in clk_core_set_rate_nolock() argument
2423 if (!core) in clk_core_set_rate_nolock()
2426 rate = clk_core_req_round_rate_nolock(core, req_rate); in clk_core_set_rate_nolock()
2429 if (rate == clk_core_get_rate_nolock(core)) in clk_core_set_rate_nolock()
2433 if (clk_core_rate_is_protected(core)) in clk_core_set_rate_nolock()
2437 top = clk_calc_new_rates(core, req_rate); in clk_core_set_rate_nolock()
2441 ret = clk_pm_runtime_get(core); in clk_core_set_rate_nolock()
2458 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2460 clk_pm_runtime_put(core); in clk_core_set_rate_nolock()
2497 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2499 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2502 clk_core_rate_protect(clk->core); in clk_set_rate()
2545 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2547 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2569 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2573 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2579 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2587 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2592 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2593 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2594 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2614 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2623 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2665 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2683 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2704 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2711 static struct clk_core *__clk_init_parent(struct clk_core *core) in __clk_init_parent() argument
2715 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2716 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2718 return clk_core_get_parent_by_index(core, index); in __clk_init_parent()
2721 static void clk_core_reparent(struct clk_core *core, in clk_core_reparent() argument
2724 clk_reparent(core, new_parent); in clk_core_reparent()
2725 __clk_recalc_accuracies(core); in clk_core_reparent()
2726 __clk_recalc_rates(core, true, POST_RATE_CHANGE); in clk_core_reparent()
2734 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2753 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2757 static int clk_core_set_parent_nolock(struct clk_core *core, in clk_core_set_parent_nolock() argument
2766 if (!core) in clk_core_set_parent_nolock()
2769 if (core->parent == parent) in clk_core_set_parent_nolock()
2773 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2777 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2780 if (clk_core_rate_is_protected(core)) in clk_core_set_parent_nolock()
2785 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2788 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2794 ret = clk_pm_runtime_get(core); in clk_core_set_parent_nolock()
2799 ret = __clk_speculate_rates(core, p_rate); in clk_core_set_parent_nolock()
2806 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2810 __clk_recalc_rates(core, true, ABORT_RATE_CHANGE); in clk_core_set_parent_nolock()
2812 __clk_recalc_rates(core, true, POST_RATE_CHANGE); in clk_core_set_parent_nolock()
2813 __clk_recalc_accuracies(core); in clk_core_set_parent_nolock()
2817 clk_pm_runtime_put(core); in clk_core_set_parent_nolock()
2824 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2855 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2857 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2858 parent ? parent->core : NULL); in clk_set_parent()
2861 clk_core_rate_protect(clk->core); in clk_set_parent()
2869 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) in clk_core_set_phase_nolock() argument
2875 if (!core) in clk_core_set_phase_nolock()
2878 if (clk_core_rate_is_protected(core)) in clk_core_set_phase_nolock()
2881 trace_clk_set_phase(core, degrees); in clk_core_set_phase_nolock()
2883 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2884 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2886 core->phase = degrees; in clk_core_set_phase_nolock()
2889 trace_clk_set_phase_complete(core, degrees); in clk_core_set_phase_nolock()
2929 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2931 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2934 clk_core_rate_protect(clk->core); in clk_set_phase()
2942 static int clk_core_get_phase(struct clk_core *core) in clk_core_get_phase() argument
2947 if (!core->ops->get_phase) in clk_core_get_phase()
2951 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
2953 core->phase = ret; in clk_core_get_phase()
2973 ret = clk_core_get_phase(clk->core); in clk_get_phase()
2980 static void clk_core_reset_duty_cycle_nolock(struct clk_core *core) in clk_core_reset_duty_cycle_nolock() argument
2983 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2984 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2987 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core);
2989 static int clk_core_update_duty_cycle_nolock(struct clk_core *core) in clk_core_update_duty_cycle_nolock() argument
2991 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2994 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2995 return clk_core_update_duty_cycle_parent_nolock(core); in clk_core_update_duty_cycle_nolock()
2997 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
3010 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_nolock()
3014 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core) in clk_core_update_duty_cycle_parent_nolock() argument
3018 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
3019 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
3020 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
3021 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
3023 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_parent_nolock()
3029 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core,
3032 static int clk_core_set_duty_cycle_nolock(struct clk_core *core, in clk_core_set_duty_cycle_nolock() argument
3039 if (clk_core_rate_is_protected(core)) in clk_core_set_duty_cycle_nolock()
3042 trace_clk_set_duty_cycle(core, duty); in clk_core_set_duty_cycle_nolock()
3044 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3045 return clk_core_set_duty_cycle_parent_nolock(core, duty); in clk_core_set_duty_cycle_nolock()
3047 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3049 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3051 trace_clk_set_duty_cycle_complete(core, duty); in clk_core_set_duty_cycle_nolock()
3056 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core, in clk_core_set_duty_cycle_parent_nolock() argument
3061 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3062 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3063 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3064 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3099 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3101 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3104 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3112 static int clk_core_get_scaled_duty_cycle(struct clk_core *core, in clk_core_get_scaled_duty_cycle() argument
3115 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3120 ret = clk_core_update_duty_cycle_nolock(core); in clk_core_get_scaled_duty_cycle()
3142 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3165 if (p->core == q->core) in clk_is_match()
3320 struct clk_core *core = data; in clk_rate_set() local
3324 ret = clk_core_set_rate_nolock(core, val); in clk_rate_set()
3334 struct clk_core *core = data; in clk_prepare_enable_set() local
3338 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3340 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3347 struct clk_core *core = data; in clk_prepare_enable_get() local
3349 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3363 struct clk_core *core = data; in clk_rate_get() local
3366 *val = clk_core_get_rate_recalc(core); in clk_rate_get()
3396 struct clk_core *core = s->private; in clk_flags_show() local
3397 unsigned long flags = core->flags; in clk_flags_show()
3415 static void possible_parent_show(struct seq_file *s, struct clk_core *core, in possible_parent_show() argument
3433 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3436 } else if (core->parents[i].name) { in possible_parent_show()
3437 seq_puts(s, core->parents[i].name); in possible_parent_show()
3438 } else if (core->parents[i].fw_name) { in possible_parent_show()
3439 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3441 if (core->parents[i].index >= 0) in possible_parent_show()
3442 name = of_clk_get_parent_name(core->of_node, core->parents[i].index); in possible_parent_show()
3454 struct clk_core *core = s->private; in possible_parents_show() local
3457 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3458 possible_parent_show(s, core, i, ' '); in possible_parents_show()
3460 possible_parent_show(s, core, i, '\n'); in possible_parents_show()
3468 struct clk_core *core = s->private; in current_parent_show() local
3470 if (core->parent) in current_parent_show()
3471 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3482 struct clk_core *core = s->private; in current_parent_write() local
3491 parent = clk_core_get_parent_by_index(core, idx); in current_parent_write()
3496 err = clk_core_set_parent_nolock(core, parent); in current_parent_write()
3515 struct clk_core *core = s->private; in clk_duty_cycle_show() local
3516 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3526 struct clk_core *core = s->private; in clk_min_rate_show() local
3530 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_min_rate_show()
3540 struct clk_core *core = s->private; in clk_max_rate_show() local
3544 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_max_rate_show()
3552 static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) in clk_debug_create_one() argument
3556 if (!core || !pdentry) in clk_debug_create_one()
3559 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3560 core->dentry = root; in clk_debug_create_one()
3562 debugfs_create_file("clk_rate", clk_rate_mode, root, core, in clk_debug_create_one()
3564 debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops); in clk_debug_create_one()
3565 debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops); in clk_debug_create_one()
3566 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3567 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3568 debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops); in clk_debug_create_one()
3569 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3570 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3571 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3572 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3573 debugfs_create_file("clk_duty_cycle", 0444, root, core, in clk_debug_create_one()
3576 debugfs_create_file("clk_prepare_enable", 0644, root, core, in clk_debug_create_one()
3579 if (core->num_parents > 1) in clk_debug_create_one()
3580 debugfs_create_file("clk_parent", 0644, root, core, in clk_debug_create_one()
3584 if (core->num_parents > 0) in clk_debug_create_one()
3585 debugfs_create_file("clk_parent", 0444, root, core, in clk_debug_create_one()
3588 if (core->num_parents > 1) in clk_debug_create_one()
3589 debugfs_create_file("clk_possible_parents", 0444, root, core, in clk_debug_create_one()
3592 if (core->ops->debug_init) in clk_debug_create_one()
3593 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3604 static void clk_debug_register(struct clk_core *core) in clk_debug_register() argument
3607 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3609 clk_debug_create_one(core, rootdir); in clk_debug_register()
3621 static void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3624 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3625 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3626 core->dentry = NULL; in clk_debug_unregister()
3641 struct clk_core *core; in clk_debug_init() local
3673 hlist_for_each_entry(core, &clk_debug_list, debug_node) in clk_debug_init()
3674 clk_debug_create_one(core, rootdir); in clk_debug_init()
3683 static inline void clk_debug_register(struct clk_core *core) { } in clk_debug_register() argument
3684 static inline void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3737 static int __clk_core_init(struct clk_core *core) in __clk_core_init() argument
3752 core->hw->core = core; in __clk_core_init()
3754 ret = clk_pm_runtime_get(core); in __clk_core_init()
3759 if (clk_core_lookup(core->name)) { in __clk_core_init()
3761 __func__, core->name); in __clk_core_init()
3767 if (core->ops->set_rate && in __clk_core_init()
3768 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3769 core->ops->recalc_rate)) { in __clk_core_init()
3771 __func__, core->name); in __clk_core_init()
3776 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3778 __func__, core->name); in __clk_core_init()
3783 if (core->ops->set_parent && !core->ops->determine_rate) { in __clk_core_init()
3785 __func__, core->name); in __clk_core_init()
3790 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3792 __func__, core->name); in __clk_core_init()
3797 if (core->ops->set_rate_and_parent && in __clk_core_init()
3798 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3800 __func__, core->name); in __clk_core_init()
3819 if (core->ops->init) { in __clk_core_init()
3820 ret = core->ops->init(core->hw); in __clk_core_init()
3825 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3838 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3839 core->orphan = parent->orphan; in __clk_core_init()
3840 } else if (!core->num_parents) { in __clk_core_init()
3841 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3842 core->orphan = false; in __clk_core_init()
3844 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3845 core->orphan = true; in __clk_core_init()
3855 if (core->ops->recalc_accuracy) in __clk_core_init()
3856 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3859 core->accuracy = parent->accuracy; in __clk_core_init()
3861 core->accuracy = 0; in __clk_core_init()
3868 phase = clk_core_get_phase(core); in __clk_core_init()
3872 core->name); in __clk_core_init()
3879 clk_core_update_duty_cycle_nolock(core); in __clk_core_init()
3887 if (core->ops->recalc_rate) in __clk_core_init()
3888 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3894 core->rate = core->req_rate = rate; in __clk_core_init()
3901 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3902 ret = clk_core_prepare(core); in __clk_core_init()
3905 __func__, core->name); in __clk_core_init()
3909 ret = clk_core_enable_lock(core); in __clk_core_init()
3912 __func__, core->name); in __clk_core_init()
3913 clk_core_unprepare(core); in __clk_core_init()
3920 kref_init(&core->ref); in __clk_core_init()
3922 clk_pm_runtime_put(core); in __clk_core_init()
3925 hlist_del_init(&core->child_node); in __clk_core_init()
3926 core->hw->core = NULL; in __clk_core_init()
3932 clk_debug_register(core); in __clk_core_init()
3942 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
3945 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3967 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk() argument
3976 clk->core = core; in alloc_clk()
4013 struct clk_core *core; in clk_hw_create_clk() local
4019 core = hw->core; in clk_hw_create_clk()
4020 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
4025 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
4030 kref_get(&core->ref); in clk_hw_create_clk()
4031 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
4048 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4072 static int clk_core_populate_parent_map(struct clk_core *core, in clk_core_populate_parent_map() argument
4090 core->parents = parents; in clk_core_populate_parent_map()
4101 __func__, core->name); in clk_core_populate_parent_map()
4134 static void clk_core_free_parent_map(struct clk_core *core) in clk_core_free_parent_map() argument
4136 int i = core->num_parents; in clk_core_free_parent_map()
4138 if (!core->num_parents) in clk_core_free_parent_map()
4142 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4143 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4146 kfree(core->parents); in clk_core_free_parent_map()
4153 struct clk_core *core; in __clk_register() local
4163 core = kzalloc(sizeof(*core), GFP_KERNEL); in __clk_register()
4164 if (!core) { in __clk_register()
4169 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4170 if (!core->name) { in __clk_register()
4179 core->ops = init->ops; in __clk_register()
4182 core->rpm_enabled = true; in __clk_register()
4183 core->dev = dev; in __clk_register()
4184 core->of_node = np; in __clk_register()
4186 core->owner = dev->driver->owner; in __clk_register()
4187 core->hw = hw; in __clk_register()
4188 core->flags = init->flags; in __clk_register()
4189 core->num_parents = init->num_parents; in __clk_register()
4190 core->min_rate = 0; in __clk_register()
4191 core->max_rate = ULONG_MAX; in __clk_register()
4193 ret = clk_core_populate_parent_map(core, init); in __clk_register()
4197 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4203 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4209 clk_core_link_consumer(core, hw->clk); in __clk_register()
4211 ret = __clk_core_init(core); in __clk_register()
4223 clk_core_free_parent_map(core); in __clk_register()
4226 kfree_const(core->name); in __clk_register()
4228 kfree(core); in __clk_register()
4311 struct clk_core *core = container_of(ref, struct clk_core, ref); in __clk_release() local
4315 clk_core_free_parent_map(core); in __clk_release()
4316 kfree_const(core->name); in __clk_release()
4317 kfree(core); in __clk_release()
4369 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4370 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4377 static void clk_core_evict_parent_cache(struct clk_core *core) in clk_core_evict_parent_cache() argument
4386 clk_core_evict_parent_cache_subtree(root, core); in clk_core_evict_parent_cache()
4402 clk_debug_unregister(clk->core); in clk_unregister()
4406 ops = clk->core->ops; in clk_unregister()
4409 clk->core->name); in clk_unregister()
4417 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4421 ops->terminate(clk->core->hw); in clk_unregister()
4423 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4428 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4433 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4435 hlist_del_init(&clk->core->child_node); in clk_unregister()
4437 if (clk->core->prepare_count) in clk_unregister()
4439 __func__, clk->core->name); in clk_unregister()
4441 if (clk->core->protect_count) in clk_unregister()
4443 __func__, clk->core->name); in clk_unregister()
4445 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4558 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4596 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4597 clk_core_rate_unprotect(clk->core); in __clk_put()
4607 owner = clk->core->owner; in __clk_put()
4608 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4667 clk->core->notifier_count++; in clk_notifier_register()
4701 clk->core->notifier_count--; in clk_notifier_unregister()