Lines Matching full:core

60 	struct clk_core		*core;  member
110 struct clk_core *core; member
121 static int clk_pm_runtime_get(struct clk_core *core) in clk_pm_runtime_get() argument
123 if (!core->rpm_enabled) in clk_pm_runtime_get()
126 return pm_runtime_resume_and_get(core->dev); in clk_pm_runtime_get()
129 static void clk_pm_runtime_put(struct clk_core *core) in clk_pm_runtime_put() argument
131 if (!core->rpm_enabled) in clk_pm_runtime_put()
134 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
155 struct clk_core *core, *failed; in clk_pm_runtime_get_all() local
168 hlist_for_each_entry(core, &clk_rpm_list, rpm_node) { in clk_pm_runtime_get_all()
169 ret = clk_pm_runtime_get(core); in clk_pm_runtime_get_all()
171 failed = core; in clk_pm_runtime_get_all()
181 hlist_for_each_entry(core, &clk_rpm_list, rpm_node) { in clk_pm_runtime_get_all()
182 if (core == failed) in clk_pm_runtime_get_all()
185 clk_pm_runtime_put(core); in clk_pm_runtime_get_all()
200 struct clk_core *core; in clk_pm_runtime_put_all() local
202 hlist_for_each_entry(core, &clk_rpm_list, rpm_node) in clk_pm_runtime_put_all()
203 clk_pm_runtime_put(core); in clk_pm_runtime_put_all()
207 static void clk_pm_runtime_init(struct clk_core *core) in clk_pm_runtime_init() argument
209 struct device *dev = core->dev; in clk_pm_runtime_init()
212 core->rpm_enabled = true; in clk_pm_runtime_init()
215 hlist_add_head(&core->rpm_node, &clk_rpm_list); in clk_pm_runtime_init()
289 static bool clk_core_rate_is_protected(struct clk_core *core) in clk_core_rate_is_protected() argument
291 return core->protect_count; in clk_core_rate_is_protected()
294 static bool clk_core_is_prepared(struct clk_core *core) in clk_core_is_prepared() argument
302 if (!core->ops->is_prepared) in clk_core_is_prepared()
303 return core->prepare_count; in clk_core_is_prepared()
305 if (!clk_pm_runtime_get(core)) { in clk_core_is_prepared()
306 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
307 clk_pm_runtime_put(core); in clk_core_is_prepared()
313 static bool clk_core_is_enabled(struct clk_core *core) in clk_core_is_enabled() argument
321 if (!core->ops->is_enabled) in clk_core_is_enabled()
322 return core->enable_count; in clk_core_is_enabled()
334 if (core->rpm_enabled) { in clk_core_is_enabled()
335 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
336 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
347 if ((core->flags & CLK_OPS_PARENT_ENABLE) && core->parent) in clk_core_is_enabled()
348 if (!clk_core_is_enabled(core->parent)) { in clk_core_is_enabled()
353 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
355 if (core->rpm_enabled) in clk_core_is_enabled()
356 pm_runtime_put(core->dev); in clk_core_is_enabled()
365 return !clk ? NULL : clk->core->name; in __clk_get_name()
371 return hw->core->name; in clk_hw_get_name()
377 return hw->core->dev; in clk_hw_get_dev()
383 return hw->core->of_node; in clk_hw_get_of_node()
389 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
395 return hw->core->num_parents; in clk_hw_get_num_parents()
401 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
407 struct clk_core *core; in clk_core_lookup() local
416 hash_for_each_possible(clk_hashtable, core, hashtable_node, hash) in clk_core_lookup()
417 if (!strcmp(core->name, name)) in clk_core_lookup()
418 return core; in clk_core_lookup()
444 * @core: clk to find parent of
478 static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index) in clk_core_get() argument
480 const char *name = core->parents[p_index].fw_name; in clk_core_get()
481 int index = core->parents[p_index].index; in clk_core_get()
483 struct device *dev = core->dev; in clk_core_get()
485 struct device_node *np = core->of_node; in clk_core_get()
506 return hw->core; in clk_core_get()
509 static void clk_core_fill_parent_index(struct clk_core *core, u8 index) in clk_core_fill_parent_index() argument
511 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
515 parent = entry->hw->core; in clk_core_fill_parent_index()
517 parent = clk_core_get(core, index); in clk_core_fill_parent_index()
532 entry->core = parent; in clk_core_fill_parent_index()
535 static struct clk_core *clk_core_get_parent_by_index(struct clk_core *core, in clk_core_get_parent_by_index() argument
538 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
541 if (!core->parents[index].core) in clk_core_get_parent_by_index()
542 clk_core_fill_parent_index(core, index); in clk_core_get_parent_by_index()
544 return core->parents[index].core; in clk_core_get_parent_by_index()
552 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
560 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
563 static unsigned long clk_core_get_rate_nolock(struct clk_core *core) in clk_core_get_rate_nolock() argument
565 if (!core) in clk_core_get_rate_nolock()
568 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
569 return core->rate; in clk_core_get_rate_nolock()
581 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
585 static unsigned long clk_core_get_accuracy_no_lock(struct clk_core *core) in clk_core_get_accuracy_no_lock() argument
587 if (!core) in clk_core_get_accuracy_no_lock()
590 return core->accuracy; in clk_core_get_accuracy_no_lock()
595 return hw->core->flags; in clk_hw_get_flags()
601 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
607 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
616 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
629 static void clk_core_init_rate_req(struct clk_core * const core,
633 static int clk_core_round_rate_nolock(struct clk_core *core,
636 static bool clk_core_has_parent(struct clk_core *core, const struct clk_core *parent) in clk_core_has_parent() argument
642 if (core->parent == parent) in clk_core_has_parent()
645 for (i = 0; i < core->num_parents; i++) { in clk_core_has_parent()
646 tmp = clk_core_get_parent_by_index(core, i); in clk_core_has_parent()
658 clk_core_forward_rate_req(struct clk_core *core, in clk_core_forward_rate_req() argument
664 if (WARN_ON(!clk_core_has_parent(core, parent))) in clk_core_forward_rate_req()
680 struct clk_core *core = hw->core; in clk_core_determine_rate_no_reparent() local
681 struct clk_core *parent = core->parent; in clk_core_determine_rate_no_reparent()
685 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_determine_rate_no_reparent()
693 clk_core_forward_rate_req(core, req, parent, &parent_req, in clk_core_determine_rate_no_reparent()
708 best = clk_core_get_rate_nolock(core); in clk_core_determine_rate_no_reparent()
721 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
726 if (core->flags & CLK_SET_RATE_NO_REPARENT) in clk_mux_determine_rate_flags()
730 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
734 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
738 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
741 clk_core_forward_rate_req(core, req, parent, &parent_req, req->rate); in clk_mux_determine_rate_flags()
776 struct clk_core *core = clk_core_lookup(name); in __clk_lookup() local
778 return !core ? NULL : core->hw->clk; in __clk_lookup()
781 static void clk_core_get_boundaries(struct clk_core *core, in clk_core_get_boundaries() argument
789 *min_rate = core->min_rate; in clk_core_get_boundaries()
790 *max_rate = core->max_rate; in clk_core_get_boundaries()
792 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
795 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
811 clk_core_get_boundaries(hw->core, min_rate, max_rate); in clk_hw_get_rate_range()
815 static bool clk_core_check_boundaries(struct clk_core *core, in clk_core_check_boundaries() argument
823 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
826 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
836 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
837 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
887 static void clk_core_rate_unprotect(struct clk_core *core) in clk_core_rate_unprotect() argument
891 if (!core) in clk_core_rate_unprotect()
894 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
895 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
898 if (--core->protect_count > 0) in clk_core_rate_unprotect()
901 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
904 static int clk_core_rate_nuke_protect(struct clk_core *core) in clk_core_rate_nuke_protect() argument
910 if (!core) in clk_core_rate_nuke_protect()
913 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
916 ret = core->protect_count; in clk_core_rate_nuke_protect()
917 core->protect_count = 1; in clk_core_rate_nuke_protect()
918 clk_core_rate_unprotect(core); in clk_core_rate_nuke_protect()
955 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
962 static void clk_core_rate_protect(struct clk_core *core) in clk_core_rate_protect() argument
966 if (!core) in clk_core_rate_protect()
969 if (core->protect_count == 0) in clk_core_rate_protect()
970 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
972 core->protect_count++; in clk_core_rate_protect()
975 static void clk_core_rate_restore_protect(struct clk_core *core, int count) in clk_core_rate_restore_protect() argument
979 if (!core) in clk_core_rate_restore_protect()
985 clk_core_rate_protect(core); in clk_core_rate_restore_protect()
986 core->protect_count = count; in clk_core_rate_restore_protect()
1013 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
1040 static void clk_core_unprepare(struct clk_core *core) in clk_core_unprepare() argument
1044 if (!core) in clk_core_unprepare()
1047 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
1048 "%s already unprepared\n", core->name)) in clk_core_unprepare()
1051 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
1052 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
1055 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
1056 clk_core_rate_unprotect(core); in clk_core_unprepare()
1058 if (--core->prepare_count > 0) in clk_core_unprepare()
1061 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
1063 trace_clk_unprepare(core); in clk_core_unprepare()
1065 if (core->ops->unprepare) in clk_core_unprepare()
1066 core->ops->unprepare(core->hw); in clk_core_unprepare()
1068 trace_clk_unprepare_complete(core); in clk_core_unprepare()
1069 clk_core_unprepare(core->parent); in clk_core_unprepare()
1070 clk_pm_runtime_put(core); in clk_core_unprepare()
1073 static void clk_core_unprepare_lock(struct clk_core *core) in clk_core_unprepare_lock() argument
1076 clk_core_unprepare(core); in clk_core_unprepare_lock()
1096 clk_core_unprepare_lock(clk->core); in clk_unprepare()
1100 static int clk_core_prepare(struct clk_core *core) in clk_core_prepare() argument
1106 if (!core) in clk_core_prepare()
1109 if (core->prepare_count == 0) { in clk_core_prepare()
1110 ret = clk_pm_runtime_get(core); in clk_core_prepare()
1114 ret = clk_core_prepare(core->parent); in clk_core_prepare()
1118 trace_clk_prepare(core); in clk_core_prepare()
1120 if (core->ops->prepare) in clk_core_prepare()
1121 ret = core->ops->prepare(core->hw); in clk_core_prepare()
1123 trace_clk_prepare_complete(core); in clk_core_prepare()
1129 core->prepare_count++; in clk_core_prepare()
1138 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
1139 clk_core_rate_protect(core); in clk_core_prepare()
1143 clk_core_unprepare(core->parent); in clk_core_prepare()
1145 clk_pm_runtime_put(core); in clk_core_prepare()
1149 static int clk_core_prepare_lock(struct clk_core *core) in clk_core_prepare_lock() argument
1154 ret = clk_core_prepare(core); in clk_core_prepare_lock()
1177 return clk_core_prepare_lock(clk->core); in clk_prepare()
1181 static void clk_core_disable(struct clk_core *core) in clk_core_disable() argument
1185 if (!core) in clk_core_disable()
1188 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
1191 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
1192 "Disabling critical %s\n", core->name)) in clk_core_disable()
1195 if (--core->enable_count > 0) in clk_core_disable()
1198 trace_clk_disable(core); in clk_core_disable()
1200 if (core->ops->disable) in clk_core_disable()
1201 core->ops->disable(core->hw); in clk_core_disable()
1203 trace_clk_disable_complete(core); in clk_core_disable()
1205 clk_core_disable(core->parent); in clk_core_disable()
1208 static void clk_core_disable_lock(struct clk_core *core) in clk_core_disable_lock() argument
1213 clk_core_disable(core); in clk_core_disable_lock()
1234 clk_core_disable_lock(clk->core); in clk_disable()
1238 static int clk_core_enable(struct clk_core *core) in clk_core_enable() argument
1244 if (!core) in clk_core_enable()
1247 if (WARN(core->prepare_count == 0, in clk_core_enable()
1248 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1251 if (core->enable_count == 0) { in clk_core_enable()
1252 ret = clk_core_enable(core->parent); in clk_core_enable()
1257 trace_clk_enable(core); in clk_core_enable()
1259 if (core->ops->enable) in clk_core_enable()
1260 ret = core->ops->enable(core->hw); in clk_core_enable()
1262 trace_clk_enable_complete(core); in clk_core_enable()
1265 clk_core_disable(core->parent); in clk_core_enable()
1270 core->enable_count++; in clk_core_enable()
1274 static int clk_core_enable_lock(struct clk_core *core) in clk_core_enable_lock() argument
1280 ret = clk_core_enable(core); in clk_core_enable_lock()
1298 struct clk_core *core = hw->core; in clk_gate_restore_context() local
1300 if (core->enable_count) in clk_gate_restore_context()
1301 core->ops->enable(hw); in clk_gate_restore_context()
1303 core->ops->disable(hw); in clk_gate_restore_context()
1307 static int clk_core_save_context(struct clk_core *core) in clk_core_save_context() argument
1312 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1318 if (core->ops && core->ops->save_context) in clk_core_save_context()
1319 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1324 static void clk_core_restore_context(struct clk_core *core) in clk_core_restore_context() argument
1328 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1329 core->ops->restore_context(core->hw); in clk_core_restore_context()
1331 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1371 struct clk_core *core; in clk_restore_context() local
1373 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_restore_context()
1374 clk_core_restore_context(core); in clk_restore_context()
1376 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_restore_context()
1377 clk_core_restore_context(core); in clk_restore_context()
1399 return clk_core_enable_lock(clk->core); in clk_enable()
1420 return clk && !(clk->core->ops->enable && clk->core->ops->disable); in clk_is_enabled_when_prepared()
1424 static int clk_core_prepare_enable(struct clk_core *core) in clk_core_prepare_enable() argument
1428 ret = clk_core_prepare_lock(core); in clk_core_prepare_enable()
1432 ret = clk_core_enable_lock(core); in clk_core_prepare_enable()
1434 clk_core_unprepare_lock(core); in clk_core_prepare_enable()
1439 static void clk_core_disable_unprepare(struct clk_core *core) in clk_core_disable_unprepare() argument
1441 clk_core_disable_lock(core); in clk_core_disable_unprepare()
1442 clk_core_unprepare_lock(core); in clk_core_disable_unprepare()
1445 static void __init clk_unprepare_unused_subtree(struct clk_core *core) in clk_unprepare_unused_subtree() argument
1451 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1454 if (core->prepare_count) in clk_unprepare_unused_subtree()
1457 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1460 if (clk_core_is_prepared(core)) { in clk_unprepare_unused_subtree()
1461 trace_clk_unprepare(core); in clk_unprepare_unused_subtree()
1462 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1463 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1464 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1465 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1466 trace_clk_unprepare_complete(core); in clk_unprepare_unused_subtree()
1470 static void __init clk_disable_unused_subtree(struct clk_core *core) in clk_disable_unused_subtree() argument
1477 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1480 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1481 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1485 if (core->enable_count) in clk_disable_unused_subtree()
1488 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1496 if (clk_core_is_enabled(core)) { in clk_disable_unused_subtree()
1497 trace_clk_disable(core); in clk_disable_unused_subtree()
1498 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1499 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1500 else if (core->ops->disable) in clk_disable_unused_subtree()
1501 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1502 trace_clk_disable_complete(core); in clk_disable_unused_subtree()
1507 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1508 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1521 struct clk_core *core; in clk_disable_unused() local
1540 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1541 clk_disable_unused_subtree(core); in clk_disable_unused()
1543 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1544 clk_disable_unused_subtree(core); in clk_disable_unused()
1546 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1547 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1549 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1550 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1560 static int clk_core_determine_round_nolock(struct clk_core *core, in clk_core_determine_round_nolock() argument
1567 if (!core) in clk_core_determine_round_nolock()
1580 __func__, core->name); in clk_core_determine_round_nolock()
1585 * At this point, core protection will be disabled in clk_core_determine_round_nolock()
1590 if (clk_core_rate_is_protected(core)) { in clk_core_determine_round_nolock()
1591 req->rate = core->rate; in clk_core_determine_round_nolock()
1592 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1593 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1594 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1595 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1608 static void clk_core_init_rate_req(struct clk_core * const core, in clk_core_init_rate_req() argument
1620 if (!core) in clk_core_init_rate_req()
1623 req->core = core; in clk_core_init_rate_req()
1625 clk_core_get_boundaries(core, &req->min_rate, &req->max_rate); in clk_core_init_rate_req()
1627 parent = core->parent; in clk_core_init_rate_req()
1653 clk_core_init_rate_req(hw->core, req, rate); in clk_hw_init_rate_request()
1677 clk_core_forward_rate_req(hw->core, old_req, in clk_hw_forward_rate_request()
1678 parent->core, req, in clk_hw_forward_rate_request()
1683 static bool clk_core_can_round(struct clk_core * const core) in clk_core_can_round() argument
1685 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1688 static int clk_core_round_rate_nolock(struct clk_core *core, in clk_core_round_rate_nolock() argument
1695 if (!core) { in clk_core_round_rate_nolock()
1700 if (clk_core_can_round(core)) in clk_core_round_rate_nolock()
1701 return clk_core_determine_round_nolock(core, req); in clk_core_round_rate_nolock()
1703 if (core->flags & CLK_SET_RATE_PARENT) { in clk_core_round_rate_nolock()
1706 clk_core_forward_rate_req(core, req, core->parent, &parent_req, req->rate); in clk_core_round_rate_nolock()
1710 ret = clk_core_round_rate_nolock(core->parent, &parent_req); in clk_core_round_rate_nolock()
1722 req->rate = core->rate; in clk_core_round_rate_nolock()
1740 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1764 clk_core_init_rate_req(hw->core, &req, rate); in clk_hw_round_rate()
1768 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1798 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1800 clk_core_init_rate_req(clk->core, &req, rate); in clk_round_rate()
1804 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1809 clk_core_rate_protect(clk->core); in clk_round_rate()
1822 * @core: clk that is changing rate
1834 static int __clk_notify(struct clk_core *core, unsigned long msg, in __clk_notify() argument
1845 if (cn->clk->core == core) { in __clk_notify()
1859 * @core: first clk in the subtree
1866 static void __clk_recalc_accuracies(struct clk_core *core) in __clk_recalc_accuracies() argument
1873 if (core->parent) in __clk_recalc_accuracies()
1874 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1876 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1877 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1880 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1882 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1886 static long clk_core_get_accuracy_recalc(struct clk_core *core) in clk_core_get_accuracy_recalc() argument
1888 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1889 __clk_recalc_accuracies(core); in clk_core_get_accuracy_recalc()
1891 return clk_core_get_accuracy_no_lock(core); in clk_core_get_accuracy_recalc()
1911 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1918 static unsigned long clk_recalc(struct clk_core *core, in clk_recalc() argument
1923 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1924 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1925 clk_pm_runtime_put(core); in clk_recalc()
1932 * @core: first clk in the subtree
1943 static void __clk_recalc_rates(struct clk_core *core, bool update_req, in __clk_recalc_rates() argument
1952 old_rate = core->rate; in __clk_recalc_rates()
1954 if (core->parent) in __clk_recalc_rates()
1955 parent_rate = core->parent->rate; in __clk_recalc_rates()
1957 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1959 core->req_rate = core->rate; in __clk_recalc_rates()
1965 if (core->notifier_count && msg) in __clk_recalc_rates()
1966 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1968 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1972 static unsigned long clk_core_get_rate_recalc(struct clk_core *core) in clk_core_get_rate_recalc() argument
1974 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1975 __clk_recalc_rates(core, false, 0); in clk_core_get_rate_recalc()
1977 return clk_core_get_rate_nolock(core); in clk_core_get_rate_recalc()
1997 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
2004 static int clk_fetch_parent_index(struct clk_core *core, in clk_fetch_parent_index() argument
2012 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
2014 if (core->parents[i].core == parent) in clk_fetch_parent_index()
2018 if (core->parents[i].core) in clk_fetch_parent_index()
2021 /* Maybe core hasn't been cached but the hw is all we know? */ in clk_fetch_parent_index()
2022 if (core->parents[i].hw) { in clk_fetch_parent_index()
2023 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
2031 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
2035 if (core->parents[i].name && in clk_fetch_parent_index()
2036 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
2040 if (i == core->num_parents) in clk_fetch_parent_index()
2043 core->parents[i].core = parent; in clk_fetch_parent_index()
2061 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
2066 * Update the orphan status of @core and all its children.
2068 static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan) in clk_core_update_orphan_status() argument
2072 core->orphan = is_orphan; in clk_core_update_orphan_status()
2074 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
2078 static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) in clk_reparent() argument
2080 bool was_orphan = core->orphan; in clk_reparent()
2082 hlist_del(&core->child_node); in clk_reparent()
2088 if (new_parent->new_child == core) in clk_reparent()
2091 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
2094 clk_core_update_orphan_status(core, becomes_orphan); in clk_reparent()
2096 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
2098 clk_core_update_orphan_status(core, true); in clk_reparent()
2101 core->parent = new_parent; in clk_reparent()
2104 static struct clk_core *__clk_set_parent_before(struct clk_core *core, in __clk_set_parent_before() argument
2108 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
2131 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
2137 if (core->prepare_count) { in __clk_set_parent_before()
2139 clk_core_enable_lock(core); in __clk_set_parent_before()
2144 clk_reparent(core, parent); in __clk_set_parent_before()
2150 static void __clk_set_parent_after(struct clk_core *core, in __clk_set_parent_after() argument
2158 if (core->prepare_count) { in __clk_set_parent_after()
2159 clk_core_disable_lock(core); in __clk_set_parent_after()
2164 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
2170 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
2177 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
2179 trace_clk_set_parent(core, parent); in __clk_set_parent()
2182 if (parent && core->ops->set_parent) in __clk_set_parent()
2183 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
2185 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
2189 clk_reparent(core, old_parent); in __clk_set_parent()
2192 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
2197 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
2204 * @core: first clk in the subtree
2216 static int __clk_speculate_rates(struct clk_core *core, in __clk_speculate_rates() argument
2225 new_rate = clk_recalc(core, parent_rate); in __clk_speculate_rates()
2228 if (core->notifier_count) in __clk_speculate_rates()
2229 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
2233 __func__, core->name, ret); in __clk_speculate_rates()
2237 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
2247 static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, in clk_calc_subtree() argument
2252 core->new_rate = new_rate; in clk_calc_subtree()
2253 core->new_parent = new_parent; in clk_calc_subtree()
2254 core->new_parent_index = p_index; in clk_calc_subtree()
2256 core->new_child = NULL; in clk_calc_subtree()
2257 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
2258 new_parent->new_child = core; in clk_calc_subtree()
2260 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
2270 static struct clk_core *clk_calc_new_rates(struct clk_core *core, in clk_calc_new_rates() argument
2273 struct clk_core *top = core; in clk_calc_new_rates()
2283 if (IS_ERR_OR_NULL(core)) in clk_calc_new_rates()
2287 parent = old_parent = core->parent; in clk_calc_new_rates()
2291 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_calc_new_rates()
2294 if (clk_core_can_round(core)) { in clk_calc_new_rates()
2297 clk_core_init_rate_req(core, &req, rate); in clk_calc_new_rates()
2301 ret = clk_core_determine_round_nolock(core, &req); in clk_calc_new_rates()
2309 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2313 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2315 core->new_rate = core->rate; in clk_calc_new_rates()
2326 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2328 __func__, core->name); in clk_calc_new_rates()
2333 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2334 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
2337 __func__, parent->name, core->name); in clk_calc_new_rates()
2342 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2347 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
2357 static struct clk_core *clk_propagate_rate_change(struct clk_core *core, in clk_propagate_rate_change() argument
2363 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2366 if (core->notifier_count) { in clk_propagate_rate_change()
2367 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2369 fail_clk = core; in clk_propagate_rate_change()
2372 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2374 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2381 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2382 if (core->new_child) { in clk_propagate_rate_change()
2383 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2395 static void clk_change_rate(struct clk_core *core) in clk_change_rate() argument
2405 old_rate = core->rate; in clk_change_rate()
2407 if (core->new_parent) { in clk_change_rate()
2408 parent = core->new_parent; in clk_change_rate()
2409 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2410 } else if (core->parent) { in clk_change_rate()
2411 parent = core->parent; in clk_change_rate()
2412 best_parent_rate = core->parent->rate; in clk_change_rate()
2415 if (clk_pm_runtime_get(core)) in clk_change_rate()
2418 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2419 clk_core_prepare(core); in clk_change_rate()
2420 clk_core_enable_lock(core); in clk_change_rate()
2423 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2424 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2425 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2427 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2429 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2431 core->new_parent_index); in clk_change_rate()
2432 } else if (core->ops->set_parent) { in clk_change_rate()
2433 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2436 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2437 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2440 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2443 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2445 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2446 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2448 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2450 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2452 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2453 clk_core_disable_lock(core); in clk_change_rate()
2454 clk_core_unprepare(core); in clk_change_rate()
2457 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2460 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2461 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2463 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2464 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2470 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2472 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2477 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2478 if (core->new_child) in clk_change_rate()
2479 clk_change_rate(core->new_child); in clk_change_rate()
2481 clk_pm_runtime_put(core); in clk_change_rate()
2484 static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, in clk_core_req_round_rate_nolock() argument
2492 if (!core) in clk_core_req_round_rate_nolock()
2496 cnt = clk_core_rate_nuke_protect(core); in clk_core_req_round_rate_nolock()
2500 clk_core_init_rate_req(core, &req, req_rate); in clk_core_req_round_rate_nolock()
2504 ret = clk_core_round_rate_nolock(core, &req); in clk_core_req_round_rate_nolock()
2509 clk_core_rate_restore_protect(core, cnt); in clk_core_req_round_rate_nolock()
2514 static int clk_core_set_rate_nolock(struct clk_core *core, in clk_core_set_rate_nolock() argument
2521 if (!core) in clk_core_set_rate_nolock()
2524 rate = clk_core_req_round_rate_nolock(core, req_rate); in clk_core_set_rate_nolock()
2527 if (rate == clk_core_get_rate_nolock(core)) in clk_core_set_rate_nolock()
2531 if (clk_core_rate_is_protected(core)) in clk_core_set_rate_nolock()
2535 top = clk_calc_new_rates(core, req_rate); in clk_core_set_rate_nolock()
2539 ret = clk_pm_runtime_get(core); in clk_core_set_rate_nolock()
2556 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2558 clk_pm_runtime_put(core); in clk_core_set_rate_nolock()
2595 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2597 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2600 clk_core_rate_protect(clk->core); in clk_set_rate()
2643 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2645 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2667 trace_clk_set_rate_range(clk->core, min, max); in clk_set_rate_range_nolock()
2671 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range_nolock()
2677 clk_core_rate_unprotect(clk->core); in clk_set_rate_range_nolock()
2685 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range_nolock()
2690 rate = clk->core->req_rate; in clk_set_rate_range_nolock()
2691 if (clk->core->flags & CLK_GET_RATE_NOCACHE) in clk_set_rate_range_nolock()
2692 rate = clk_core_get_rate_recalc(clk->core); in clk_set_rate_range_nolock()
2712 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range_nolock()
2721 clk_core_rate_protect(clk->core); in clk_set_rate_range_nolock()
2763 trace_clk_set_min_rate(clk->core, rate); in clk_set_min_rate()
2781 trace_clk_set_max_rate(clk->core, rate); in clk_set_max_rate()
2802 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2809 static struct clk_core *__clk_init_parent(struct clk_core *core) in __clk_init_parent() argument
2813 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2814 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2816 return clk_core_get_parent_by_index(core, index); in __clk_init_parent()
2819 static void clk_core_reparent(struct clk_core *core, in clk_core_reparent() argument
2822 clk_reparent(core, new_parent); in clk_core_reparent()
2823 __clk_recalc_accuracies(core); in clk_core_reparent()
2824 __clk_recalc_rates(core, true, POST_RATE_CHANGE); in clk_core_reparent()
2832 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2851 return clk_core_has_parent(clk->core, parent->core); in clk_has_parent()
2855 static int clk_core_set_parent_nolock(struct clk_core *core, in clk_core_set_parent_nolock() argument
2864 if (!core) in clk_core_set_parent_nolock()
2867 if (core->parent == parent) in clk_core_set_parent_nolock()
2871 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2875 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2878 if (clk_core_rate_is_protected(core)) in clk_core_set_parent_nolock()
2883 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2886 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2892 ret = clk_pm_runtime_get(core); in clk_core_set_parent_nolock()
2897 ret = __clk_speculate_rates(core, p_rate); in clk_core_set_parent_nolock()
2904 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2908 __clk_recalc_rates(core, true, ABORT_RATE_CHANGE); in clk_core_set_parent_nolock()
2910 __clk_recalc_rates(core, true, POST_RATE_CHANGE); in clk_core_set_parent_nolock()
2911 __clk_recalc_accuracies(core); in clk_core_set_parent_nolock()
2915 clk_pm_runtime_put(core); in clk_core_set_parent_nolock()
2922 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2953 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2955 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2956 parent ? parent->core : NULL); in clk_set_parent()
2959 clk_core_rate_protect(clk->core); in clk_set_parent()
2967 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) in clk_core_set_phase_nolock() argument
2973 if (!core) in clk_core_set_phase_nolock()
2976 if (clk_core_rate_is_protected(core)) in clk_core_set_phase_nolock()
2979 trace_clk_set_phase(core, degrees); in clk_core_set_phase_nolock()
2981 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2982 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2984 core->phase = degrees; in clk_core_set_phase_nolock()
2987 trace_clk_set_phase_complete(core, degrees); in clk_core_set_phase_nolock()
3027 clk_core_rate_unprotect(clk->core); in clk_set_phase()
3029 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
3032 clk_core_rate_protect(clk->core); in clk_set_phase()
3040 static int clk_core_get_phase(struct clk_core *core) in clk_core_get_phase() argument
3045 if (!core->ops->get_phase) in clk_core_get_phase()
3049 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
3051 core->phase = ret; in clk_core_get_phase()
3071 ret = clk_core_get_phase(clk->core); in clk_get_phase()
3078 static void clk_core_reset_duty_cycle_nolock(struct clk_core *core) in clk_core_reset_duty_cycle_nolock() argument
3081 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
3082 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
3085 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core);
3087 static int clk_core_update_duty_cycle_nolock(struct clk_core *core) in clk_core_update_duty_cycle_nolock() argument
3089 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
3092 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
3093 return clk_core_update_duty_cycle_parent_nolock(core); in clk_core_update_duty_cycle_nolock()
3095 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
3108 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_nolock()
3112 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core) in clk_core_update_duty_cycle_parent_nolock() argument
3116 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
3117 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
3118 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
3119 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
3121 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_parent_nolock()
3127 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core,
3130 static int clk_core_set_duty_cycle_nolock(struct clk_core *core, in clk_core_set_duty_cycle_nolock() argument
3137 if (clk_core_rate_is_protected(core)) in clk_core_set_duty_cycle_nolock()
3140 trace_clk_set_duty_cycle(core, duty); in clk_core_set_duty_cycle_nolock()
3142 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
3143 return clk_core_set_duty_cycle_parent_nolock(core, duty); in clk_core_set_duty_cycle_nolock()
3145 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
3147 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
3149 trace_clk_set_duty_cycle_complete(core, duty); in clk_core_set_duty_cycle_nolock()
3154 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core, in clk_core_set_duty_cycle_parent_nolock() argument
3159 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
3160 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
3161 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
3162 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
3197 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
3199 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
3202 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
3210 static int clk_core_get_scaled_duty_cycle(struct clk_core *core, in clk_core_get_scaled_duty_cycle() argument
3213 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
3218 ret = clk_core_update_duty_cycle_nolock(core); in clk_core_get_scaled_duty_cycle()
3240 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
3261 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
3263 if (p->core == q->core) in clk_is_match()
3442 struct clk_core *core = data; in clk_rate_set() local
3446 ret = clk_core_set_rate_nolock(core, val); in clk_rate_set()
3456 struct clk_core *core = data; in clk_phase_set() local
3461 ret = clk_core_set_phase_nolock(core, degrees); in clk_phase_set()
3471 struct clk_core *core = data; in clk_prepare_enable_set() local
3475 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3477 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3484 struct clk_core *core = data; in clk_prepare_enable_get() local
3486 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3503 struct clk_core *core = data; in clk_rate_get() local
3506 *val = clk_core_get_rate_recalc(core); in clk_rate_get()
3516 struct clk_core *core = data; in clk_phase_get() local
3518 *val = core->phase; in clk_phase_get()
3546 struct clk_core *core = s->private; in clk_flags_show() local
3547 unsigned long flags = core->flags; in clk_flags_show()
3565 static void possible_parent_show(struct seq_file *s, struct clk_core *core, in possible_parent_show() argument
3583 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3586 } else if (core->parents[i].name) { in possible_parent_show()
3587 seq_puts(s, core->parents[i].name); in possible_parent_show()
3588 } else if (core->parents[i].fw_name) { in possible_parent_show()
3589 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3591 if (core->parents[i].index >= 0) in possible_parent_show()
3592 name = of_clk_get_parent_name(core->of_node, core->parents[i].index); in possible_parent_show()
3604 struct clk_core *core = s->private; in possible_parents_show() local
3607 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3608 possible_parent_show(s, core, i, ' '); in possible_parents_show()
3610 possible_parent_show(s, core, i, '\n'); in possible_parents_show()
3618 struct clk_core *core = s->private; in current_parent_show() local
3620 if (core->parent) in current_parent_show()
3621 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3632 struct clk_core *core = s->private; in current_parent_write() local
3641 parent = clk_core_get_parent_by_index(core, idx); in current_parent_write()
3646 err = clk_core_set_parent_nolock(core, parent); in current_parent_write()
3665 struct clk_core *core = s->private; in clk_duty_cycle_show() local
3666 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3676 struct clk_core *core = s->private; in clk_min_rate_show() local
3680 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_min_rate_show()
3690 struct clk_core *core = s->private; in clk_max_rate_show() local
3694 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_max_rate_show()
3702 static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) in clk_debug_create_one() argument
3706 if (!core || !pdentry) in clk_debug_create_one()
3709 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3710 core->dentry = root; in clk_debug_create_one()
3712 debugfs_create_file("clk_rate", clk_rate_mode, root, core, in clk_debug_create_one()
3714 debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops); in clk_debug_create_one()
3715 debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops); in clk_debug_create_one()
3716 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3717 debugfs_create_file("clk_phase", clk_phase_mode, root, core, in clk_debug_create_one()
3719 debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops); in clk_debug_create_one()
3720 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3721 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3722 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3723 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3724 debugfs_create_file("clk_duty_cycle", 0444, root, core, in clk_debug_create_one()
3727 debugfs_create_file("clk_prepare_enable", 0644, root, core, in clk_debug_create_one()
3730 if (core->num_parents > 1) in clk_debug_create_one()
3731 debugfs_create_file("clk_parent", 0644, root, core, in clk_debug_create_one()
3735 if (core->num_parents > 0) in clk_debug_create_one()
3736 debugfs_create_file("clk_parent", 0444, root, core, in clk_debug_create_one()
3739 if (core->num_parents > 1) in clk_debug_create_one()
3740 debugfs_create_file("clk_possible_parents", 0444, root, core, in clk_debug_create_one()
3743 if (core->ops->debug_init) in clk_debug_create_one()
3744 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3749 * @core: the clk being added to the debugfs clk directory
3755 static void clk_debug_register(struct clk_core *core) in clk_debug_register() argument
3758 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3760 clk_debug_create_one(core, rootdir); in clk_debug_register()
3766 * @core: the clk being removed from the debugfs clk directory
3772 static void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3775 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3776 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3777 core->dentry = NULL; in clk_debug_unregister()
3792 struct clk_core *core; in clk_debug_init() local
3824 hlist_for_each_entry(core, &clk_debug_list, debug_node) in clk_debug_init()
3825 clk_debug_create_one(core, rootdir); in clk_debug_init()
3834 static inline void clk_debug_register(struct clk_core *core) { } in clk_debug_register() argument
3835 static inline void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3883 * @core: clk_core being initialized
3888 static int __clk_core_init(struct clk_core *core) in __clk_core_init() argument
3898 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3899 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3903 core->hw->core = core; in __clk_core_init()
3905 ret = clk_pm_runtime_get(core); in __clk_core_init()
3910 if (clk_core_lookup(core->name)) { in __clk_core_init()
3912 __func__, core->name); in __clk_core_init()
3918 if (core->ops->set_rate && in __clk_core_init()
3919 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3920 core->ops->recalc_rate)) { in __clk_core_init()
3922 __func__, core->name); in __clk_core_init()
3927 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3929 __func__, core->name); in __clk_core_init()
3934 if (core->ops->set_parent && !core->ops->determine_rate) { in __clk_core_init()
3936 __func__, core->name); in __clk_core_init()
3941 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3943 __func__, core->name); in __clk_core_init()
3948 if (core->ops->set_rate_and_parent && in __clk_core_init()
3949 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3951 __func__, core->name); in __clk_core_init()
3970 if (core->ops->init) { in __clk_core_init()
3971 ret = core->ops->init(core->hw); in __clk_core_init()
3976 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3979 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3989 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3990 core->orphan = parent->orphan; in __clk_core_init()
3991 } else if (!core->num_parents) { in __clk_core_init()
3992 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3993 core->orphan = false; in __clk_core_init()
3995 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3996 core->orphan = true; in __clk_core_init()
3998 hash_add(clk_hashtable, &core->hashtable_node, in __clk_core_init()
3999 full_name_hash(NULL, core->name, strlen(core->name))); in __clk_core_init()
4008 if (core->ops->recalc_accuracy) in __clk_core_init()
4009 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
4012 core->accuracy = parent->accuracy; in __clk_core_init()
4014 core->accuracy = 0; in __clk_core_init()
4021 phase = clk_core_get_phase(core); in __clk_core_init()
4025 core->name); in __clk_core_init()
4032 clk_core_update_duty_cycle_nolock(core); in __clk_core_init()
4040 if (core->ops->recalc_rate) in __clk_core_init()
4041 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
4047 core->rate = core->req_rate = rate; in __clk_core_init()
4054 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
4055 ret = clk_core_prepare(core); in __clk_core_init()
4058 __func__, core->name); in __clk_core_init()
4062 ret = clk_core_enable_lock(core); in __clk_core_init()
4065 __func__, core->name); in __clk_core_init()
4066 clk_core_unprepare(core); in __clk_core_init()
4073 clk_pm_runtime_put(core); in __clk_core_init()
4076 hash_del(&core->hashtable_node); in __clk_core_init()
4077 hlist_del_init(&core->child_node); in __clk_core_init()
4078 core->hw->core = NULL; in __clk_core_init()
4084 clk_debug_register(core); in __clk_core_init()
4091 * @core: clk to add consumer to
4094 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
4097 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
4113 * @core: clk to allocate a consumer for
4119 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk() argument
4128 clk->core = core; in alloc_clk()
4165 struct clk_core *core; in clk_hw_create_clk() local
4171 core = hw->core; in clk_hw_create_clk()
4172 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
4177 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
4182 kref_get(&core->ref); in clk_hw_create_clk()
4183 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
4200 struct device *dev = hw->core->dev; in clk_hw_get_clk()
4224 static int clk_core_populate_parent_map(struct clk_core *core, in clk_core_populate_parent_map() argument
4242 core->parents = parents; in clk_core_populate_parent_map()
4253 __func__, core->name); in clk_core_populate_parent_map()
4286 static void clk_core_free_parent_map(struct clk_core *core) in clk_core_free_parent_map() argument
4288 int i = core->num_parents; in clk_core_free_parent_map()
4290 if (!core->num_parents) in clk_core_free_parent_map()
4294 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
4295 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
4298 kfree(core->parents); in clk_core_free_parent_map()
4304 struct clk_core *core = container_of(ref, struct clk_core, ref); in __clk_release() local
4306 if (core->rpm_enabled) { in __clk_release()
4308 hlist_del(&core->rpm_node); in __clk_release()
4312 clk_core_free_parent_map(core); in __clk_release()
4313 kfree_const(core->name); in __clk_release()
4314 kfree(core); in __clk_release()
4321 struct clk_core *core; in __clk_register() local
4327 * we catch use of hw->init early on in the core. in __clk_register()
4331 core = kzalloc_obj(*core); in __clk_register()
4332 if (!core) { in __clk_register()
4337 kref_init(&core->ref); in __clk_register()
4339 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
4340 if (!core->name) { in __clk_register()
4349 core->ops = init->ops; in __clk_register()
4351 core->dev = dev; in __clk_register()
4352 clk_pm_runtime_init(core); in __clk_register()
4353 core->of_node = np; in __clk_register()
4355 core->owner = dev->driver->owner; in __clk_register()
4356 core->hw = hw; in __clk_register()
4357 core->flags = init->flags; in __clk_register()
4358 core->num_parents = init->num_parents; in __clk_register()
4359 core->min_rate = 0; in __clk_register()
4360 core->max_rate = ULONG_MAX; in __clk_register()
4362 ret = clk_core_populate_parent_map(core, init); in __clk_register()
4366 INIT_HLIST_HEAD(&core->clks); in __clk_register()
4372 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
4378 clk_core_link_consumer(core, hw->clk); in __clk_register()
4380 ret = __clk_core_init(core); in __clk_register()
4395 kref_put(&core->ref, __clk_release); in __clk_register()
4531 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4532 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4539 static void clk_core_evict_parent_cache(struct clk_core *core) in clk_core_evict_parent_cache() argument
4548 clk_core_evict_parent_cache_subtree(root, core); in clk_core_evict_parent_cache()
4564 clk_debug_unregister(clk->core); in clk_unregister()
4568 ops = clk->core->ops; in clk_unregister()
4571 clk->core->name); in clk_unregister()
4580 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4584 ops->terminate(clk->core->hw); in clk_unregister()
4586 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4591 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4596 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4598 hash_del(&clk->core->hashtable_node); in clk_unregister()
4599 hlist_del_init(&clk->core->child_node); in clk_unregister()
4601 if (clk->core->prepare_count) in clk_unregister()
4603 __func__, clk->core->name); in clk_unregister()
4605 if (clk->core->protect_count) in clk_unregister()
4607 __func__, clk->core->name); in clk_unregister()
4610 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4721 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4759 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4760 clk_core_rate_unprotect(clk->core); in __clk_put()
4772 owner = clk->core->owner; in __clk_put()
4773 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4828 clk->core->notifier_count++; in clk_notifier_register()
4862 clk->core->notifier_count--; in clk_notifier_unregister()