aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clk/clk.c')
-rw-r--r--drivers/clk/clk.c131
1 files changed, 111 insertions, 20 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index c42e608af6bb..dff0373f53c1 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -277,6 +277,10 @@ static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry)
277 if (!d) 277 if (!d)
278 goto err_out; 278 goto err_out;
279 279
280 if (clk->ops->debug_init)
281 if (clk->ops->debug_init(clk->hw, clk->dentry))
282 goto err_out;
283
280 ret = 0; 284 ret = 0;
281 goto out; 285 goto out;
282 286
@@ -1339,8 +1343,11 @@ static int __clk_speculate_rates(struct clk *clk, unsigned long parent_rate)
1339 if (clk->notifier_count) 1343 if (clk->notifier_count)
1340 ret = __clk_notify(clk, PRE_RATE_CHANGE, clk->rate, new_rate); 1344 ret = __clk_notify(clk, PRE_RATE_CHANGE, clk->rate, new_rate);
1341 1345
1342 if (ret & NOTIFY_STOP_MASK) 1346 if (ret & NOTIFY_STOP_MASK) {
1347 pr_debug("%s: clk notifier callback for clock %s aborted with error %d\n",
1348 __func__, clk->name, ret);
1343 goto out; 1349 goto out;
1350 }
1344 1351
1345 hlist_for_each_entry(child, &clk->children, child_node) { 1352 hlist_for_each_entry(child, &clk->children, child_node) {
1346 ret = __clk_speculate_rates(child, new_rate); 1353 ret = __clk_speculate_rates(child, new_rate);
@@ -1588,7 +1595,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
1588 /* notify that we are about to change rates */ 1595 /* notify that we are about to change rates */
1589 fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE); 1596 fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE);
1590 if (fail_clk) { 1597 if (fail_clk) {
1591 pr_warn("%s: failed to set %s rate\n", __func__, 1598 pr_debug("%s: failed to set %s rate\n", __func__,
1592 fail_clk->name); 1599 fail_clk->name);
1593 clk_propagate_rate_change(top, ABORT_RATE_CHANGE); 1600 clk_propagate_rate_change(top, ABORT_RATE_CHANGE);
1594 ret = -EBUSY; 1601 ret = -EBUSY;
@@ -2260,20 +2267,11 @@ void __clk_put(struct clk *clk)
2260 * re-enter into the clk framework by calling any top-level clk APIs; 2267 * re-enter into the clk framework by calling any top-level clk APIs;
2261 * this will cause a nested prepare_lock mutex. 2268 * this will cause a nested prepare_lock mutex.
2262 * 2269 *
2263 * Pre-change notifier callbacks will be passed the current, pre-change 2270 * In all notification cases cases (pre, post and abort rate change) the
2264 * rate of the clk via struct clk_notifier_data.old_rate. The new, 2271 * original clock rate is passed to the callback via struct
2265 * post-change rate of the clk is passed via struct 2272 * clk_notifier_data.old_rate and the new frequency is passed via struct
2266 * clk_notifier_data.new_rate.
2267 *
2268 * Post-change notifiers will pass the now-current, post-change rate of
2269 * the clk in both struct clk_notifier_data.old_rate and struct
2270 * clk_notifier_data.new_rate. 2273 * clk_notifier_data.new_rate.
2271 * 2274 *
2272 * Abort-change notifiers are effectively the opposite of pre-change
2273 * notifiers: the original pre-change clk rate is passed in via struct
2274 * clk_notifier_data.new_rate and the failed post-change rate is passed
2275 * in via struct clk_notifier_data.old_rate.
2276 *
2277 * clk_notifier_register() must be called from non-atomic context. 2275 * clk_notifier_register() must be called from non-atomic context.
2278 * Returns -EINVAL if called with null arguments, -ENOMEM upon 2276 * Returns -EINVAL if called with null arguments, -ENOMEM upon
2279 * allocation failure; otherwise, passes along the return value of 2277 * allocation failure; otherwise, passes along the return value of
@@ -2473,7 +2471,7 @@ EXPORT_SYMBOL_GPL(of_clk_del_provider);
2473struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec) 2471struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec)
2474{ 2472{
2475 struct of_clk_provider *provider; 2473 struct of_clk_provider *provider;
2476 struct clk *clk = ERR_PTR(-ENOENT); 2474 struct clk *clk = ERR_PTR(-EPROBE_DEFER);
2477 2475
2478 /* Check if we have such a provider in our array */ 2476 /* Check if we have such a provider in our array */
2479 list_for_each_entry(provider, &of_clk_providers, link) { 2477 list_for_each_entry(provider, &of_clk_providers, link) {
@@ -2506,8 +2504,12 @@ EXPORT_SYMBOL_GPL(of_clk_get_parent_count);
2506const char *of_clk_get_parent_name(struct device_node *np, int index) 2504const char *of_clk_get_parent_name(struct device_node *np, int index)
2507{ 2505{
2508 struct of_phandle_args clkspec; 2506 struct of_phandle_args clkspec;
2507 struct property *prop;
2509 const char *clk_name; 2508 const char *clk_name;
2509 const __be32 *vp;
2510 u32 pv;
2510 int rc; 2511 int rc;
2512 int count;
2511 2513
2512 if (index < 0) 2514 if (index < 0)
2513 return NULL; 2515 return NULL;
@@ -2517,8 +2519,22 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
2517 if (rc) 2519 if (rc)
2518 return NULL; 2520 return NULL;
2519 2521
2522 index = clkspec.args_count ? clkspec.args[0] : 0;
2523 count = 0;
2524
2525 /* if there is an indices property, use it to transfer the index
2526 * specified into an array offset for the clock-output-names property.
2527 */
2528 of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) {
2529 if (index == pv) {
2530 index = count;
2531 break;
2532 }
2533 count++;
2534 }
2535
2520 if (of_property_read_string_index(clkspec.np, "clock-output-names", 2536 if (of_property_read_string_index(clkspec.np, "clock-output-names",
2521 clkspec.args_count ? clkspec.args[0] : 0, 2537 index,
2522 &clk_name) < 0) 2538 &clk_name) < 0)
2523 clk_name = clkspec.np->name; 2539 clk_name = clkspec.np->name;
2524 2540
@@ -2527,24 +2543,99 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
2527} 2543}
2528EXPORT_SYMBOL_GPL(of_clk_get_parent_name); 2544EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
2529 2545
2546struct clock_provider {
2547 of_clk_init_cb_t clk_init_cb;
2548 struct device_node *np;
2549 struct list_head node;
2550};
2551
2552static LIST_HEAD(clk_provider_list);
2553
2554/*
2555 * This function looks for a parent clock. If there is one, then it
2556 * checks that the provider for this parent clock was initialized, in
2557 * this case the parent clock will be ready.
2558 */
2559static int parent_ready(struct device_node *np)
2560{
2561 int i = 0;
2562
2563 while (true) {
2564 struct clk *clk = of_clk_get(np, i);
2565
2566 /* this parent is ready we can check the next one */
2567 if (!IS_ERR(clk)) {
2568 clk_put(clk);
2569 i++;
2570 continue;
2571 }
2572
2573 /* at least one parent is not ready, we exit now */
2574 if (PTR_ERR(clk) == -EPROBE_DEFER)
2575 return 0;
2576
2577 /*
2578 * Here we make assumption that the device tree is
2579 * written correctly. So an error means that there is
2580 * no more parent. As we didn't exit yet, then the
2581 * previous parent are ready. If there is no clock
2582 * parent, no need to wait for them, then we can
2583 * consider their absence as being ready
2584 */
2585 return 1;
2586 }
2587}
2588
2530/** 2589/**
2531 * of_clk_init() - Scan and init clock providers from the DT 2590 * of_clk_init() - Scan and init clock providers from the DT
2532 * @matches: array of compatible values and init functions for providers. 2591 * @matches: array of compatible values and init functions for providers.
2533 * 2592 *
2534 * This function scans the device tree for matching clock providers and 2593 * This function scans the device tree for matching clock providers
2535 * calls their initialization functions 2594 * and calls their initialization functions. It also does it by trying
2595 * to follow the dependencies.
2536 */ 2596 */
2537void __init of_clk_init(const struct of_device_id *matches) 2597void __init of_clk_init(const struct of_device_id *matches)
2538{ 2598{
2539 const struct of_device_id *match; 2599 const struct of_device_id *match;
2540 struct device_node *np; 2600 struct device_node *np;
2601 struct clock_provider *clk_provider, *next;
2602 bool is_init_done;
2603 bool force = false;
2541 2604
2542 if (!matches) 2605 if (!matches)
2543 matches = &__clk_of_table; 2606 matches = &__clk_of_table;
2544 2607
2608 /* First prepare the list of the clocks providers */
2545 for_each_matching_node_and_match(np, matches, &match) { 2609 for_each_matching_node_and_match(np, matches, &match) {
2546 of_clk_init_cb_t clk_init_cb = match->data; 2610 struct clock_provider *parent =
2547 clk_init_cb(np); 2611 kzalloc(sizeof(struct clock_provider), GFP_KERNEL);
2612
2613 parent->clk_init_cb = match->data;
2614 parent->np = np;
2615 list_add_tail(&parent->node, &clk_provider_list);
2616 }
2617
2618 while (!list_empty(&clk_provider_list)) {
2619 is_init_done = false;
2620 list_for_each_entry_safe(clk_provider, next,
2621 &clk_provider_list, node) {
2622 if (force || parent_ready(clk_provider->np)) {
2623 clk_provider->clk_init_cb(clk_provider->np);
2624 list_del(&clk_provider->node);
2625 kfree(clk_provider);
2626 is_init_done = true;
2627 }
2628 }
2629
2630 /*
2631 * We didn't manage to initialize any of the
2632 * remaining providers during the last loop, so now we
2633 * initialize all the remaining ones unconditionally
2634 * in case the clock parent was not mandatory
2635 */
2636 if (!is_init_done)
2637 force = true;
2638
2548 } 2639 }
2549} 2640}
2550#endif 2641#endif