Lines Matching full:core

50 	struct clk_core		*core;  member
100 struct clk_core *core; member
111 static int clk_pm_runtime_get(struct clk_core *core) in clk_pm_runtime_get() argument
115 if (!core->rpm_enabled) in clk_pm_runtime_get()
118 ret = pm_runtime_get_sync(core->dev); in clk_pm_runtime_get()
120 pm_runtime_put_noidle(core->dev); in clk_pm_runtime_get()
126 static void clk_pm_runtime_put(struct clk_core *core) in clk_pm_runtime_put() argument
128 if (!core->rpm_enabled) in clk_pm_runtime_put()
131 pm_runtime_put_sync(core->dev); in clk_pm_runtime_put()
203 static bool clk_core_rate_is_protected(struct clk_core *core) in clk_core_rate_is_protected() argument
205 return core->protect_count; in clk_core_rate_is_protected()
208 static bool clk_core_is_prepared(struct clk_core *core) in clk_core_is_prepared() argument
216 if (!core->ops->is_prepared) in clk_core_is_prepared()
217 return core->prepare_count; in clk_core_is_prepared()
219 if (!clk_pm_runtime_get(core)) { in clk_core_is_prepared()
220 ret = core->ops->is_prepared(core->hw); in clk_core_is_prepared()
221 clk_pm_runtime_put(core); in clk_core_is_prepared()
227 static bool clk_core_is_enabled(struct clk_core *core) in clk_core_is_enabled() argument
235 if (!core->ops->is_enabled) in clk_core_is_enabled()
236 return core->enable_count; in clk_core_is_enabled()
248 if (core->rpm_enabled) { in clk_core_is_enabled()
249 pm_runtime_get_noresume(core->dev); in clk_core_is_enabled()
250 if (!pm_runtime_active(core->dev)) { in clk_core_is_enabled()
256 ret = core->ops->is_enabled(core->hw); in clk_core_is_enabled()
258 if (core->rpm_enabled) in clk_core_is_enabled()
259 pm_runtime_put(core->dev); in clk_core_is_enabled()
268 return !clk ? NULL : clk->core->name; in __clk_get_name()
274 return hw->core->name; in clk_hw_get_name()
280 return !clk ? NULL : clk->core->hw; in __clk_get_hw()
286 return hw->core->num_parents; in clk_hw_get_num_parents()
292 return hw->core->parent ? hw->core->parent->hw : NULL; in clk_hw_get_parent()
297 struct clk_core *core) in __clk_lookup_subtree() argument
302 if (!strcmp(core->name, name)) in __clk_lookup_subtree()
303 return core; in __clk_lookup_subtree()
305 hlist_for_each_entry(child, &core->children, child_node) { in __clk_lookup_subtree()
360 * @core: clk to find parent of
394 static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index) in clk_core_get() argument
396 const char *name = core->parents[p_index].fw_name; in clk_core_get()
397 int index = core->parents[p_index].index; in clk_core_get()
399 struct device *dev = core->dev; in clk_core_get()
401 struct device_node *np = core->of_node; in clk_core_get()
419 return hw->core; in clk_core_get()
422 static void clk_core_fill_parent_index(struct clk_core *core, u8 index) in clk_core_fill_parent_index() argument
424 struct clk_parent_map *entry = &core->parents[index]; in clk_core_fill_parent_index()
428 parent = entry->hw->core; in clk_core_fill_parent_index()
437 parent = clk_core_get(core, index); in clk_core_fill_parent_index()
444 entry->core = parent; in clk_core_fill_parent_index()
447 static struct clk_core *clk_core_get_parent_by_index(struct clk_core *core, in clk_core_get_parent_by_index() argument
450 if (!core || index >= core->num_parents || !core->parents) in clk_core_get_parent_by_index()
453 if (!core->parents[index].core) in clk_core_get_parent_by_index()
454 clk_core_fill_parent_index(core, index); in clk_core_get_parent_by_index()
456 return core->parents[index].core; in clk_core_get_parent_by_index()
464 parent = clk_core_get_parent_by_index(hw->core, index); in clk_hw_get_parent_by_index()
472 return !clk ? 0 : clk->core->enable_count; in __clk_get_enable_count()
475 static unsigned long clk_core_get_rate_nolock(struct clk_core *core) in clk_core_get_rate_nolock() argument
477 if (!core) in clk_core_get_rate_nolock()
480 if (!core->num_parents || core->parent) in clk_core_get_rate_nolock()
481 return core->rate; in clk_core_get_rate_nolock()
493 return clk_core_get_rate_nolock(hw->core); in clk_hw_get_rate()
497 static unsigned long clk_core_get_accuracy_no_lock(struct clk_core *core) in clk_core_get_accuracy_no_lock() argument
499 if (!core) in clk_core_get_accuracy_no_lock()
502 return core->accuracy; in clk_core_get_accuracy_no_lock()
507 return hw->core->flags; in clk_hw_get_flags()
513 return clk_core_is_prepared(hw->core); in clk_hw_is_prepared()
519 return clk_core_rate_is_protected(hw->core); in clk_hw_rate_is_protected()
525 return clk_core_is_enabled(hw->core); in clk_hw_is_enabled()
534 return clk_core_is_enabled(clk->core); in __clk_is_enabled()
551 struct clk_core *core = hw->core, *parent, *best_parent = NULL; in clk_mux_determine_rate_flags() local
557 if (core->flags & CLK_SET_RATE_NO_REPARENT) { in clk_mux_determine_rate_flags()
558 parent = core->parent; in clk_mux_determine_rate_flags()
559 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
569 best = clk_core_get_rate_nolock(core); in clk_mux_determine_rate_flags()
576 num_parents = core->num_parents; in clk_mux_determine_rate_flags()
578 parent = clk_core_get_parent_by_index(core, i); in clk_mux_determine_rate_flags()
582 if (core->flags & CLK_SET_RATE_PARENT) { in clk_mux_determine_rate_flags()
613 struct clk_core *core = clk_core_lookup(name); in __clk_lookup() local
615 return !core ? NULL : core->hw->clk; in __clk_lookup()
618 static void clk_core_get_boundaries(struct clk_core *core, in clk_core_get_boundaries() argument
626 *min_rate = core->min_rate; in clk_core_get_boundaries()
627 *max_rate = core->max_rate; in clk_core_get_boundaries()
629 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
632 hlist_for_each_entry(clk_user, &core->clks, clks_node) in clk_core_get_boundaries()
636 static bool clk_core_check_boundaries(struct clk_core *core, in clk_core_check_boundaries() argument
644 if (min_rate > core->max_rate || max_rate < core->min_rate) in clk_core_check_boundaries()
647 hlist_for_each_entry(user, &core->clks, clks_node) in clk_core_check_boundaries()
657 hw->core->min_rate = min_rate; in clk_hw_set_rate_range()
658 hw->core->max_rate = max_rate; in clk_hw_set_rate_range()
689 static void clk_core_rate_unprotect(struct clk_core *core) in clk_core_rate_unprotect() argument
693 if (!core) in clk_core_rate_unprotect()
696 if (WARN(core->protect_count == 0, in clk_core_rate_unprotect()
697 "%s already unprotected\n", core->name)) in clk_core_rate_unprotect()
700 if (--core->protect_count > 0) in clk_core_rate_unprotect()
703 clk_core_rate_unprotect(core->parent); in clk_core_rate_unprotect()
706 static int clk_core_rate_nuke_protect(struct clk_core *core) in clk_core_rate_nuke_protect() argument
712 if (!core) in clk_core_rate_nuke_protect()
715 if (core->protect_count == 0) in clk_core_rate_nuke_protect()
718 ret = core->protect_count; in clk_core_rate_nuke_protect()
719 core->protect_count = 1; in clk_core_rate_nuke_protect()
720 clk_core_rate_unprotect(core); in clk_core_rate_nuke_protect()
757 clk_core_rate_unprotect(clk->core); in clk_rate_exclusive_put()
764 static void clk_core_rate_protect(struct clk_core *core) in clk_core_rate_protect() argument
768 if (!core) in clk_core_rate_protect()
771 if (core->protect_count == 0) in clk_core_rate_protect()
772 clk_core_rate_protect(core->parent); in clk_core_rate_protect()
774 core->protect_count++; in clk_core_rate_protect()
777 static void clk_core_rate_restore_protect(struct clk_core *core, int count) in clk_core_rate_restore_protect() argument
781 if (!core) in clk_core_rate_restore_protect()
787 clk_core_rate_protect(core); in clk_core_rate_restore_protect()
788 core->protect_count = count; in clk_core_rate_restore_protect()
815 clk_core_rate_protect(clk->core); in clk_rate_exclusive_get()
823 static void clk_core_unprepare(struct clk_core *core) in clk_core_unprepare() argument
827 if (!core) in clk_core_unprepare()
830 if (WARN(core->prepare_count == 0, in clk_core_unprepare()
831 "%s already unprepared\n", core->name)) in clk_core_unprepare()
834 if (WARN(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_unprepare()
835 "Unpreparing critical %s\n", core->name)) in clk_core_unprepare()
838 if (core->flags & CLK_SET_RATE_GATE) in clk_core_unprepare()
839 clk_core_rate_unprotect(core); in clk_core_unprepare()
841 if (--core->prepare_count > 0) in clk_core_unprepare()
844 WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); in clk_core_unprepare()
846 trace_clk_unprepare(core); in clk_core_unprepare()
848 if (core->ops->unprepare) in clk_core_unprepare()
849 core->ops->unprepare(core->hw); in clk_core_unprepare()
851 trace_clk_unprepare_complete(core); in clk_core_unprepare()
852 clk_core_unprepare(core->parent); in clk_core_unprepare()
853 clk_pm_runtime_put(core); in clk_core_unprepare()
856 static void clk_core_unprepare_lock(struct clk_core *core) in clk_core_unprepare_lock() argument
859 clk_core_unprepare(core); in clk_core_unprepare_lock()
879 clk_core_unprepare_lock(clk->core); in clk_unprepare()
883 static int clk_core_prepare(struct clk_core *core) in clk_core_prepare() argument
889 if (!core) in clk_core_prepare()
892 if (core->prepare_count == 0) { in clk_core_prepare()
893 ret = clk_pm_runtime_get(core); in clk_core_prepare()
897 ret = clk_core_prepare(core->parent); in clk_core_prepare()
901 trace_clk_prepare(core); in clk_core_prepare()
903 if (core->ops->prepare) in clk_core_prepare()
904 ret = core->ops->prepare(core->hw); in clk_core_prepare()
906 trace_clk_prepare_complete(core); in clk_core_prepare()
912 core->prepare_count++; in clk_core_prepare()
921 if (core->flags & CLK_SET_RATE_GATE) in clk_core_prepare()
922 clk_core_rate_protect(core); in clk_core_prepare()
926 clk_core_unprepare(core->parent); in clk_core_prepare()
928 clk_pm_runtime_put(core); in clk_core_prepare()
932 static int clk_core_prepare_lock(struct clk_core *core) in clk_core_prepare_lock() argument
937 ret = clk_core_prepare(core); in clk_core_prepare_lock()
960 return clk_core_prepare_lock(clk->core); in clk_prepare()
964 static void clk_core_disable(struct clk_core *core) in clk_core_disable() argument
968 if (!core) in clk_core_disable()
971 if (WARN(core->enable_count == 0, "%s already disabled\n", core->name)) in clk_core_disable()
974 if (WARN(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL, in clk_core_disable()
975 "Disabling critical %s\n", core->name)) in clk_core_disable()
978 if (--core->enable_count > 0) in clk_core_disable()
981 trace_clk_disable_rcuidle(core); in clk_core_disable()
983 if (core->ops->disable) in clk_core_disable()
984 core->ops->disable(core->hw); in clk_core_disable()
986 trace_clk_disable_complete_rcuidle(core); in clk_core_disable()
988 clk_core_disable(core->parent); in clk_core_disable()
991 static void clk_core_disable_lock(struct clk_core *core) in clk_core_disable_lock() argument
996 clk_core_disable(core); in clk_core_disable_lock()
1017 clk_core_disable_lock(clk->core); in clk_disable()
1021 static int clk_core_enable(struct clk_core *core) in clk_core_enable() argument
1027 if (!core) in clk_core_enable()
1030 if (WARN(core->prepare_count == 0, in clk_core_enable()
1031 "Enabling unprepared %s\n", core->name)) in clk_core_enable()
1034 if (core->enable_count == 0) { in clk_core_enable()
1035 ret = clk_core_enable(core->parent); in clk_core_enable()
1040 trace_clk_enable_rcuidle(core); in clk_core_enable()
1042 if (core->ops->enable) in clk_core_enable()
1043 ret = core->ops->enable(core->hw); in clk_core_enable()
1045 trace_clk_enable_complete_rcuidle(core); in clk_core_enable()
1048 clk_core_disable(core->parent); in clk_core_enable()
1053 core->enable_count++; in clk_core_enable()
1057 static int clk_core_enable_lock(struct clk_core *core) in clk_core_enable_lock() argument
1063 ret = clk_core_enable(core); in clk_core_enable_lock()
1081 struct clk_core *core = hw->core; in clk_gate_restore_context() local
1083 if (core->enable_count) in clk_gate_restore_context()
1084 core->ops->enable(hw); in clk_gate_restore_context()
1086 core->ops->disable(hw); in clk_gate_restore_context()
1090 static int clk_core_save_context(struct clk_core *core) in clk_core_save_context() argument
1095 hlist_for_each_entry(child, &core->children, child_node) { in clk_core_save_context()
1101 if (core->ops && core->ops->save_context) in clk_core_save_context()
1102 ret = core->ops->save_context(core->hw); in clk_core_save_context()
1107 static void clk_core_restore_context(struct clk_core *core) in clk_core_restore_context() argument
1111 if (core->ops && core->ops->restore_context) in clk_core_restore_context()
1112 core->ops->restore_context(core->hw); in clk_core_restore_context()
1114 hlist_for_each_entry(child, &core->children, child_node) in clk_core_restore_context()
1154 struct clk_core *core; in clk_restore_context() local
1156 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_restore_context()
1157 clk_core_restore_context(core); in clk_restore_context()
1159 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_restore_context()
1160 clk_core_restore_context(core); in clk_restore_context()
1182 return clk_core_enable_lock(clk->core); in clk_enable()
1186 static int clk_core_prepare_enable(struct clk_core *core) in clk_core_prepare_enable() argument
1190 ret = clk_core_prepare_lock(core); in clk_core_prepare_enable()
1194 ret = clk_core_enable_lock(core); in clk_core_prepare_enable()
1196 clk_core_unprepare_lock(core); in clk_core_prepare_enable()
1201 static void clk_core_disable_unprepare(struct clk_core *core) in clk_core_disable_unprepare() argument
1203 clk_core_disable_lock(core); in clk_core_disable_unprepare()
1204 clk_core_unprepare_lock(core); in clk_core_disable_unprepare()
1207 static void __init clk_unprepare_unused_subtree(struct clk_core *core) in clk_unprepare_unused_subtree() argument
1213 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_unused_subtree()
1216 if (dev_has_sync_state(core->dev) && in clk_unprepare_unused_subtree()
1217 !(core->flags & CLK_DONT_HOLD_STATE)) in clk_unprepare_unused_subtree()
1220 if (core->prepare_count) in clk_unprepare_unused_subtree()
1223 if (core->flags & CLK_IGNORE_UNUSED) in clk_unprepare_unused_subtree()
1226 if (clk_pm_runtime_get(core)) in clk_unprepare_unused_subtree()
1229 if (clk_core_is_prepared(core)) { in clk_unprepare_unused_subtree()
1230 trace_clk_unprepare(core); in clk_unprepare_unused_subtree()
1231 if (core->ops->unprepare_unused) in clk_unprepare_unused_subtree()
1232 core->ops->unprepare_unused(core->hw); in clk_unprepare_unused_subtree()
1233 else if (core->ops->unprepare) in clk_unprepare_unused_subtree()
1234 core->ops->unprepare(core->hw); in clk_unprepare_unused_subtree()
1235 trace_clk_unprepare_complete(core); in clk_unprepare_unused_subtree()
1238 clk_pm_runtime_put(core); in clk_unprepare_unused_subtree()
1241 static void __init clk_disable_unused_subtree(struct clk_core *core) in clk_disable_unused_subtree() argument
1248 hlist_for_each_entry(child, &core->children, child_node) in clk_disable_unused_subtree()
1251 if (dev_has_sync_state(core->dev) && in clk_disable_unused_subtree()
1252 !(core->flags & CLK_DONT_HOLD_STATE)) in clk_disable_unused_subtree()
1255 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1256 clk_core_prepare_enable(core->parent); in clk_disable_unused_subtree()
1258 if (clk_pm_runtime_get(core)) in clk_disable_unused_subtree()
1263 if (core->enable_count) in clk_disable_unused_subtree()
1266 if (core->flags & CLK_IGNORE_UNUSED) in clk_disable_unused_subtree()
1274 if (clk_core_is_enabled(core)) { in clk_disable_unused_subtree()
1275 trace_clk_disable(core); in clk_disable_unused_subtree()
1276 if (core->ops->disable_unused) in clk_disable_unused_subtree()
1277 core->ops->disable_unused(core->hw); in clk_disable_unused_subtree()
1278 else if (core->ops->disable) in clk_disable_unused_subtree()
1279 core->ops->disable(core->hw); in clk_disable_unused_subtree()
1280 trace_clk_disable_complete(core); in clk_disable_unused_subtree()
1285 clk_pm_runtime_put(core); in clk_disable_unused_subtree()
1287 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_disable_unused_subtree()
1288 clk_core_disable_unprepare(core->parent); in clk_disable_unused_subtree()
1301 struct clk_core *core; in clk_disable_unused() local
1310 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1311 clk_disable_unused_subtree(core); in clk_disable_unused()
1313 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1314 clk_disable_unused_subtree(core); in clk_disable_unused()
1316 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_disable_unused()
1317 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1319 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_disable_unused()
1320 clk_unprepare_unused_subtree(core); in clk_disable_unused()
1328 static void clk_unprepare_disable_dev_subtree(struct clk_core *core, in clk_unprepare_disable_dev_subtree() argument
1335 hlist_for_each_entry(child, &core->children, child_node) in clk_unprepare_disable_dev_subtree()
1338 if (core->dev != dev || !core->need_sync) in clk_unprepare_disable_dev_subtree()
1341 clk_core_disable_unprepare(core); in clk_unprepare_disable_dev_subtree()
1346 struct clk_core *core; in clk_sync_state() local
1350 hlist_for_each_entry(core, &clk_root_list, child_node) in clk_sync_state()
1351 clk_unprepare_disable_dev_subtree(core, dev); in clk_sync_state()
1353 hlist_for_each_entry(core, &clk_orphan_list, child_node) in clk_sync_state()
1354 clk_unprepare_disable_dev_subtree(core, dev); in clk_sync_state()
1360 static int clk_core_determine_round_nolock(struct clk_core *core, in clk_core_determine_round_nolock() argument
1367 if (!core) in clk_core_determine_round_nolock()
1371 * At this point, core protection will be disabled if in clk_core_determine_round_nolock()
1376 if (clk_core_rate_is_protected(core)) { in clk_core_determine_round_nolock()
1377 req->rate = core->rate; in clk_core_determine_round_nolock()
1378 } else if (core->ops->determine_rate) { in clk_core_determine_round_nolock()
1379 return core->ops->determine_rate(core->hw, req); in clk_core_determine_round_nolock()
1380 } else if (core->ops->round_rate) { in clk_core_determine_round_nolock()
1381 rate = core->ops->round_rate(core->hw, req->rate, in clk_core_determine_round_nolock()
1394 static void clk_core_init_rate_req(struct clk_core * const core, in clk_core_init_rate_req() argument
1399 if (WARN_ON(!core || !req)) in clk_core_init_rate_req()
1402 parent = core->parent; in clk_core_init_rate_req()
1412 static bool clk_core_can_round(struct clk_core * const core) in clk_core_can_round() argument
1414 return core->ops->determine_rate || core->ops->round_rate; in clk_core_can_round()
1417 static int clk_core_round_rate_nolock(struct clk_core *core, in clk_core_round_rate_nolock() argument
1422 if (!core) { in clk_core_round_rate_nolock()
1427 clk_core_init_rate_req(core, req); in clk_core_round_rate_nolock()
1429 if (clk_core_can_round(core)) in clk_core_round_rate_nolock()
1430 return clk_core_determine_round_nolock(core, req); in clk_core_round_rate_nolock()
1431 else if (core->flags & CLK_SET_RATE_PARENT) in clk_core_round_rate_nolock()
1432 return clk_core_round_rate_nolock(core->parent, req); in clk_core_round_rate_nolock()
1434 req->rate = core->rate; in clk_core_round_rate_nolock()
1452 return clk_core_round_rate_nolock(hw->core, req); in __clk_determine_rate()
1476 clk_core_get_boundaries(hw->core, &req.min_rate, &req.max_rate); in clk_hw_round_rate()
1479 ret = clk_core_round_rate_nolock(hw->core, &req); in clk_hw_round_rate()
1507 clk_core_rate_unprotect(clk->core); in clk_round_rate()
1509 clk_core_get_boundaries(clk->core, &req.min_rate, &req.max_rate); in clk_round_rate()
1512 ret = clk_core_round_rate_nolock(clk->core, &req); in clk_round_rate()
1515 clk_core_rate_protect(clk->core); in clk_round_rate()
1528 * @core: clk that is changing rate
1540 static int __clk_notify(struct clk_core *core, unsigned long msg, in __clk_notify() argument
1551 if (cn->clk->core == core) { in __clk_notify()
1565 * @core: first clk in the subtree
1572 static void __clk_recalc_accuracies(struct clk_core *core) in __clk_recalc_accuracies() argument
1579 if (core->parent) in __clk_recalc_accuracies()
1580 parent_accuracy = core->parent->accuracy; in __clk_recalc_accuracies()
1582 if (core->ops->recalc_accuracy) in __clk_recalc_accuracies()
1583 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_recalc_accuracies()
1586 core->accuracy = parent_accuracy; in __clk_recalc_accuracies()
1588 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_accuracies()
1592 static long clk_core_get_accuracy_recalc(struct clk_core *core) in clk_core_get_accuracy_recalc() argument
1594 if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE)) in clk_core_get_accuracy_recalc()
1595 __clk_recalc_accuracies(core); in clk_core_get_accuracy_recalc()
1597 return clk_core_get_accuracy_no_lock(core); in clk_core_get_accuracy_recalc()
1617 accuracy = clk_core_get_accuracy_recalc(clk->core); in clk_get_accuracy()
1624 static unsigned long clk_recalc(struct clk_core *core, in clk_recalc() argument
1629 if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { in clk_recalc()
1630 rate = core->ops->recalc_rate(core->hw, parent_rate); in clk_recalc()
1631 clk_pm_runtime_put(core); in clk_recalc()
1638 * @core: first clk in the subtree
1648 static void __clk_recalc_rates(struct clk_core *core, unsigned long msg) in __clk_recalc_rates() argument
1656 old_rate = core->rate; in __clk_recalc_rates()
1658 if (core->parent) in __clk_recalc_rates()
1659 parent_rate = core->parent->rate; in __clk_recalc_rates()
1661 core->rate = clk_recalc(core, parent_rate); in __clk_recalc_rates()
1667 if (core->notifier_count && msg) in __clk_recalc_rates()
1668 __clk_notify(core, msg, old_rate, core->rate); in __clk_recalc_rates()
1670 hlist_for_each_entry(child, &core->children, child_node) in __clk_recalc_rates()
1674 static unsigned long clk_core_get_rate_recalc(struct clk_core *core) in clk_core_get_rate_recalc() argument
1676 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) in clk_core_get_rate_recalc()
1677 __clk_recalc_rates(core, 0); in clk_core_get_rate_recalc()
1679 return clk_core_get_rate_nolock(core); in clk_core_get_rate_recalc()
1698 rate = clk_core_get_rate_recalc(clk->core); in clk_get_rate()
1705 static int clk_fetch_parent_index(struct clk_core *core, in clk_fetch_parent_index() argument
1713 for (i = 0; i < core->num_parents; i++) { in clk_fetch_parent_index()
1715 if (core->parents[i].core == parent) in clk_fetch_parent_index()
1719 if (core->parents[i].core) in clk_fetch_parent_index()
1722 /* Maybe core hasn't been cached but the hw is all we know? */ in clk_fetch_parent_index()
1723 if (core->parents[i].hw) { in clk_fetch_parent_index()
1724 if (core->parents[i].hw == parent->hw) in clk_fetch_parent_index()
1732 if (parent == clk_core_get(core, i)) in clk_fetch_parent_index()
1736 if (core->parents[i].name && in clk_fetch_parent_index()
1737 !strcmp(parent->name, core->parents[i].name)) in clk_fetch_parent_index()
1741 if (i == core->num_parents) in clk_fetch_parent_index()
1744 core->parents[i].core = parent; in clk_fetch_parent_index()
1762 return clk_fetch_parent_index(hw->core, parent->core); in clk_hw_get_parent_index()
1766 static void clk_core_hold_state(struct clk_core *core) in clk_core_hold_state() argument
1768 if (core->need_sync || !core->boot_enabled) in clk_core_hold_state()
1771 if (core->orphan || !dev_has_sync_state(core->dev)) in clk_core_hold_state()
1774 if (core->flags & CLK_DONT_HOLD_STATE) in clk_core_hold_state()
1777 core->need_sync = !clk_core_prepare_enable(core); in clk_core_hold_state()
1780 static void __clk_core_update_orphan_hold_state(struct clk_core *core) in __clk_core_update_orphan_hold_state() argument
1784 if (core->orphan) in __clk_core_update_orphan_hold_state()
1787 clk_core_hold_state(core); in __clk_core_update_orphan_hold_state()
1789 hlist_for_each_entry(child, &core->children, child_node) in __clk_core_update_orphan_hold_state()
1794 * Update the orphan status of @core and all its children.
1796 static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan) in clk_core_update_orphan_status() argument
1800 core->orphan = is_orphan; in clk_core_update_orphan_status()
1802 hlist_for_each_entry(child, &core->children, child_node) in clk_core_update_orphan_status()
1806 static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) in clk_reparent() argument
1808 bool was_orphan = core->orphan; in clk_reparent()
1810 hlist_del(&core->child_node); in clk_reparent()
1816 if (new_parent->new_child == core) in clk_reparent()
1819 hlist_add_head(&core->child_node, &new_parent->children); in clk_reparent()
1822 clk_core_update_orphan_status(core, becomes_orphan); in clk_reparent()
1824 hlist_add_head(&core->child_node, &clk_orphan_list); in clk_reparent()
1826 clk_core_update_orphan_status(core, true); in clk_reparent()
1829 core->parent = new_parent; in clk_reparent()
1832 static struct clk_core *__clk_set_parent_before(struct clk_core *core, in __clk_set_parent_before() argument
1836 struct clk_core *old_parent = core->parent; in __clk_set_parent_before()
1859 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_before()
1865 if (core->prepare_count) { in __clk_set_parent_before()
1867 clk_core_enable_lock(core); in __clk_set_parent_before()
1872 clk_reparent(core, parent); in __clk_set_parent_before()
1878 static void __clk_set_parent_after(struct clk_core *core, in __clk_set_parent_after() argument
1886 if (core->prepare_count) { in __clk_set_parent_after()
1887 clk_core_disable_lock(core); in __clk_set_parent_after()
1892 if (core->flags & CLK_OPS_PARENT_ENABLE) { in __clk_set_parent_after()
1898 static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, in __clk_set_parent() argument
1905 old_parent = __clk_set_parent_before(core, parent); in __clk_set_parent()
1907 trace_clk_set_parent(core, parent); in __clk_set_parent()
1910 if (parent && core->ops->set_parent) in __clk_set_parent()
1911 ret = core->ops->set_parent(core->hw, p_index); in __clk_set_parent()
1913 trace_clk_set_parent_complete(core, parent); in __clk_set_parent()
1917 clk_reparent(core, old_parent); in __clk_set_parent()
1919 __clk_set_parent_after(core, old_parent, parent); in __clk_set_parent()
1924 __clk_set_parent_after(core, parent, old_parent); in __clk_set_parent()
1931 * @core: first clk in the subtree
1943 static int __clk_speculate_rates(struct clk_core *core, in __clk_speculate_rates() argument
1952 new_rate = clk_recalc(core, parent_rate); in __clk_speculate_rates()
1955 if (core->notifier_count) in __clk_speculate_rates()
1956 ret = __clk_notify(core, PRE_RATE_CHANGE, core->rate, new_rate); in __clk_speculate_rates()
1960 __func__, core->name, ret); in __clk_speculate_rates()
1964 hlist_for_each_entry(child, &core->children, child_node) { in __clk_speculate_rates()
1974 static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, in clk_calc_subtree() argument
1979 core->new_rate = new_rate; in clk_calc_subtree()
1980 core->new_parent = new_parent; in clk_calc_subtree()
1981 core->new_parent_index = p_index; in clk_calc_subtree()
1983 core->new_child = NULL; in clk_calc_subtree()
1984 if (new_parent && new_parent != core->parent) in clk_calc_subtree()
1985 new_parent->new_child = core; in clk_calc_subtree()
1987 hlist_for_each_entry(child, &core->children, child_node) { in clk_calc_subtree()
1997 static struct clk_core *clk_calc_new_rates(struct clk_core *core, in clk_calc_new_rates() argument
2000 struct clk_core *top = core; in clk_calc_new_rates()
2010 if (IS_ERR_OR_NULL(core)) in clk_calc_new_rates()
2014 parent = old_parent = core->parent; in clk_calc_new_rates()
2018 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_calc_new_rates()
2021 if (clk_core_can_round(core)) { in clk_calc_new_rates()
2028 clk_core_init_rate_req(core, &req); in clk_calc_new_rates()
2030 ret = clk_core_determine_round_nolock(core, &req); in clk_calc_new_rates()
2036 parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; in clk_calc_new_rates()
2040 } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) { in clk_calc_new_rates()
2042 core->new_rate = core->rate; in clk_calc_new_rates()
2053 (core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) { in clk_calc_new_rates()
2055 __func__, core->name); in clk_calc_new_rates()
2060 if (parent && core->num_parents > 1) { in clk_calc_new_rates()
2061 p_index = clk_fetch_parent_index(core, parent); in clk_calc_new_rates()
2064 __func__, parent->name, core->name); in clk_calc_new_rates()
2069 if ((core->flags & CLK_SET_RATE_PARENT) && parent && in clk_calc_new_rates()
2074 clk_calc_subtree(core, new_rate, parent, p_index); in clk_calc_new_rates()
2084 static struct clk_core *clk_propagate_rate_change(struct clk_core *core, in clk_propagate_rate_change() argument
2090 if (core->rate == core->new_rate) in clk_propagate_rate_change()
2093 if (core->notifier_count) { in clk_propagate_rate_change()
2094 ret = __clk_notify(core, event, core->rate, core->new_rate); in clk_propagate_rate_change()
2096 fail_clk = core; in clk_propagate_rate_change()
2099 if (core->ops->pre_rate_change) { in clk_propagate_rate_change()
2100 ret = core->ops->pre_rate_change(core->hw, core->rate, in clk_propagate_rate_change()
2101 core->new_rate); in clk_propagate_rate_change()
2103 fail_clk = core; in clk_propagate_rate_change()
2106 hlist_for_each_entry(child, &core->children, child_node) { in clk_propagate_rate_change()
2108 if (child->new_parent && child->new_parent != core) in clk_propagate_rate_change()
2115 /* handle the new child who might not be in core->children yet */ in clk_propagate_rate_change()
2116 if (core->new_child) { in clk_propagate_rate_change()
2117 tmp_clk = clk_propagate_rate_change(core->new_child, event); in clk_propagate_rate_change()
2129 static void clk_change_rate(struct clk_core *core) in clk_change_rate() argument
2139 old_rate = core->rate; in clk_change_rate()
2141 if (core->new_parent) { in clk_change_rate()
2142 parent = core->new_parent; in clk_change_rate()
2143 best_parent_rate = core->new_parent->rate; in clk_change_rate()
2144 } else if (core->parent) { in clk_change_rate()
2145 parent = core->parent; in clk_change_rate()
2146 best_parent_rate = core->parent->rate; in clk_change_rate()
2149 if (clk_pm_runtime_get(core)) in clk_change_rate()
2152 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2155 clk_core_prepare(core); in clk_change_rate()
2157 clk_core_enable(core); in clk_change_rate()
2161 if (core->new_parent && core->new_parent != core->parent) { in clk_change_rate()
2162 old_parent = __clk_set_parent_before(core, core->new_parent); in clk_change_rate()
2163 trace_clk_set_parent(core, core->new_parent); in clk_change_rate()
2165 if (core->ops->set_rate_and_parent) { in clk_change_rate()
2167 core->ops->set_rate_and_parent(core->hw, core->new_rate, in clk_change_rate()
2169 core->new_parent_index); in clk_change_rate()
2170 } else if (core->ops->set_parent) { in clk_change_rate()
2171 core->ops->set_parent(core->hw, core->new_parent_index); in clk_change_rate()
2174 trace_clk_set_parent_complete(core, core->new_parent); in clk_change_rate()
2175 __clk_set_parent_after(core, core->new_parent, old_parent); in clk_change_rate()
2178 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2181 trace_clk_set_rate(core, core->new_rate); in clk_change_rate()
2183 if (!skip_set_rate && core->ops->set_rate) in clk_change_rate()
2184 core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); in clk_change_rate()
2186 trace_clk_set_rate_complete(core, core->new_rate); in clk_change_rate()
2188 core->rate = clk_recalc(core, best_parent_rate); in clk_change_rate()
2190 if (core->flags & CLK_SET_RATE_UNGATE) { in clk_change_rate()
2194 clk_core_disable(core); in clk_change_rate()
2196 clk_core_unprepare(core); in clk_change_rate()
2199 if (core->flags & CLK_OPS_PARENT_ENABLE) in clk_change_rate()
2202 if (core->notifier_count && old_rate != core->rate) in clk_change_rate()
2203 __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); in clk_change_rate()
2205 if (core->flags & CLK_RECALC_NEW_RATES) in clk_change_rate()
2206 (void)clk_calc_new_rates(core, core->new_rate); in clk_change_rate()
2208 if (core->ops->post_rate_change) in clk_change_rate()
2209 core->ops->post_rate_change(core->hw, old_rate, core->rate); in clk_change_rate()
2215 hlist_for_each_entry_safe(child, tmp, &core->children, child_node) { in clk_change_rate()
2217 if (child->new_parent && child->new_parent != core) in clk_change_rate()
2222 /* handle the new child who might not be in core->children yet */ in clk_change_rate()
2223 if (core->new_child) in clk_change_rate()
2224 clk_change_rate(core->new_child); in clk_change_rate()
2226 clk_pm_runtime_put(core); in clk_change_rate()
2229 static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, in clk_core_req_round_rate_nolock() argument
2237 if (!core) in clk_core_req_round_rate_nolock()
2241 cnt = clk_core_rate_nuke_protect(core); in clk_core_req_round_rate_nolock()
2245 clk_core_get_boundaries(core, &req.min_rate, &req.max_rate); in clk_core_req_round_rate_nolock()
2248 ret = clk_core_round_rate_nolock(core, &req); in clk_core_req_round_rate_nolock()
2251 clk_core_rate_restore_protect(core, cnt); in clk_core_req_round_rate_nolock()
2256 static int clk_core_set_rate_nolock(struct clk_core *core, in clk_core_set_rate_nolock() argument
2263 if (!core) in clk_core_set_rate_nolock()
2266 rate = clk_core_req_round_rate_nolock(core, req_rate); in clk_core_set_rate_nolock()
2269 if (rate == clk_core_get_rate_nolock(core)) in clk_core_set_rate_nolock()
2273 if (clk_core_rate_is_protected(core)) in clk_core_set_rate_nolock()
2277 top = clk_calc_new_rates(core, req_rate); in clk_core_set_rate_nolock()
2281 ret = clk_pm_runtime_get(core); in clk_core_set_rate_nolock()
2298 core->req_rate = req_rate; in clk_core_set_rate_nolock()
2300 clk_pm_runtime_put(core); in clk_core_set_rate_nolock()
2337 clk_core_rate_unprotect(clk->core); in clk_set_rate()
2339 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate()
2342 clk_core_rate_protect(clk->core); in clk_set_rate()
2385 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_exclusive()
2387 clk_core_rate_protect(clk->core); in clk_set_rate_exclusive()
2415 __func__, clk->core->name, clk->dev_id, clk->con_id, in clk_set_rate_range()
2423 clk_core_rate_unprotect(clk->core); in clk_set_rate_range()
2431 if (!clk_core_check_boundaries(clk->core, min, max)) { in clk_set_rate_range()
2436 rate = clk_core_get_rate_nolock(clk->core); in clk_set_rate_range()
2456 ret = clk_core_set_rate_nolock(clk->core, rate); in clk_set_rate_range()
2466 clk_core_rate_protect(clk->core); in clk_set_rate_range()
2521 parent = !clk->core->parent ? NULL : clk->core->parent->hw->clk; in clk_get_parent()
2528 static struct clk_core *__clk_init_parent(struct clk_core *core) in __clk_init_parent() argument
2532 if (core->num_parents > 1 && core->ops->get_parent) in __clk_init_parent()
2533 index = core->ops->get_parent(core->hw); in __clk_init_parent()
2535 return clk_core_get_parent_by_index(core, index); in __clk_init_parent()
2538 static void clk_core_reparent(struct clk_core *core, in clk_core_reparent() argument
2541 clk_reparent(core, new_parent); in clk_core_reparent()
2542 __clk_recalc_accuracies(core); in clk_core_reparent()
2543 __clk_recalc_rates(core, POST_RATE_CHANGE); in clk_core_reparent()
2551 clk_core_reparent(hw->core, !new_parent ? NULL : new_parent->core); in clk_hw_reparent()
2566 struct clk_core *core, *parent_core; in clk_has_parent() local
2573 core = clk->core; in clk_has_parent()
2574 parent_core = parent->core; in clk_has_parent()
2577 if (core->parent == parent_core) in clk_has_parent()
2580 for (i = 0; i < core->num_parents; i++) in clk_has_parent()
2581 if (!strcmp(core->parents[i].name, parent_core->name)) in clk_has_parent()
2588 static int clk_core_set_parent_nolock(struct clk_core *core, in clk_core_set_parent_nolock() argument
2597 if (!core) in clk_core_set_parent_nolock()
2600 if (core->parent == parent) in clk_core_set_parent_nolock()
2604 if (core->num_parents > 1 && !core->ops->set_parent) in clk_core_set_parent_nolock()
2608 if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) in clk_core_set_parent_nolock()
2611 if (clk_core_rate_is_protected(core)) in clk_core_set_parent_nolock()
2616 p_index = clk_fetch_parent_index(core, parent); in clk_core_set_parent_nolock()
2619 __func__, parent->name, core->name); in clk_core_set_parent_nolock()
2625 ret = clk_pm_runtime_get(core); in clk_core_set_parent_nolock()
2630 ret = __clk_speculate_rates(core, p_rate); in clk_core_set_parent_nolock()
2637 ret = __clk_set_parent(core, parent, p_index); in clk_core_set_parent_nolock()
2641 __clk_recalc_rates(core, ABORT_RATE_CHANGE); in clk_core_set_parent_nolock()
2643 __clk_recalc_rates(core, POST_RATE_CHANGE); in clk_core_set_parent_nolock()
2644 __clk_recalc_accuracies(core); in clk_core_set_parent_nolock()
2648 clk_pm_runtime_put(core); in clk_core_set_parent_nolock()
2655 return clk_core_set_parent_nolock(hw->core, parent->core); in clk_hw_set_parent()
2686 clk_core_rate_unprotect(clk->core); in clk_set_parent()
2688 ret = clk_core_set_parent_nolock(clk->core, in clk_set_parent()
2689 parent ? parent->core : NULL); in clk_set_parent()
2692 clk_core_rate_protect(clk->core); in clk_set_parent()
2700 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) in clk_core_set_phase_nolock() argument
2706 if (!core) in clk_core_set_phase_nolock()
2709 if (clk_core_rate_is_protected(core)) in clk_core_set_phase_nolock()
2712 trace_clk_set_phase(core, degrees); in clk_core_set_phase_nolock()
2714 if (core->ops->set_phase) { in clk_core_set_phase_nolock()
2715 ret = core->ops->set_phase(core->hw, degrees); in clk_core_set_phase_nolock()
2717 core->phase = degrees; in clk_core_set_phase_nolock()
2720 trace_clk_set_phase_complete(core, degrees); in clk_core_set_phase_nolock()
2760 clk_core_rate_unprotect(clk->core); in clk_set_phase()
2762 ret = clk_core_set_phase_nolock(clk->core, degrees); in clk_set_phase()
2765 clk_core_rate_protect(clk->core); in clk_set_phase()
2773 static int clk_core_get_phase(struct clk_core *core) in clk_core_get_phase() argument
2778 if (!core->ops->get_phase) in clk_core_get_phase()
2782 ret = core->ops->get_phase(core->hw); in clk_core_get_phase()
2784 core->phase = ret; in clk_core_get_phase()
2804 ret = clk_core_get_phase(clk->core); in clk_get_phase()
2811 static void clk_core_reset_duty_cycle_nolock(struct clk_core *core) in clk_core_reset_duty_cycle_nolock() argument
2814 core->duty.num = 1; in clk_core_reset_duty_cycle_nolock()
2815 core->duty.den = 2; in clk_core_reset_duty_cycle_nolock()
2818 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core);
2820 static int clk_core_update_duty_cycle_nolock(struct clk_core *core) in clk_core_update_duty_cycle_nolock() argument
2822 struct clk_duty *duty = &core->duty; in clk_core_update_duty_cycle_nolock()
2825 if (!core->ops->get_duty_cycle) in clk_core_update_duty_cycle_nolock()
2826 return clk_core_update_duty_cycle_parent_nolock(core); in clk_core_update_duty_cycle_nolock()
2828 ret = core->ops->get_duty_cycle(core->hw, duty); in clk_core_update_duty_cycle_nolock()
2841 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_nolock()
2845 static int clk_core_update_duty_cycle_parent_nolock(struct clk_core *core) in clk_core_update_duty_cycle_parent_nolock() argument
2849 if (core->parent && in clk_core_update_duty_cycle_parent_nolock()
2850 core->flags & CLK_DUTY_CYCLE_PARENT) { in clk_core_update_duty_cycle_parent_nolock()
2851 ret = clk_core_update_duty_cycle_nolock(core->parent); in clk_core_update_duty_cycle_parent_nolock()
2852 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_update_duty_cycle_parent_nolock()
2854 clk_core_reset_duty_cycle_nolock(core); in clk_core_update_duty_cycle_parent_nolock()
2860 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core,
2863 static int clk_core_set_duty_cycle_nolock(struct clk_core *core, in clk_core_set_duty_cycle_nolock() argument
2870 if (clk_core_rate_is_protected(core)) in clk_core_set_duty_cycle_nolock()
2873 trace_clk_set_duty_cycle(core, duty); in clk_core_set_duty_cycle_nolock()
2875 if (!core->ops->set_duty_cycle) in clk_core_set_duty_cycle_nolock()
2876 return clk_core_set_duty_cycle_parent_nolock(core, duty); in clk_core_set_duty_cycle_nolock()
2878 ret = core->ops->set_duty_cycle(core->hw, duty); in clk_core_set_duty_cycle_nolock()
2880 memcpy(&core->duty, duty, sizeof(*duty)); in clk_core_set_duty_cycle_nolock()
2882 trace_clk_set_duty_cycle_complete(core, duty); in clk_core_set_duty_cycle_nolock()
2887 static int clk_core_set_duty_cycle_parent_nolock(struct clk_core *core, in clk_core_set_duty_cycle_parent_nolock() argument
2892 if (core->parent && in clk_core_set_duty_cycle_parent_nolock()
2893 core->flags & (CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT)) { in clk_core_set_duty_cycle_parent_nolock()
2894 ret = clk_core_set_duty_cycle_nolock(core->parent, duty); in clk_core_set_duty_cycle_parent_nolock()
2895 memcpy(&core->duty, &core->parent->duty, sizeof(core->duty)); in clk_core_set_duty_cycle_parent_nolock()
2930 clk_core_rate_unprotect(clk->core); in clk_set_duty_cycle()
2932 ret = clk_core_set_duty_cycle_nolock(clk->core, &duty); in clk_set_duty_cycle()
2935 clk_core_rate_protect(clk->core); in clk_set_duty_cycle()
2943 static int clk_core_get_scaled_duty_cycle(struct clk_core *core, in clk_core_get_scaled_duty_cycle() argument
2946 struct clk_duty *duty = &core->duty; in clk_core_get_scaled_duty_cycle()
2951 ret = clk_core_update_duty_cycle_nolock(core); in clk_core_get_scaled_duty_cycle()
2973 return clk_core_get_scaled_duty_cycle(clk->core, scale); in clk_get_scaled_duty_cycle()
2994 /* true if clk->core pointers match. Avoid dereferencing garbage */ in clk_is_match()
2996 if (p->core == q->core) in clk_is_match()
3146 struct clk_core *core = data; in clk_rate_set() local
3150 ret = clk_core_set_rate_nolock(core, val); in clk_rate_set()
3160 struct clk_core *core = data; in clk_prepare_enable_set() local
3164 ret = clk_prepare_enable(core->hw->clk); in clk_prepare_enable_set()
3166 clk_disable_unprepare(core->hw->clk); in clk_prepare_enable_set()
3173 struct clk_core *core = data; in clk_prepare_enable_get() local
3175 *val = core->enable_count && core->prepare_count; in clk_prepare_enable_get()
3189 struct clk_core *core = data; in clk_rate_get() local
3191 *val = core->rate; in clk_rate_get()
3219 struct clk_core *core = s->private; in clk_flags_show() local
3220 unsigned long flags = core->flags; in clk_flags_show()
3238 static void possible_parent_show(struct seq_file *s, struct clk_core *core, in possible_parent_show() argument
3255 parent = clk_core_get_parent_by_index(core, i); in possible_parent_show()
3258 else if (core->parents[i].name) in possible_parent_show()
3259 seq_puts(s, core->parents[i].name); in possible_parent_show()
3260 else if (core->parents[i].fw_name) in possible_parent_show()
3261 seq_printf(s, "<%s>(fw)", core->parents[i].fw_name); in possible_parent_show()
3262 else if (core->parents[i].index >= 0) in possible_parent_show()
3264 of_clk_get_parent_name(core->of_node, in possible_parent_show()
3265 core->parents[i].index)); in possible_parent_show()
3274 struct clk_core *core = s->private; in possible_parents_show() local
3277 for (i = 0; i < core->num_parents - 1; i++) in possible_parents_show()
3278 possible_parent_show(s, core, i, ' '); in possible_parents_show()
3280 possible_parent_show(s, core, i, '\n'); in possible_parents_show()
3288 struct clk_core *core = s->private; in current_parent_show() local
3290 if (core->parent) in current_parent_show()
3291 seq_printf(s, "%s\n", core->parent->name); in current_parent_show()
3299 struct clk_core *core = s->private; in clk_duty_cycle_show() local
3300 struct clk_duty *duty = &core->duty; in clk_duty_cycle_show()
3310 struct clk_core *core = s->private; in clk_min_rate_show() local
3314 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_min_rate_show()
3324 struct clk_core *core = s->private; in clk_max_rate_show() local
3328 clk_core_get_boundaries(core, &min_rate, &max_rate); in clk_max_rate_show()
3336 static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry) in clk_debug_create_one() argument
3340 if (!core || !pdentry) in clk_debug_create_one()
3343 root = debugfs_create_dir(core->name, pdentry); in clk_debug_create_one()
3344 core->dentry = root; in clk_debug_create_one()
3346 debugfs_create_file("clk_rate", clk_rate_mode, root, core, in clk_debug_create_one()
3348 debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops); in clk_debug_create_one()
3349 debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops); in clk_debug_create_one()
3350 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); in clk_debug_create_one()
3351 debugfs_create_u32("clk_phase", 0444, root, &core->phase); in clk_debug_create_one()
3352 debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops); in clk_debug_create_one()
3353 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); in clk_debug_create_one()
3354 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count); in clk_debug_create_one()
3355 debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count); in clk_debug_create_one()
3356 debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count); in clk_debug_create_one()
3357 debugfs_create_file("clk_duty_cycle", 0444, root, core, in clk_debug_create_one()
3360 debugfs_create_file("clk_prepare_enable", 0644, root, core, in clk_debug_create_one()
3364 if (core->num_parents > 0) in clk_debug_create_one()
3365 debugfs_create_file("clk_parent", 0444, root, core, in clk_debug_create_one()
3368 if (core->num_parents > 1) in clk_debug_create_one()
3369 debugfs_create_file("clk_possible_parents", 0444, root, core, in clk_debug_create_one()
3372 if (core->ops->debug_init) in clk_debug_create_one()
3373 core->ops->debug_init(core->hw, core->dentry); in clk_debug_create_one()
3378 * @core: the clk being added to the debugfs clk directory
3384 static void clk_debug_register(struct clk_core *core) in clk_debug_register() argument
3387 hlist_add_head(&core->debug_node, &clk_debug_list); in clk_debug_register()
3389 clk_debug_create_one(core, rootdir); in clk_debug_register()
3395 * @core: the clk being removed from the debugfs clk directory
3401 static void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3404 hlist_del_init(&core->debug_node); in clk_debug_unregister()
3405 debugfs_remove_recursive(core->dentry); in clk_debug_unregister()
3406 core->dentry = NULL; in clk_debug_unregister()
3421 struct clk_core *core; in clk_debug_init() local
3453 hlist_for_each_entry(core, &clk_debug_list, debug_node) in clk_debug_init()
3454 clk_debug_create_one(core, rootdir); in clk_debug_init()
3463 static inline void clk_debug_register(struct clk_core *core) { } in clk_debug_register() argument
3464 static inline void clk_debug_unregister(struct clk_core *core) in clk_debug_unregister() argument
3513 * @core: clk_core being initialized
3518 static int __clk_core_init(struct clk_core *core) in __clk_core_init() argument
3525 if (!core) in __clk_core_init()
3531 * Set hw->core after grabbing the prepare_lock to synchronize with in __clk_core_init()
3532 * callers of clk_core_fill_parent_index() where we treat hw->core in __clk_core_init()
3536 core->hw->core = core; in __clk_core_init()
3538 ret = clk_pm_runtime_get(core); in __clk_core_init()
3543 if (clk_core_lookup(core->name)) { in __clk_core_init()
3545 __func__, core->name); in __clk_core_init()
3551 if (core->ops->set_rate && in __clk_core_init()
3552 !((core->ops->round_rate || core->ops->determine_rate) && in __clk_core_init()
3553 core->ops->recalc_rate)) { in __clk_core_init()
3555 __func__, core->name); in __clk_core_init()
3560 if (core->ops->set_parent && !core->ops->get_parent) { in __clk_core_init()
3562 __func__, core->name); in __clk_core_init()
3567 if (core->num_parents > 1 && !core->ops->get_parent) { in __clk_core_init()
3569 __func__, core->name); in __clk_core_init()
3574 if (core->ops->set_rate_and_parent && in __clk_core_init()
3575 !(core->ops->set_parent && core->ops->set_rate)) { in __clk_core_init()
3577 __func__, core->name); in __clk_core_init()
3596 if (core->ops->init) { in __clk_core_init()
3597 ret = core->ops->init(core->hw); in __clk_core_init()
3602 parent = core->parent = __clk_init_parent(core); in __clk_core_init()
3605 * Populate core->parent if parent has already been clk_core_init'd. If in __clk_core_init()
3615 hlist_add_head(&core->child_node, &parent->children); in __clk_core_init()
3616 core->orphan = parent->orphan; in __clk_core_init()
3617 } else if (!core->num_parents) { in __clk_core_init()
3618 hlist_add_head(&core->child_node, &clk_root_list); in __clk_core_init()
3619 core->orphan = false; in __clk_core_init()
3621 hlist_add_head(&core->child_node, &clk_orphan_list); in __clk_core_init()
3622 core->orphan = true; in __clk_core_init()
3632 if (core->ops->recalc_accuracy) in __clk_core_init()
3633 core->accuracy = core->ops->recalc_accuracy(core->hw, in __clk_core_init()
3636 core->accuracy = parent->accuracy; in __clk_core_init()
3638 core->accuracy = 0; in __clk_core_init()
3645 phase = clk_core_get_phase(core); in __clk_core_init()
3649 core->name); in __clk_core_init()
3656 clk_core_update_duty_cycle_nolock(core); in __clk_core_init()
3664 if (core->ops->recalc_rate) in __clk_core_init()
3665 rate = core->ops->recalc_rate(core->hw, in __clk_core_init()
3671 core->rate = core->req_rate = rate; in __clk_core_init()
3673 core->boot_enabled = clk_core_is_enabled(core); in __clk_core_init()
3680 if (core->flags & CLK_IS_CRITICAL) { in __clk_core_init()
3683 ret = clk_core_prepare(core); in __clk_core_init()
3686 __func__, core->name); in __clk_core_init()
3691 ret = clk_core_enable(core); in __clk_core_init()
3695 __func__, core->name); in __clk_core_init()
3696 clk_core_unprepare(core); in __clk_core_init()
3701 clk_core_hold_state(core); in __clk_core_init()
3705 kref_init(&core->ref); in __clk_core_init()
3707 clk_pm_runtime_put(core); in __clk_core_init()
3710 hlist_del_init(&core->child_node); in __clk_core_init()
3711 core->hw->core = NULL; in __clk_core_init()
3717 clk_debug_register(core); in __clk_core_init()
3724 * @core: clk to add consumer to
3727 static void clk_core_link_consumer(struct clk_core *core, struct clk *clk) in clk_core_link_consumer() argument
3730 hlist_add_head(&clk->clks_node, &core->clks); in clk_core_link_consumer()
3746 * @core: clk to allocate a consumer for
3752 static struct clk *alloc_clk(struct clk_core *core, const char *dev_id, in alloc_clk() argument
3761 clk->core = core; in alloc_clk()
3798 struct clk_core *core; in clk_hw_create_clk() local
3804 core = hw->core; in clk_hw_create_clk()
3805 clk = alloc_clk(core, dev_id, con_id); in clk_hw_create_clk()
3810 if (!try_module_get(core->owner)) { in clk_hw_create_clk()
3815 kref_get(&core->ref); in clk_hw_create_clk()
3816 clk_core_link_consumer(core, clk); in clk_hw_create_clk()
3833 struct device *dev = hw->core->dev; in clk_hw_get_clk()
3857 static int clk_core_populate_parent_map(struct clk_core *core, in clk_core_populate_parent_map() argument
3875 core->parents = parents; in clk_core_populate_parent_map()
3886 __func__, core->name); in clk_core_populate_parent_map()
3919 static void clk_core_free_parent_map(struct clk_core *core) in clk_core_free_parent_map() argument
3921 int i = core->num_parents; in clk_core_free_parent_map()
3923 if (!core->num_parents) in clk_core_free_parent_map()
3927 kfree_const(core->parents[i].name); in clk_core_free_parent_map()
3928 kfree_const(core->parents[i].fw_name); in clk_core_free_parent_map()
3931 kfree(core->parents); in clk_core_free_parent_map()
3938 struct clk_core *core; in __clk_register() local
3944 * we catch use of hw->init early on in the core. in __clk_register()
3948 core = kzalloc(sizeof(*core), GFP_KERNEL); in __clk_register()
3949 if (!core) { in __clk_register()
3954 core->name = kstrdup_const(init->name, GFP_KERNEL); in __clk_register()
3955 if (!core->name) { in __clk_register()
3964 core->ops = init->ops; in __clk_register()
3967 core->rpm_enabled = true; in __clk_register()
3968 core->dev = dev; in __clk_register()
3969 core->of_node = np; in __clk_register()
3971 core->owner = dev->driver->owner; in __clk_register()
3972 core->hw = hw; in __clk_register()
3973 core->flags = init->flags; in __clk_register()
3974 core->num_parents = init->num_parents; in __clk_register()
3975 core->min_rate = 0; in __clk_register()
3976 core->max_rate = ULONG_MAX; in __clk_register()
3978 ret = clk_core_populate_parent_map(core, init); in __clk_register()
3982 INIT_HLIST_HEAD(&core->clks); in __clk_register()
3988 hw->clk = alloc_clk(core, NULL, NULL); in __clk_register()
3994 clk_core_link_consumer(core, hw->clk); in __clk_register()
3996 ret = __clk_core_init(core); in __clk_register()
4008 clk_core_free_parent_map(core); in __clk_register()
4011 kfree_const(core->name); in __clk_register()
4013 kfree(core); in __clk_register()
4096 struct clk_core *core = container_of(ref, struct clk_core, ref); in __clk_release() local
4100 clk_core_free_parent_map(core); in __clk_release()
4101 kfree_const(core->name); in __clk_release()
4102 kfree(core); in __clk_release()
4147 if (root->parents[i].core == target) in clk_core_evict_parent_cache_subtree()
4148 root->parents[i].core = NULL; in clk_core_evict_parent_cache_subtree()
4155 static void clk_core_evict_parent_cache(struct clk_core *core) in clk_core_evict_parent_cache() argument
4164 clk_core_evict_parent_cache_subtree(root, core); in clk_core_evict_parent_cache()
4180 clk_debug_unregister(clk->core); in clk_unregister()
4184 ops = clk->core->ops; in clk_unregister()
4187 clk->core->name); in clk_unregister()
4195 clk->core->ops = &clk_nodrv_ops; in clk_unregister()
4199 ops->terminate(clk->core->hw); in clk_unregister()
4201 if (!hlist_empty(&clk->core->children)) { in clk_unregister()
4206 hlist_for_each_entry_safe(child, t, &clk->core->children, in clk_unregister()
4211 clk_core_evict_parent_cache(clk->core); in clk_unregister()
4213 hlist_del_init(&clk->core->child_node); in clk_unregister()
4215 if (clk->core->prepare_count) in clk_unregister()
4217 __func__, clk->core->name); in clk_unregister()
4219 if (clk->core->protect_count) in clk_unregister()
4221 __func__, clk->core->name); in clk_unregister()
4223 kref_put(&clk->core->ref, __clk_release); in clk_unregister()
4384 WARN_ON_ONCE(dev != hw->core->dev); in devm_clk_hw_get_clk()
4422 clk->core->protect_count -= (clk->exclusive_count - 1); in __clk_put()
4423 clk_core_rate_unprotect(clk->core); in __clk_put()
4428 if (clk->min_rate > clk->core->req_rate || in __clk_put()
4429 clk->max_rate < clk->core->req_rate) in __clk_put()
4430 clk_core_set_rate_nolock(clk->core, clk->core->req_rate); in __clk_put()
4432 owner = clk->core->owner; in __clk_put()
4433 kref_put(&clk->core->ref, __clk_release); in __clk_put()
4492 clk->core->notifier_count++; in clk_notifier_register()
4526 clk->core->notifier_count--; in clk_notifier_unregister()
5304 struct clk_core *core; in clk_rate_write() local
5319 core = clk_core_lookup(clk_name); in clk_rate_write()
5320 if (IS_ERR_OR_NULL(core)) { in clk_rate_write()
5326 ret = clk_core_set_rate_nolock(core, val); in clk_rate_write()
5363 struct clk_core *core; in clk_enable_write() local
5378 core = clk_core_lookup(clk_name); in clk_enable_write()
5379 if (IS_ERR_OR_NULL(core)) { in clk_enable_write()
5385 ret = clk_core_prepare_enable(core); in clk_enable_write()
5389 clk_core_disable_unprepare(core); in clk_enable_write()
5422 struct clk_core *core, *p; in clk_parent_write() local
5437 core = clk_core_lookup(clk_name); in clk_parent_write()
5438 if (IS_ERR_OR_NULL(core)) { in clk_parent_write()
5448 ret = clk_core_set_parent_nolock(core, p); in clk_parent_write()