clk.c (962a70d05edac2e2eb53cd077715930083964b9e) clk.c (73e0e496afdac9a5190eb3b9c51fdfebcc14ebd4)
1/*
2 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
3 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Standard functionality for the common clock API. See Documentation/clk.txt
10 */
11
1/*
2 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
3 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Standard functionality for the common clock API. See Documentation/clk.txt
10 */
11
12#include <linux/clk-private.h>
12#include <linux/clk-provider.h>
13#include <linux/clk/clk-conf.h>
14#include <linux/module.h>
15#include <linux/mutex.h>
16#include <linux/spinlock.h>
17#include <linux/err.h>
18#include <linux/list.h>
19#include <linux/slab.h>
20#include <linux/of.h>

--- 11 unchanged lines hidden (view full) ---

32
33static int prepare_refcnt;
34static int enable_refcnt;
35
36static HLIST_HEAD(clk_root_list);
37static HLIST_HEAD(clk_orphan_list);
38static LIST_HEAD(clk_notifier_list);
39
13#include <linux/clk/clk-conf.h>
14#include <linux/module.h>
15#include <linux/mutex.h>
16#include <linux/spinlock.h>
17#include <linux/err.h>
18#include <linux/list.h>
19#include <linux/slab.h>
20#include <linux/of.h>

--- 11 unchanged lines hidden (view full) ---

32
33static int prepare_refcnt;
34static int enable_refcnt;
35
36static HLIST_HEAD(clk_root_list);
37static HLIST_HEAD(clk_orphan_list);
38static LIST_HEAD(clk_notifier_list);
39
40static long clk_core_get_accuracy(struct clk_core *clk);
41static unsigned long clk_core_get_rate(struct clk_core *clk);
42static int clk_core_get_phase(struct clk_core *clk);
43static bool clk_core_is_prepared(struct clk_core *clk);
44static bool clk_core_is_enabled(struct clk_core *clk);
45static struct clk_core *clk_core_lookup(const char *name);
46
47/*** private data structures ***/
48
49struct clk_core {
50 const char *name;
51 const struct clk_ops *ops;
52 struct clk_hw *hw;
53 struct module *owner;
54 struct clk_core *parent;
55 const char **parent_names;
56 struct clk_core **parents;
57 u8 num_parents;
58 u8 new_parent_index;
59 unsigned long rate;
60 unsigned long req_rate;
61 unsigned long new_rate;
62 struct clk_core *new_parent;
63 struct clk_core *new_child;
64 unsigned long flags;
65 unsigned int enable_count;
66 unsigned int prepare_count;
67 unsigned long accuracy;
68 int phase;
69 struct hlist_head children;
70 struct hlist_node child_node;
71 struct hlist_node debug_node;
72 struct hlist_head clks;
73 unsigned int notifier_count;
74#ifdef CONFIG_DEBUG_FS
75 struct dentry *dentry;
76#endif
77 struct kref ref;
78};
79
80struct clk {
81 struct clk_core *core;
82 const char *dev_id;
83 const char *con_id;
84 unsigned long min_rate;
85 unsigned long max_rate;
86 struct hlist_node child_node;
87};
88
40/*** locking ***/
41static void clk_prepare_lock(void)
42{
43 if (!mutex_trylock(&prepare_lock)) {
44 if (prepare_owner == current) {
45 prepare_refcnt++;
46 return;
47 }

--- 61 unchanged lines hidden (view full) ---

109 NULL,
110};
111
112static struct hlist_head *orphan_list[] = {
113 &clk_orphan_list,
114 NULL,
115};
116
89/*** locking ***/
90static void clk_prepare_lock(void)
91{
92 if (!mutex_trylock(&prepare_lock)) {
93 if (prepare_owner == current) {
94 prepare_refcnt++;
95 return;
96 }

--- 61 unchanged lines hidden (view full) ---

158 NULL,
159};
160
161static struct hlist_head *orphan_list[] = {
162 &clk_orphan_list,
163 NULL,
164};
165
117static void clk_summary_show_one(struct seq_file *s, struct clk *c, int level)
166static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
167 int level)
118{
119 if (!c)
120 return;
121
122 seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu %-3d\n",
123 level * 3 + 1, "",
124 30 - level * 3, c->name,
168{
169 if (!c)
170 return;
171
172 seq_printf(s, "%*s%-*s %11d %12d %11lu %10lu %-3d\n",
173 level * 3 + 1, "",
174 30 - level * 3, c->name,
125 c->enable_count, c->prepare_count, clk_get_rate(c),
126 clk_get_accuracy(c), clk_get_phase(c));
175 c->enable_count, c->prepare_count, clk_core_get_rate(c),
176 clk_core_get_accuracy(c), clk_core_get_phase(c));
127}
128
177}
178
129static void clk_summary_show_subtree(struct seq_file *s, struct clk *c,
179static void clk_summary_show_subtree(struct seq_file *s, struct clk_core *c,
130 int level)
131{
180 int level)
181{
132 struct clk *child;
182 struct clk_core *child;
133
134 if (!c)
135 return;
136
137 clk_summary_show_one(s, c, level);
138
139 hlist_for_each_entry(child, &c->children, child_node)
140 clk_summary_show_subtree(s, child, level + 1);
141}
142
143static int clk_summary_show(struct seq_file *s, void *data)
144{
183
184 if (!c)
185 return;
186
187 clk_summary_show_one(s, c, level);
188
189 hlist_for_each_entry(child, &c->children, child_node)
190 clk_summary_show_subtree(s, child, level + 1);
191}
192
193static int clk_summary_show(struct seq_file *s, void *data)
194{
145 struct clk *c;
195 struct clk_core *c;
146 struct hlist_head **lists = (struct hlist_head **)s->private;
147
148 seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n");
149 seq_puts(s, "----------------------------------------------------------------------------------------\n");
150
151 clk_prepare_lock();
152
153 for (; *lists; lists++)

--- 13 unchanged lines hidden (view full) ---

167
168static const struct file_operations clk_summary_fops = {
169 .open = clk_summary_open,
170 .read = seq_read,
171 .llseek = seq_lseek,
172 .release = single_release,
173};
174
196 struct hlist_head **lists = (struct hlist_head **)s->private;
197
198 seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n");
199 seq_puts(s, "----------------------------------------------------------------------------------------\n");
200
201 clk_prepare_lock();
202
203 for (; *lists; lists++)

--- 13 unchanged lines hidden (view full) ---

217
218static const struct file_operations clk_summary_fops = {
219 .open = clk_summary_open,
220 .read = seq_read,
221 .llseek = seq_lseek,
222 .release = single_release,
223};
224
175static void clk_dump_one(struct seq_file *s, struct clk *c, int level)
225static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
176{
177 if (!c)
178 return;
179
180 seq_printf(s, "\"%s\": { ", c->name);
181 seq_printf(s, "\"enable_count\": %d,", c->enable_count);
182 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count);
226{
227 if (!c)
228 return;
229
230 seq_printf(s, "\"%s\": { ", c->name);
231 seq_printf(s, "\"enable_count\": %d,", c->enable_count);
232 seq_printf(s, "\"prepare_count\": %d,", c->prepare_count);
183 seq_printf(s, "\"rate\": %lu", clk_get_rate(c));
184 seq_printf(s, "\"accuracy\": %lu", clk_get_accuracy(c));
185 seq_printf(s, "\"phase\": %d", clk_get_phase(c));
233 seq_printf(s, "\"rate\": %lu", clk_core_get_rate(c));
234 seq_printf(s, "\"accuracy\": %lu", clk_core_get_accuracy(c));
235 seq_printf(s, "\"phase\": %d", clk_core_get_phase(c));
186}
187
236}
237
188static void clk_dump_subtree(struct seq_file *s, struct clk *c, int level)
238static void clk_dump_subtree(struct seq_file *s, struct clk_core *c, int level)
189{
239{
190 struct clk *child;
240 struct clk_core *child;
191
192 if (!c)
193 return;
194
195 clk_dump_one(s, c, level);
196
197 hlist_for_each_entry(child, &c->children, child_node) {
198 seq_printf(s, ",");
199 clk_dump_subtree(s, child, level + 1);
200 }
201
202 seq_printf(s, "}");
203}
204
205static int clk_dump(struct seq_file *s, void *data)
206{
241
242 if (!c)
243 return;
244
245 clk_dump_one(s, c, level);
246
247 hlist_for_each_entry(child, &c->children, child_node) {
248 seq_printf(s, ",");
249 clk_dump_subtree(s, child, level + 1);
250 }
251
252 seq_printf(s, "}");
253}
254
255static int clk_dump(struct seq_file *s, void *data)
256{
207 struct clk *c;
257 struct clk_core *c;
208 bool first_node = true;
209 struct hlist_head **lists = (struct hlist_head **)s->private;
210
211 seq_printf(s, "{");
212
213 clk_prepare_lock();
214
215 for (; *lists; lists++) {

--- 19 unchanged lines hidden (view full) ---

235
236static const struct file_operations clk_dump_fops = {
237 .open = clk_dump_open,
238 .read = seq_read,
239 .llseek = seq_lseek,
240 .release = single_release,
241};
242
258 bool first_node = true;
259 struct hlist_head **lists = (struct hlist_head **)s->private;
260
261 seq_printf(s, "{");
262
263 clk_prepare_lock();
264
265 for (; *lists; lists++) {

--- 19 unchanged lines hidden (view full) ---

285
286static const struct file_operations clk_dump_fops = {
287 .open = clk_dump_open,
288 .read = seq_read,
289 .llseek = seq_lseek,
290 .release = single_release,
291};
292
243static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry)
293static int clk_debug_create_one(struct clk_core *clk, struct dentry *pdentry)
244{
245 struct dentry *d;
246 int ret = -ENOMEM;
247
248 if (!clk || !pdentry) {
249 ret = -EINVAL;
250 goto out;
251 }

--- 58 unchanged lines hidden (view full) ---

310/**
311 * clk_debug_register - add a clk node to the debugfs clk tree
312 * @clk: the clk being added to the debugfs clk tree
313 *
314 * Dynamically adds a clk to the debugfs clk tree if debugfs has been
315 * initialized. Otherwise it bails out early since the debugfs clk tree
316 * will be created lazily by clk_debug_init as part of a late_initcall.
317 */
294{
295 struct dentry *d;
296 int ret = -ENOMEM;
297
298 if (!clk || !pdentry) {
299 ret = -EINVAL;
300 goto out;
301 }

--- 58 unchanged lines hidden (view full) ---

360/**
361 * clk_debug_register - add a clk node to the debugfs clk tree
362 * @clk: the clk being added to the debugfs clk tree
363 *
364 * Dynamically adds a clk to the debugfs clk tree if debugfs has been
365 * initialized. Otherwise it bails out early since the debugfs clk tree
366 * will be created lazily by clk_debug_init as part of a late_initcall.
367 */
318static int clk_debug_register(struct clk *clk)
368static int clk_debug_register(struct clk_core *clk)
319{
320 int ret = 0;
321
322 mutex_lock(&clk_debug_lock);
323 hlist_add_head(&clk->debug_node, &clk_debug_list);
324
325 if (!inited)
326 goto unlock;

--- 8 unchanged lines hidden (view full) ---

335 /**
336 * clk_debug_unregister - remove a clk node from the debugfs clk tree
337 * @clk: the clk being removed from the debugfs clk tree
338 *
339 * Dynamically removes a clk and all it's children clk nodes from the
340 * debugfs clk tree if clk->dentry points to debugfs created by
341 * clk_debug_register in __clk_init.
342 */
369{
370 int ret = 0;
371
372 mutex_lock(&clk_debug_lock);
373 hlist_add_head(&clk->debug_node, &clk_debug_list);
374
375 if (!inited)
376 goto unlock;

--- 8 unchanged lines hidden (view full) ---

385 /**
386 * clk_debug_unregister - remove a clk node from the debugfs clk tree
387 * @clk: the clk being removed from the debugfs clk tree
388 *
389 * Dynamically removes a clk and all it's children clk nodes from the
390 * debugfs clk tree if clk->dentry points to debugfs created by
391 * clk_debug_register in __clk_init.
392 */
343static void clk_debug_unregister(struct clk *clk)
393static void clk_debug_unregister(struct clk_core *clk)
344{
345 mutex_lock(&clk_debug_lock);
394{
395 mutex_lock(&clk_debug_lock);
346 if (!clk->dentry)
347 goto out;
348
349 hlist_del_init(&clk->debug_node);
350 debugfs_remove_recursive(clk->dentry);
351 clk->dentry = NULL;
396 hlist_del_init(&clk->debug_node);
397 debugfs_remove_recursive(clk->dentry);
398 clk->dentry = NULL;
352out:
353 mutex_unlock(&clk_debug_lock);
354}
355
356struct dentry *clk_debugfs_add_file(struct clk_hw *hw, char *name, umode_t mode,
357 void *data, const struct file_operations *fops)
358{
359 struct dentry *d = NULL;
360
399 mutex_unlock(&clk_debug_lock);
400}
401
402struct dentry *clk_debugfs_add_file(struct clk_hw *hw, char *name, umode_t mode,
403 void *data, const struct file_operations *fops)
404{
405 struct dentry *d = NULL;
406
361 if (hw->clk->dentry)
362 d = debugfs_create_file(name, mode, hw->clk->dentry, data, fops);
407 if (hw->core->dentry)
408 d = debugfs_create_file(name, mode, hw->core->dentry, data,
409 fops);
363
364 return d;
365}
366EXPORT_SYMBOL_GPL(clk_debugfs_add_file);
367
368/**
369 * clk_debug_init - lazily create the debugfs clk tree visualization
370 *
371 * clks are often initialized very early during boot before memory can
372 * be dynamically allocated and well before debugfs is setup.
373 * clk_debug_init walks the clk tree hierarchy while holding
374 * prepare_lock and creates the topology as part of a late_initcall,
375 * thus insuring that clks initialized very early will still be
376 * represented in the debugfs clk tree. This function should only be
377 * called once at boot-time, and all other clks added dynamically will
378 * be done so with clk_debug_register.
379 */
380static int __init clk_debug_init(void)
381{
410
411 return d;
412}
413EXPORT_SYMBOL_GPL(clk_debugfs_add_file);
414
415/**
416 * clk_debug_init - lazily create the debugfs clk tree visualization
417 *
418 * clks are often initialized very early during boot before memory can
419 * be dynamically allocated and well before debugfs is setup.
420 * clk_debug_init walks the clk tree hierarchy while holding
421 * prepare_lock and creates the topology as part of a late_initcall,
422 * thus insuring that clks initialized very early will still be
423 * represented in the debugfs clk tree. This function should only be
424 * called once at boot-time, and all other clks added dynamically will
425 * be done so with clk_debug_register.
426 */
427static int __init clk_debug_init(void)
428{
382 struct clk *clk;
429 struct clk_core *clk;
383 struct dentry *d;
384
385 rootdir = debugfs_create_dir("clk", NULL);
386
387 if (!rootdir)
388 return -ENOMEM;
389
390 d = debugfs_create_file("clk_summary", S_IRUGO, rootdir, &all_lists,

--- 22 unchanged lines hidden (view full) ---

413
414 inited = 1;
415 mutex_unlock(&clk_debug_lock);
416
417 return 0;
418}
419late_initcall(clk_debug_init);
420#else
430 struct dentry *d;
431
432 rootdir = debugfs_create_dir("clk", NULL);
433
434 if (!rootdir)
435 return -ENOMEM;
436
437 d = debugfs_create_file("clk_summary", S_IRUGO, rootdir, &all_lists,

--- 22 unchanged lines hidden (view full) ---

460
461 inited = 1;
462 mutex_unlock(&clk_debug_lock);
463
464 return 0;
465}
466late_initcall(clk_debug_init);
467#else
421static inline int clk_debug_register(struct clk *clk) { return 0; }
422static inline void clk_debug_reparent(struct clk *clk, struct clk *new_parent)
468static inline int clk_debug_register(struct clk_core *clk) { return 0; }
469static inline void clk_debug_reparent(struct clk_core *clk,
470 struct clk_core *new_parent)
423{
424}
471{
472}
425static inline void clk_debug_unregister(struct clk *clk)
473static inline void clk_debug_unregister(struct clk_core *clk)
426{
427}
428#endif
429
430/* caller must hold prepare_lock */
474{
475}
476#endif
477
478/* caller must hold prepare_lock */
431static void clk_unprepare_unused_subtree(struct clk *clk)
479static void clk_unprepare_unused_subtree(struct clk_core *clk)
432{
480{
433 struct clk *child;
481 struct clk_core *child;
434
482
435 if (!clk)
436 return;
437
438 hlist_for_each_entry(child, &clk->children, child_node)
439 clk_unprepare_unused_subtree(child);
440
441 if (clk->prepare_count)
442 return;
443
444 if (clk->flags & CLK_IGNORE_UNUSED)
445 return;
446
483 hlist_for_each_entry(child, &clk->children, child_node)
484 clk_unprepare_unused_subtree(child);
485
486 if (clk->prepare_count)
487 return;
488
489 if (clk->flags & CLK_IGNORE_UNUSED)
490 return;
491
447 if (__clk_is_prepared(clk)) {
492 if (clk_core_is_prepared(clk)) {
448 if (clk->ops->unprepare_unused)
449 clk->ops->unprepare_unused(clk->hw);
450 else if (clk->ops->unprepare)
451 clk->ops->unprepare(clk->hw);
452 }
453}
454
455/* caller must hold prepare_lock */
493 if (clk->ops->unprepare_unused)
494 clk->ops->unprepare_unused(clk->hw);
495 else if (clk->ops->unprepare)
496 clk->ops->unprepare(clk->hw);
497 }
498}
499
500/* caller must hold prepare_lock */
456static void clk_disable_unused_subtree(struct clk *clk)
501static void clk_disable_unused_subtree(struct clk_core *clk)
457{
502{
458 struct clk *child;
503 struct clk_core *child;
459 unsigned long flags;
460
504 unsigned long flags;
505
461 if (!clk)
462 goto out;
463
464 hlist_for_each_entry(child, &clk->children, child_node)
465 clk_disable_unused_subtree(child);
466
467 flags = clk_enable_lock();
468
469 if (clk->enable_count)
470 goto unlock_out;
471
472 if (clk->flags & CLK_IGNORE_UNUSED)
473 goto unlock_out;
474
475 /*
476 * some gate clocks have special needs during the disable-unused
477 * sequence. call .disable_unused if available, otherwise fall
478 * back to .disable
479 */
506 hlist_for_each_entry(child, &clk->children, child_node)
507 clk_disable_unused_subtree(child);
508
509 flags = clk_enable_lock();
510
511 if (clk->enable_count)
512 goto unlock_out;
513
514 if (clk->flags & CLK_IGNORE_UNUSED)
515 goto unlock_out;
516
517 /*
518 * some gate clocks have special needs during the disable-unused
519 * sequence. call .disable_unused if available, otherwise fall
520 * back to .disable
521 */
480 if (__clk_is_enabled(clk)) {
522 if (clk_core_is_enabled(clk)) {
481 if (clk->ops->disable_unused)
482 clk->ops->disable_unused(clk->hw);
483 else if (clk->ops->disable)
484 clk->ops->disable(clk->hw);
485 }
486
487unlock_out:
488 clk_enable_unlock(flags);
523 if (clk->ops->disable_unused)
524 clk->ops->disable_unused(clk->hw);
525 else if (clk->ops->disable)
526 clk->ops->disable(clk->hw);
527 }
528
529unlock_out:
530 clk_enable_unlock(flags);
489
490out:
491 return;
492}
493
494static bool clk_ignore_unused;
495static int __init clk_ignore_unused_setup(char *__unused)
496{
497 clk_ignore_unused = true;
498 return 1;
499}
500__setup("clk_ignore_unused", clk_ignore_unused_setup);
501
502static int clk_disable_unused(void)
503{
531}
532
533static bool clk_ignore_unused;
534static int __init clk_ignore_unused_setup(char *__unused)
535{
536 clk_ignore_unused = true;
537 return 1;
538}
539__setup("clk_ignore_unused", clk_ignore_unused_setup);
540
541static int clk_disable_unused(void)
542{
504 struct clk *clk;
543 struct clk_core *clk;
505
506 if (clk_ignore_unused) {
507 pr_warn("clk: Not disabling unused clocks\n");
508 return 0;
509 }
510
511 clk_prepare_lock();
512

--- 14 unchanged lines hidden (view full) ---

527 return 0;
528}
529late_initcall_sync(clk_disable_unused);
530
531/*** helper functions ***/
532
533const char *__clk_get_name(struct clk *clk)
534{
544
545 if (clk_ignore_unused) {
546 pr_warn("clk: Not disabling unused clocks\n");
547 return 0;
548 }
549
550 clk_prepare_lock();
551

--- 14 unchanged lines hidden (view full) ---

566 return 0;
567}
568late_initcall_sync(clk_disable_unused);
569
570/*** helper functions ***/
571
572const char *__clk_get_name(struct clk *clk)
573{
535 return !clk ? NULL : clk->name;
574 return !clk ? NULL : clk->core->name;
536}
537EXPORT_SYMBOL_GPL(__clk_get_name);
538
539struct clk_hw *__clk_get_hw(struct clk *clk)
540{
575}
576EXPORT_SYMBOL_GPL(__clk_get_name);
577
578struct clk_hw *__clk_get_hw(struct clk *clk)
579{
541 return !clk ? NULL : clk->hw;
580 return !clk ? NULL : clk->core->hw;
542}
543EXPORT_SYMBOL_GPL(__clk_get_hw);
544
545u8 __clk_get_num_parents(struct clk *clk)
546{
581}
582EXPORT_SYMBOL_GPL(__clk_get_hw);
583
584u8 __clk_get_num_parents(struct clk *clk)
585{
547 return !clk ? 0 : clk->num_parents;
586 return !clk ? 0 : clk->core->num_parents;
548}
549EXPORT_SYMBOL_GPL(__clk_get_num_parents);
550
551struct clk *__clk_get_parent(struct clk *clk)
552{
587}
588EXPORT_SYMBOL_GPL(__clk_get_num_parents);
589
590struct clk *__clk_get_parent(struct clk *clk)
591{
553 return !clk ? NULL : clk->parent;
592 if (!clk)
593 return NULL;
594
595 /* TODO: Create a per-user clk and change callers to call clk_put */
596 return !clk->core->parent ? NULL : clk->core->parent->hw->clk;
554}
555EXPORT_SYMBOL_GPL(__clk_get_parent);
556
597}
598EXPORT_SYMBOL_GPL(__clk_get_parent);
599
557struct clk *clk_get_parent_by_index(struct clk *clk, u8 index)
600static struct clk_core *clk_core_get_parent_by_index(struct clk_core *clk,
601 u8 index)
558{
559 if (!clk || index >= clk->num_parents)
560 return NULL;
561 else if (!clk->parents)
602{
603 if (!clk || index >= clk->num_parents)
604 return NULL;
605 else if (!clk->parents)
562 return __clk_lookup(clk->parent_names[index]);
606 return clk_core_lookup(clk->parent_names[index]);
563 else if (!clk->parents[index])
564 return clk->parents[index] =
607 else if (!clk->parents[index])
608 return clk->parents[index] =
565 __clk_lookup(clk->parent_names[index]);
609 clk_core_lookup(clk->parent_names[index]);
566 else
567 return clk->parents[index];
568}
610 else
611 return clk->parents[index];
612}
613
614struct clk *clk_get_parent_by_index(struct clk *clk, u8 index)
615{
616 struct clk_core *parent;
617
618 if (!clk)
619 return NULL;
620
621 parent = clk_core_get_parent_by_index(clk->core, index);
622
623 return !parent ? NULL : parent->hw->clk;
624}
569EXPORT_SYMBOL_GPL(clk_get_parent_by_index);
570
571unsigned int __clk_get_enable_count(struct clk *clk)
572{
625EXPORT_SYMBOL_GPL(clk_get_parent_by_index);
626
627unsigned int __clk_get_enable_count(struct clk *clk)
628{
573 return !clk ? 0 : clk->enable_count;
629 return !clk ? 0 : clk->core->enable_count;
574}
575
630}
631
576unsigned long __clk_get_rate(struct clk *clk)
632static unsigned long clk_core_get_rate_nolock(struct clk_core *clk)
577{
578 unsigned long ret;
579
580 if (!clk) {
581 ret = 0;
582 goto out;
583 }
584
585 ret = clk->rate;
586
587 if (clk->flags & CLK_IS_ROOT)
588 goto out;
589
590 if (!clk->parent)
591 ret = 0;
592
593out:
594 return ret;
595}
633{
634 unsigned long ret;
635
636 if (!clk) {
637 ret = 0;
638 goto out;
639 }
640
641 ret = clk->rate;
642
643 if (clk->flags & CLK_IS_ROOT)
644 goto out;
645
646 if (!clk->parent)
647 ret = 0;
648
649out:
650 return ret;
651}
652
653unsigned long __clk_get_rate(struct clk *clk)
654{
655 if (!clk)
656 return 0;
657
658 return clk_core_get_rate_nolock(clk->core);
659}
596EXPORT_SYMBOL_GPL(__clk_get_rate);
597
660EXPORT_SYMBOL_GPL(__clk_get_rate);
661
598static unsigned long __clk_get_accuracy(struct clk *clk)
662static unsigned long __clk_get_accuracy(struct clk_core *clk)
599{
600 if (!clk)
601 return 0;
602
603 return clk->accuracy;
604}
605
606unsigned long __clk_get_flags(struct clk *clk)
607{
663{
664 if (!clk)
665 return 0;
666
667 return clk->accuracy;
668}
669
670unsigned long __clk_get_flags(struct clk *clk)
671{
608 return !clk ? 0 : clk->flags;
672 return !clk ? 0 : clk->core->flags;
609}
610EXPORT_SYMBOL_GPL(__clk_get_flags);
611
673}
674EXPORT_SYMBOL_GPL(__clk_get_flags);
675
612bool __clk_is_prepared(struct clk *clk)
676static bool clk_core_is_prepared(struct clk_core *clk)
613{
614 int ret;
615
616 if (!clk)
617 return false;
618
619 /*
620 * .is_prepared is optional for clocks that can prepare

--- 4 unchanged lines hidden (view full) ---

625 goto out;
626 }
627
628 ret = clk->ops->is_prepared(clk->hw);
629out:
630 return !!ret;
631}
632
677{
678 int ret;
679
680 if (!clk)
681 return false;
682
683 /*
684 * .is_prepared is optional for clocks that can prepare

--- 4 unchanged lines hidden (view full) ---

689 goto out;
690 }
691
692 ret = clk->ops->is_prepared(clk->hw);
693out:
694 return !!ret;
695}
696
633bool __clk_is_enabled(struct clk *clk)
697bool __clk_is_prepared(struct clk *clk)
634{
698{
699 if (!clk)
700 return false;
701
702 return clk_core_is_prepared(clk->core);
703}
704
705static bool clk_core_is_enabled(struct clk_core *clk)
706{
635 int ret;
636
637 if (!clk)
638 return false;
639
640 /*
641 * .is_enabled is only mandatory for clocks that gate
642 * fall back to software usage counter if .is_enabled is missing
643 */
644 if (!clk->ops->is_enabled) {
645 ret = clk->enable_count ? 1 : 0;
646 goto out;
647 }
648
649 ret = clk->ops->is_enabled(clk->hw);
650out:
651 return !!ret;
652}
707 int ret;
708
709 if (!clk)
710 return false;
711
712 /*
713 * .is_enabled is only mandatory for clocks that gate
714 * fall back to software usage counter if .is_enabled is missing
715 */
716 if (!clk->ops->is_enabled) {
717 ret = clk->enable_count ? 1 : 0;
718 goto out;
719 }
720
721 ret = clk->ops->is_enabled(clk->hw);
722out:
723 return !!ret;
724}
725
726bool __clk_is_enabled(struct clk *clk)
727{
728 if (!clk)
729 return false;
730
731 return clk_core_is_enabled(clk->core);
732}
653EXPORT_SYMBOL_GPL(__clk_is_enabled);
654
733EXPORT_SYMBOL_GPL(__clk_is_enabled);
734
655static struct clk *__clk_lookup_subtree(const char *name, struct clk *clk)
735static struct clk_core *__clk_lookup_subtree(const char *name,
736 struct clk_core *clk)
656{
737{
657 struct clk *child;
658 struct clk *ret;
738 struct clk_core *child;
739 struct clk_core *ret;
659
660 if (!strcmp(clk->name, name))
661 return clk;
662
663 hlist_for_each_entry(child, &clk->children, child_node) {
664 ret = __clk_lookup_subtree(name, child);
665 if (ret)
666 return ret;
667 }
668
669 return NULL;
670}
671
740
741 if (!strcmp(clk->name, name))
742 return clk;
743
744 hlist_for_each_entry(child, &clk->children, child_node) {
745 ret = __clk_lookup_subtree(name, child);
746 if (ret)
747 return ret;
748 }
749
750 return NULL;
751}
752
672struct clk *__clk_lookup(const char *name)
753static struct clk_core *clk_core_lookup(const char *name)
673{
754{
674 struct clk *root_clk;
675 struct clk *ret;
755 struct clk_core *root_clk;
756 struct clk_core *ret;
676
677 if (!name)
678 return NULL;
679
680 /* search the 'proper' clk tree first */
681 hlist_for_each_entry(root_clk, &clk_root_list, child_node) {
682 ret = __clk_lookup_subtree(name, root_clk);
683 if (ret)

--- 5 unchanged lines hidden (view full) ---

689 ret = __clk_lookup_subtree(name, root_clk);
690 if (ret)
691 return ret;
692 }
693
694 return NULL;
695}
696
757
758 if (!name)
759 return NULL;
760
761 /* search the 'proper' clk tree first */
762 hlist_for_each_entry(root_clk, &clk_root_list, child_node) {
763 ret = __clk_lookup_subtree(name, root_clk);
764 if (ret)

--- 5 unchanged lines hidden (view full) ---

770 ret = __clk_lookup_subtree(name, root_clk);
771 if (ret)
772 return ret;
773 }
774
775 return NULL;
776}
777
697/*
698 * Helper for finding best parent to provide a given frequency. This can be used
699 * directly as a determine_rate callback (e.g. for a mux), or from a more
700 * complex clock that may combine a mux with other operations.
701 */
702long __clk_mux_determine_rate(struct clk_hw *hw, unsigned long rate,
703 unsigned long *best_parent_rate,
704 struct clk_hw **best_parent_p)
778static bool mux_is_better_rate(unsigned long rate, unsigned long now,
779 unsigned long best, unsigned long flags)
705{
780{
706 struct clk *clk = hw->clk, *parent, *best_parent = NULL;
781 if (flags & CLK_MUX_ROUND_CLOSEST)
782 return abs(now - rate) < abs(best - rate);
783
784 return now <= rate && now > best;
785}
786
787static long
788clk_mux_determine_rate_flags(struct clk_hw *hw, unsigned long rate,
789 unsigned long min_rate,
790 unsigned long max_rate,
791 unsigned long *best_parent_rate,
792 struct clk_hw **best_parent_p,
793 unsigned long flags)
794{
795 struct clk_core *core = hw->core, *parent, *best_parent = NULL;
707 int i, num_parents;
708 unsigned long parent_rate, best = 0;
709
710 /* if NO_REPARENT flag set, pass through to current parent */
796 int i, num_parents;
797 unsigned long parent_rate, best = 0;
798
799 /* if NO_REPARENT flag set, pass through to current parent */
711 if (clk->flags & CLK_SET_RATE_NO_REPARENT) {
712 parent = clk->parent;
713 if (clk->flags & CLK_SET_RATE_PARENT)
714 best = __clk_round_rate(parent, rate);
800 if (core->flags & CLK_SET_RATE_NO_REPARENT) {
801 parent = core->parent;
802 if (core->flags & CLK_SET_RATE_PARENT)
803 best = __clk_determine_rate(parent->hw, rate,
804 min_rate, max_rate);
715 else if (parent)
805 else if (parent)
716 best = __clk_get_rate(parent);
806 best = clk_core_get_rate_nolock(parent);
717 else
807 else
718 best = __clk_get_rate(clk);
808 best = clk_core_get_rate_nolock(core);
719 goto out;
720 }
721
722 /* find the parent that can provide the fastest rate <= rate */
809 goto out;
810 }
811
812 /* find the parent that can provide the fastest rate <= rate */
723 num_parents = clk->num_parents;
813 num_parents = core->num_parents;
724 for (i = 0; i < num_parents; i++) {
814 for (i = 0; i < num_parents; i++) {
725 parent = clk_get_parent_by_index(clk, i);
815 parent = clk_core_get_parent_by_index(core, i);
726 if (!parent)
727 continue;
816 if (!parent)
817 continue;
728 if (clk->flags & CLK_SET_RATE_PARENT)
729 parent_rate = __clk_round_rate(parent, rate);
818 if (core->flags & CLK_SET_RATE_PARENT)
819 parent_rate = __clk_determine_rate(parent->hw, rate,
820 min_rate,
821 max_rate);
730 else
822 else
731 parent_rate = __clk_get_rate(parent);
732 if (parent_rate <= rate && parent_rate > best) {
823 parent_rate = clk_core_get_rate_nolock(parent);
824 if (mux_is_better_rate(rate, parent_rate, best, flags)) {
733 best_parent = parent;
734 best = parent_rate;
735 }
736 }
737
738out:
739 if (best_parent)
740 *best_parent_p = best_parent->hw;
741 *best_parent_rate = best;
742
743 return best;
744}
825 best_parent = parent;
826 best = parent_rate;
827 }
828 }
829
830out:
831 if (best_parent)
832 *best_parent_p = best_parent->hw;
833 *best_parent_rate = best;
834
835 return best;
836}
837
838struct clk *__clk_lookup(const char *name)
839{
840 struct clk_core *core = clk_core_lookup(name);
841
842 return !core ? NULL : core->hw->clk;
843}
844
845static void clk_core_get_boundaries(struct clk_core *clk,
846 unsigned long *min_rate,
847 unsigned long *max_rate)
848{
849 struct clk *clk_user;
850
851 *min_rate = 0;
852 *max_rate = ULONG_MAX;
853
854 hlist_for_each_entry(clk_user, &clk->clks, child_node)
855 *min_rate = max(*min_rate, clk_user->min_rate);
856
857 hlist_for_each_entry(clk_user, &clk->clks, child_node)
858 *max_rate = min(*max_rate, clk_user->max_rate);
859}
860
861/*
862 * Helper for finding best parent to provide a given frequency. This can be used
863 * directly as a determine_rate callback (e.g. for a mux), or from a more
864 * complex clock that may combine a mux with other operations.
865 */
866long __clk_mux_determine_rate(struct clk_hw *hw, unsigned long rate,
867 unsigned long min_rate,
868 unsigned long max_rate,
869 unsigned long *best_parent_rate,
870 struct clk_hw **best_parent_p)
871{
872 return clk_mux_determine_rate_flags(hw, rate, min_rate, max_rate,
873 best_parent_rate,
874 best_parent_p, 0);
875}
745EXPORT_SYMBOL_GPL(__clk_mux_determine_rate);
746
876EXPORT_SYMBOL_GPL(__clk_mux_determine_rate);
877
878long __clk_mux_determine_rate_closest(struct clk_hw *hw, unsigned long rate,
879 unsigned long min_rate,
880 unsigned long max_rate,
881 unsigned long *best_parent_rate,
882 struct clk_hw **best_parent_p)
883{
884 return clk_mux_determine_rate_flags(hw, rate, min_rate, max_rate,
885 best_parent_rate,
886 best_parent_p,
887 CLK_MUX_ROUND_CLOSEST);
888}
889EXPORT_SYMBOL_GPL(__clk_mux_determine_rate_closest);
890
747/*** clk api ***/
748
891/*** clk api ***/
892
749void __clk_unprepare(struct clk *clk)
893static void clk_core_unprepare(struct clk_core *clk)
750{
751 if (!clk)
752 return;
753
754 if (WARN_ON(clk->prepare_count == 0))
755 return;
756
757 if (--clk->prepare_count > 0)
758 return;
759
760 WARN_ON(clk->enable_count > 0);
761
762 if (clk->ops->unprepare)
763 clk->ops->unprepare(clk->hw);
764
894{
895 if (!clk)
896 return;
897
898 if (WARN_ON(clk->prepare_count == 0))
899 return;
900
901 if (--clk->prepare_count > 0)
902 return;
903
904 WARN_ON(clk->enable_count > 0);
905
906 if (clk->ops->unprepare)
907 clk->ops->unprepare(clk->hw);
908
765 __clk_unprepare(clk->parent);
909 clk_core_unprepare(clk->parent);
766}
767
768/**
769 * clk_unprepare - undo preparation of a clock source
770 * @clk: the clk being unprepared
771 *
772 * clk_unprepare may sleep, which differentiates it from clk_disable. In a
773 * simple case, clk_unprepare can be used instead of clk_disable to gate a clk
774 * if the operation may sleep. One example is a clk which is accessed over
775 * I2c. In the complex case a clk gate operation may require a fast and a slow
776 * part. It is this reason that clk_unprepare and clk_disable are not mutually
777 * exclusive. In fact clk_disable must be called before clk_unprepare.
778 */
779void clk_unprepare(struct clk *clk)
780{
781 if (IS_ERR_OR_NULL(clk))
782 return;
783
784 clk_prepare_lock();
910}
911
912/**
913 * clk_unprepare - undo preparation of a clock source
914 * @clk: the clk being unprepared
915 *
916 * clk_unprepare may sleep, which differentiates it from clk_disable. In a
917 * simple case, clk_unprepare can be used instead of clk_disable to gate a clk
918 * if the operation may sleep. One example is a clk which is accessed over
919 * I2c. In the complex case a clk gate operation may require a fast and a slow
920 * part. It is this reason that clk_unprepare and clk_disable are not mutually
921 * exclusive. In fact clk_disable must be called before clk_unprepare.
922 */
923void clk_unprepare(struct clk *clk)
924{
925 if (IS_ERR_OR_NULL(clk))
926 return;
927
928 clk_prepare_lock();
785 __clk_unprepare(clk);
929 clk_core_unprepare(clk->core);
786 clk_prepare_unlock();
787}
788EXPORT_SYMBOL_GPL(clk_unprepare);
789
930 clk_prepare_unlock();
931}
932EXPORT_SYMBOL_GPL(clk_unprepare);
933
790int __clk_prepare(struct clk *clk)
934static int clk_core_prepare(struct clk_core *clk)
791{
792 int ret = 0;
793
794 if (!clk)
795 return 0;
796
797 if (clk->prepare_count == 0) {
935{
936 int ret = 0;
937
938 if (!clk)
939 return 0;
940
941 if (clk->prepare_count == 0) {
798 ret = __clk_prepare(clk->parent);
942 ret = clk_core_prepare(clk->parent);
799 if (ret)
800 return ret;
801
802 if (clk->ops->prepare) {
803 ret = clk->ops->prepare(clk->hw);
804 if (ret) {
943 if (ret)
944 return ret;
945
946 if (clk->ops->prepare) {
947 ret = clk->ops->prepare(clk->hw);
948 if (ret) {
805 __clk_unprepare(clk->parent);
949 clk_core_unprepare(clk->parent);
806 return ret;
807 }
808 }
809 }
810
811 clk->prepare_count++;
812
813 return 0;

--- 10 unchanged lines hidden (view full) ---

824 * It is this reason that clk_prepare and clk_enable are not mutually
825 * exclusive. In fact clk_prepare must be called before clk_enable.
826 * Returns 0 on success, -EERROR otherwise.
827 */
828int clk_prepare(struct clk *clk)
829{
830 int ret;
831
950 return ret;
951 }
952 }
953 }
954
955 clk->prepare_count++;
956
957 return 0;

--- 10 unchanged lines hidden (view full) ---

968 * It is this reason that clk_prepare and clk_enable are not mutually
969 * exclusive. In fact clk_prepare must be called before clk_enable.
970 * Returns 0 on success, -EERROR otherwise.
971 */
972int clk_prepare(struct clk *clk)
973{
974 int ret;
975
976 if (!clk)
977 return 0;
978
832 clk_prepare_lock();
979 clk_prepare_lock();
833 ret = __clk_prepare(clk);
980 ret = clk_core_prepare(clk->core);
834 clk_prepare_unlock();
835
836 return ret;
837}
838EXPORT_SYMBOL_GPL(clk_prepare);
839
981 clk_prepare_unlock();
982
983 return ret;
984}
985EXPORT_SYMBOL_GPL(clk_prepare);
986
840static void __clk_disable(struct clk *clk)
987static void clk_core_disable(struct clk_core *clk)
841{
842 if (!clk)
843 return;
844
845 if (WARN_ON(clk->enable_count == 0))
846 return;
847
848 if (--clk->enable_count > 0)
849 return;
850
851 if (clk->ops->disable)
852 clk->ops->disable(clk->hw);
853
988{
989 if (!clk)
990 return;
991
992 if (WARN_ON(clk->enable_count == 0))
993 return;
994
995 if (--clk->enable_count > 0)
996 return;
997
998 if (clk->ops->disable)
999 clk->ops->disable(clk->hw);
1000
854 __clk_disable(clk->parent);
1001 clk_core_disable(clk->parent);
855}
856
1002}
1003
1004static void __clk_disable(struct clk *clk)
1005{
1006 if (!clk)
1007 return;
1008
1009 clk_core_disable(clk->core);
1010}
1011
857/**
858 * clk_disable - gate a clock
859 * @clk: the clk being gated
860 *
861 * clk_disable must not sleep, which differentiates it from clk_unprepare. In
862 * a simple case, clk_disable can be used instead of clk_unprepare to gate a
863 * clk if the operation is fast and will never sleep. One example is a
864 * SoC-internal clk which is controlled via simple register writes. In the

--- 9 unchanged lines hidden (view full) ---

874 return;
875
876 flags = clk_enable_lock();
877 __clk_disable(clk);
878 clk_enable_unlock(flags);
879}
880EXPORT_SYMBOL_GPL(clk_disable);
881
1012/**
1013 * clk_disable - gate a clock
1014 * @clk: the clk being gated
1015 *
1016 * clk_disable must not sleep, which differentiates it from clk_unprepare. In
1017 * a simple case, clk_disable can be used instead of clk_unprepare to gate a
1018 * clk if the operation is fast and will never sleep. One example is a
1019 * SoC-internal clk which is controlled via simple register writes. In the

--- 9 unchanged lines hidden (view full) ---

1029 return;
1030
1031 flags = clk_enable_lock();
1032 __clk_disable(clk);
1033 clk_enable_unlock(flags);
1034}
1035EXPORT_SYMBOL_GPL(clk_disable);
1036
882static int __clk_enable(struct clk *clk)
1037static int clk_core_enable(struct clk_core *clk)
883{
884 int ret = 0;
885
886 if (!clk)
887 return 0;
888
889 if (WARN_ON(clk->prepare_count == 0))
890 return -ESHUTDOWN;
891
892 if (clk->enable_count == 0) {
1038{
1039 int ret = 0;
1040
1041 if (!clk)
1042 return 0;
1043
1044 if (WARN_ON(clk->prepare_count == 0))
1045 return -ESHUTDOWN;
1046
1047 if (clk->enable_count == 0) {
893 ret = __clk_enable(clk->parent);
1048 ret = clk_core_enable(clk->parent);
894
895 if (ret)
896 return ret;
897
898 if (clk->ops->enable) {
899 ret = clk->ops->enable(clk->hw);
900 if (ret) {
1049
1050 if (ret)
1051 return ret;
1052
1053 if (clk->ops->enable) {
1054 ret = clk->ops->enable(clk->hw);
1055 if (ret) {
901 __clk_disable(clk->parent);
1056 clk_core_disable(clk->parent);
902 return ret;
903 }
904 }
905 }
906
907 clk->enable_count++;
908 return 0;
909}
910
1057 return ret;
1058 }
1059 }
1060 }
1061
1062 clk->enable_count++;
1063 return 0;
1064}
1065
1066static int __clk_enable(struct clk *clk)
1067{
1068 if (!clk)
1069 return 0;
1070
1071 return clk_core_enable(clk->core);
1072}
1073
911/**
912 * clk_enable - ungate a clock
913 * @clk: the clk being ungated
914 *
915 * clk_enable must not sleep, which differentiates it from clk_prepare. In a
916 * simple case, clk_enable can be used instead of clk_prepare to ungate a clk
917 * if the operation will never sleep. One example is a SoC-internal clk which
918 * is controlled via simple register writes. In the complex case a clk ungate

--- 10 unchanged lines hidden (view full) ---

929 flags = clk_enable_lock();
930 ret = __clk_enable(clk);
931 clk_enable_unlock(flags);
932
933 return ret;
934}
935EXPORT_SYMBOL_GPL(clk_enable);
936
1074/**
1075 * clk_enable - ungate a clock
1076 * @clk: the clk being ungated
1077 *
1078 * clk_enable must not sleep, which differentiates it from clk_prepare. In a
1079 * simple case, clk_enable can be used instead of clk_prepare to ungate a clk
1080 * if the operation will never sleep. One example is a SoC-internal clk which
1081 * is controlled via simple register writes. In the complex case a clk ungate

--- 10 unchanged lines hidden (view full) ---

1092 flags = clk_enable_lock();
1093 ret = __clk_enable(clk);
1094 clk_enable_unlock(flags);
1095
1096 return ret;
1097}
1098EXPORT_SYMBOL_GPL(clk_enable);
1099
937/**
938 * __clk_round_rate - round the given rate for a clk
939 * @clk: round the rate of this clock
940 * @rate: the rate which is to be rounded
941 *
942 * Caller must hold prepare_lock. Useful for clk_ops such as .set_rate
943 */
944unsigned long __clk_round_rate(struct clk *clk, unsigned long rate)
1100static unsigned long clk_core_round_rate_nolock(struct clk_core *clk,
1101 unsigned long rate,
1102 unsigned long min_rate,
1103 unsigned long max_rate)
945{
946 unsigned long parent_rate = 0;
1104{
1105 unsigned long parent_rate = 0;
947 struct clk *parent;
1106 struct clk_core *parent;
948 struct clk_hw *parent_hw;
949
950 if (!clk)
951 return 0;
952
953 parent = clk->parent;
954 if (parent)
955 parent_rate = parent->rate;
956
957 if (clk->ops->determine_rate) {
958 parent_hw = parent ? parent->hw : NULL;
1107 struct clk_hw *parent_hw;
1108
1109 if (!clk)
1110 return 0;
1111
1112 parent = clk->parent;
1113 if (parent)
1114 parent_rate = parent->rate;
1115
1116 if (clk->ops->determine_rate) {
1117 parent_hw = parent ? parent->hw : NULL;
959 return clk->ops->determine_rate(clk->hw, rate, &parent_rate,
960 &parent_hw);
1118 return clk->ops->determine_rate(clk->hw, rate,
1119 min_rate, max_rate,
1120 &parent_rate, &parent_hw);
961 } else if (clk->ops->round_rate)
962 return clk->ops->round_rate(clk->hw, rate, &parent_rate);
963 else if (clk->flags & CLK_SET_RATE_PARENT)
1121 } else if (clk->ops->round_rate)
1122 return clk->ops->round_rate(clk->hw, rate, &parent_rate);
1123 else if (clk->flags & CLK_SET_RATE_PARENT)
964 return __clk_round_rate(clk->parent, rate);
1124 return clk_core_round_rate_nolock(clk->parent, rate, min_rate,
1125 max_rate);
965 else
966 return clk->rate;
967}
1126 else
1127 return clk->rate;
1128}
1129
1130/**
1131 * __clk_determine_rate - get the closest rate actually supported by a clock
1132 * @hw: determine the rate of this clock
1133 * @rate: target rate
1134 * @min_rate: returned rate must be greater than this rate
1135 * @max_rate: returned rate must be less than this rate
1136 *
1137 * Caller must hold prepare_lock. Useful for clk_ops such as .set_rate and
1138 * .determine_rate.
1139 */
1140unsigned long __clk_determine_rate(struct clk_hw *hw,
1141 unsigned long rate,
1142 unsigned long min_rate,
1143 unsigned long max_rate)
1144{
1145 if (!hw)
1146 return 0;
1147
1148 return clk_core_round_rate_nolock(hw->core, rate, min_rate, max_rate);
1149}
1150EXPORT_SYMBOL_GPL(__clk_determine_rate);
1151
1152/**
1153 * __clk_round_rate - round the given rate for a clk
1154 * @clk: round the rate of this clock
1155 * @rate: the rate which is to be rounded
1156 *
1157 * Caller must hold prepare_lock. Useful for clk_ops such as .set_rate
1158 */
1159unsigned long __clk_round_rate(struct clk *clk, unsigned long rate)
1160{
1161 unsigned long min_rate;
1162 unsigned long max_rate;
1163
1164 if (!clk)
1165 return 0;
1166
1167 clk_core_get_boundaries(clk->core, &min_rate, &max_rate);
1168
1169 return clk_core_round_rate_nolock(clk->core, rate, min_rate, max_rate);
1170}
968EXPORT_SYMBOL_GPL(__clk_round_rate);
969
970/**
971 * clk_round_rate - round the given rate for a clk
972 * @clk: the clk for which we are rounding a rate
973 * @rate: the rate which is to be rounded
974 *
975 * Takes in a rate as input and rounds it to a rate that the clk can actually
976 * use which is then returned. If clk doesn't support round_rate operation
977 * then the parent rate is returned.
978 */
979long clk_round_rate(struct clk *clk, unsigned long rate)
980{
981 unsigned long ret;
982
1171EXPORT_SYMBOL_GPL(__clk_round_rate);
1172
1173/**
1174 * clk_round_rate - round the given rate for a clk
1175 * @clk: the clk for which we are rounding a rate
1176 * @rate: the rate which is to be rounded
1177 *
1178 * Takes in a rate as input and rounds it to a rate that the clk can actually
1179 * use which is then returned. If clk doesn't support round_rate operation
1180 * then the parent rate is returned.
1181 */
1182long clk_round_rate(struct clk *clk, unsigned long rate)
1183{
1184 unsigned long ret;
1185
1186 if (!clk)
1187 return 0;
1188
983 clk_prepare_lock();
984 ret = __clk_round_rate(clk, rate);
985 clk_prepare_unlock();
986
987 return ret;
988}
989EXPORT_SYMBOL_GPL(clk_round_rate);
990

--- 6 unchanged lines hidden (view full) ---

997 *
998 * Triggers a notifier call chain on the clk rate-change notification
999 * for 'clk'. Passes a pointer to the struct clk and the previous
1000 * and current rates to the notifier callback. Intended to be called by
1001 * internal clock code only. Returns NOTIFY_DONE from the last driver
1002 * called if all went well, or NOTIFY_STOP or NOTIFY_BAD immediately if
1003 * a driver returns that.
1004 */
1189 clk_prepare_lock();
1190 ret = __clk_round_rate(clk, rate);
1191 clk_prepare_unlock();
1192
1193 return ret;
1194}
1195EXPORT_SYMBOL_GPL(clk_round_rate);
1196

--- 6 unchanged lines hidden (view full) ---

1203 *
1204 * Triggers a notifier call chain on the clk rate-change notification
1205 * for 'clk'. Passes a pointer to the struct clk and the previous
1206 * and current rates to the notifier callback. Intended to be called by
1207 * internal clock code only. Returns NOTIFY_DONE from the last driver
1208 * called if all went well, or NOTIFY_STOP or NOTIFY_BAD immediately if
1209 * a driver returns that.
1210 */
1005static int __clk_notify(struct clk *clk, unsigned long msg,
1211static int __clk_notify(struct clk_core *clk, unsigned long msg,
1006 unsigned long old_rate, unsigned long new_rate)
1007{
1008 struct clk_notifier *cn;
1009 struct clk_notifier_data cnd;
1010 int ret = NOTIFY_DONE;
1011
1212 unsigned long old_rate, unsigned long new_rate)
1213{
1214 struct clk_notifier *cn;
1215 struct clk_notifier_data cnd;
1216 int ret = NOTIFY_DONE;
1217
1012 cnd.clk = clk;
1013 cnd.old_rate = old_rate;
1014 cnd.new_rate = new_rate;
1015
1016 list_for_each_entry(cn, &clk_notifier_list, node) {
1218 cnd.old_rate = old_rate;
1219 cnd.new_rate = new_rate;
1220
1221 list_for_each_entry(cn, &clk_notifier_list, node) {
1017 if (cn->clk == clk) {
1222 if (cn->clk->core == clk) {
1223 cnd.clk = cn->clk;
1018 ret = srcu_notifier_call_chain(&cn->notifier_head, msg,
1019 &cnd);
1224 ret = srcu_notifier_call_chain(&cn->notifier_head, msg,
1225 &cnd);
1020 break;
1021 }
1022 }
1023
1024 return ret;
1025}
1026
1027/**
1028 * __clk_recalc_accuracies
1029 * @clk: first clk in the subtree
1030 *
1031 * Walks the subtree of clks starting with clk and recalculates accuracies as
1032 * it goes. Note that if a clk does not implement the .recalc_accuracy
1033 * callback then it is assumed that the clock will take on the accuracy of it's
1034 * parent.
1035 *
1036 * Caller must hold prepare_lock.
1037 */
1226 }
1227 }
1228
1229 return ret;
1230}
1231
1232/**
1233 * __clk_recalc_accuracies
1234 * @clk: first clk in the subtree
1235 *
1236 * Walks the subtree of clks starting with clk and recalculates accuracies as
1237 * it goes. Note that if a clk does not implement the .recalc_accuracy
1238 * callback then it is assumed that the clock will take on the accuracy of it's
1239 * parent.
1240 *
1241 * Caller must hold prepare_lock.
1242 */
1038static void __clk_recalc_accuracies(struct clk *clk)
1243static void __clk_recalc_accuracies(struct clk_core *clk)
1039{
1040 unsigned long parent_accuracy = 0;
1244{
1245 unsigned long parent_accuracy = 0;
1041 struct clk *child;
1246 struct clk_core *child;
1042
1043 if (clk->parent)
1044 parent_accuracy = clk->parent->accuracy;
1045
1046 if (clk->ops->recalc_accuracy)
1047 clk->accuracy = clk->ops->recalc_accuracy(clk->hw,
1048 parent_accuracy);
1049 else
1050 clk->accuracy = parent_accuracy;
1051
1052 hlist_for_each_entry(child, &clk->children, child_node)
1053 __clk_recalc_accuracies(child);
1054}
1055
1247
1248 if (clk->parent)
1249 parent_accuracy = clk->parent->accuracy;
1250
1251 if (clk->ops->recalc_accuracy)
1252 clk->accuracy = clk->ops->recalc_accuracy(clk->hw,
1253 parent_accuracy);
1254 else
1255 clk->accuracy = parent_accuracy;
1256
1257 hlist_for_each_entry(child, &clk->children, child_node)
1258 __clk_recalc_accuracies(child);
1259}
1260
1261static long clk_core_get_accuracy(struct clk_core *clk)
1262{
1263 unsigned long accuracy;
1264
1265 clk_prepare_lock();
1266 if (clk && (clk->flags & CLK_GET_ACCURACY_NOCACHE))
1267 __clk_recalc_accuracies(clk);
1268
1269 accuracy = __clk_get_accuracy(clk);
1270 clk_prepare_unlock();
1271
1272 return accuracy;
1273}
1274
1056/**
1057 * clk_get_accuracy - return the accuracy of clk
1058 * @clk: the clk whose accuracy is being returned
1059 *
1060 * Simply returns the cached accuracy of the clk, unless
1061 * CLK_GET_ACCURACY_NOCACHE flag is set, which means a recalc_rate will be
1062 * issued.
1063 * If clk is NULL then returns 0.
1064 */
1065long clk_get_accuracy(struct clk *clk)
1066{
1275/**
1276 * clk_get_accuracy - return the accuracy of clk
1277 * @clk: the clk whose accuracy is being returned
1278 *
1279 * Simply returns the cached accuracy of the clk, unless
1280 * CLK_GET_ACCURACY_NOCACHE flag is set, which means a recalc_rate will be
1281 * issued.
1282 * If clk is NULL then returns 0.
1283 */
1284long clk_get_accuracy(struct clk *clk)
1285{
1067 unsigned long accuracy;
1286 if (!clk)
1287 return 0;
1068
1288
1069 clk_prepare_lock();
1070 if (clk && (clk->flags & CLK_GET_ACCURACY_NOCACHE))
1071 __clk_recalc_accuracies(clk);
1072
1073 accuracy = __clk_get_accuracy(clk);
1074 clk_prepare_unlock();
1075
1076 return accuracy;
1289 return clk_core_get_accuracy(clk->core);
1077}
1078EXPORT_SYMBOL_GPL(clk_get_accuracy);
1079
1290}
1291EXPORT_SYMBOL_GPL(clk_get_accuracy);
1292
1080static unsigned long clk_recalc(struct clk *clk, unsigned long parent_rate)
1293static unsigned long clk_recalc(struct clk_core *clk,
1294 unsigned long parent_rate)
1081{
1082 if (clk->ops->recalc_rate)
1083 return clk->ops->recalc_rate(clk->hw, parent_rate);
1084 return parent_rate;
1085}
1086
1087/**
1088 * __clk_recalc_rates

--- 4 unchanged lines hidden (view full) ---

1093 * goes. Note that if a clk does not implement the .recalc_rate callback then
1094 * it is assumed that the clock will take on the rate of its parent.
1095 *
1096 * clk_recalc_rates also propagates the POST_RATE_CHANGE notification,
1097 * if necessary.
1098 *
1099 * Caller must hold prepare_lock.
1100 */
1295{
1296 if (clk->ops->recalc_rate)
1297 return clk->ops->recalc_rate(clk->hw, parent_rate);
1298 return parent_rate;
1299}
1300
1301/**
1302 * __clk_recalc_rates

--- 4 unchanged lines hidden (view full) ---

1307 * goes. Note that if a clk does not implement the .recalc_rate callback then
1308 * it is assumed that the clock will take on the rate of its parent.
1309 *
1310 * clk_recalc_rates also propagates the POST_RATE_CHANGE notification,
1311 * if necessary.
1312 *
1313 * Caller must hold prepare_lock.
1314 */
1101static void __clk_recalc_rates(struct clk *clk, unsigned long msg)
1315static void __clk_recalc_rates(struct clk_core *clk, unsigned long msg)
1102{
1103 unsigned long old_rate;
1104 unsigned long parent_rate = 0;
1316{
1317 unsigned long old_rate;
1318 unsigned long parent_rate = 0;
1105 struct clk *child;
1319 struct clk_core *child;
1106
1107 old_rate = clk->rate;
1108
1109 if (clk->parent)
1110 parent_rate = clk->parent->rate;
1111
1112 clk->rate = clk_recalc(clk, parent_rate);
1113
1114 /*
1115 * ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE
1116 * & ABORT_RATE_CHANGE notifiers
1117 */
1118 if (clk->notifier_count && msg)
1119 __clk_notify(clk, msg, old_rate, clk->rate);
1120
1121 hlist_for_each_entry(child, &clk->children, child_node)
1122 __clk_recalc_rates(child, msg);
1123}
1124
1320
1321 old_rate = clk->rate;
1322
1323 if (clk->parent)
1324 parent_rate = clk->parent->rate;
1325
1326 clk->rate = clk_recalc(clk, parent_rate);
1327
1328 /*
1329 * ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE
1330 * & ABORT_RATE_CHANGE notifiers
1331 */
1332 if (clk->notifier_count && msg)
1333 __clk_notify(clk, msg, old_rate, clk->rate);
1334
1335 hlist_for_each_entry(child, &clk->children, child_node)
1336 __clk_recalc_rates(child, msg);
1337}
1338
1125/**
1126 * clk_get_rate - return the rate of clk
1127 * @clk: the clk whose rate is being returned
1128 *
1129 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1130 * is set, which means a recalc_rate will be issued.
1131 * If clk is NULL then returns 0.
1132 */
1133unsigned long clk_get_rate(struct clk *clk)
1339static unsigned long clk_core_get_rate(struct clk_core *clk)
1134{
1135 unsigned long rate;
1136
1137 clk_prepare_lock();
1138
1139 if (clk && (clk->flags & CLK_GET_RATE_NOCACHE))
1140 __clk_recalc_rates(clk, 0);
1141
1340{
1341 unsigned long rate;
1342
1343 clk_prepare_lock();
1344
1345 if (clk && (clk->flags & CLK_GET_RATE_NOCACHE))
1346 __clk_recalc_rates(clk, 0);
1347
1142 rate = __clk_get_rate(clk);
1348 rate = clk_core_get_rate_nolock(clk);
1143 clk_prepare_unlock();
1144
1145 return rate;
1146}
1349 clk_prepare_unlock();
1350
1351 return rate;
1352}
1353EXPORT_SYMBOL_GPL(clk_core_get_rate);
1354
1355/**
1356 * clk_get_rate - return the rate of clk
1357 * @clk: the clk whose rate is being returned
1358 *
1359 * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
1360 * is set, which means a recalc_rate will be issued.
1361 * If clk is NULL then returns 0.
1362 */
1363unsigned long clk_get_rate(struct clk *clk)
1364{
1365 if (!clk)
1366 return 0;
1367
1368 return clk_core_get_rate(clk->core);
1369}
1147EXPORT_SYMBOL_GPL(clk_get_rate);
1148
1370EXPORT_SYMBOL_GPL(clk_get_rate);
1371
1149static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
1372static int clk_fetch_parent_index(struct clk_core *clk,
1373 struct clk_core *parent)
1150{
1151 int i;
1152
1153 if (!clk->parents) {
1154 clk->parents = kcalloc(clk->num_parents,
1155 sizeof(struct clk *), GFP_KERNEL);
1156 if (!clk->parents)
1157 return -ENOMEM;
1158 }
1159
1160 /*
1161 * find index of new parent clock using cached parent ptrs,
1162 * or if not yet cached, use string name comparison and cache
1374{
1375 int i;
1376
1377 if (!clk->parents) {
1378 clk->parents = kcalloc(clk->num_parents,
1379 sizeof(struct clk *), GFP_KERNEL);
1380 if (!clk->parents)
1381 return -ENOMEM;
1382 }
1383
1384 /*
1385 * find index of new parent clock using cached parent ptrs,
1386 * or if not yet cached, use string name comparison and cache
1163 * them now to avoid future calls to __clk_lookup.
1387 * them now to avoid future calls to clk_core_lookup.
1164 */
1165 for (i = 0; i < clk->num_parents; i++) {
1166 if (clk->parents[i] == parent)
1167 return i;
1168
1169 if (clk->parents[i])
1170 continue;
1171
1172 if (!strcmp(clk->parent_names[i], parent->name)) {
1388 */
1389 for (i = 0; i < clk->num_parents; i++) {
1390 if (clk->parents[i] == parent)
1391 return i;
1392
1393 if (clk->parents[i])
1394 continue;
1395
1396 if (!strcmp(clk->parent_names[i], parent->name)) {
1173 clk->parents[i] = __clk_lookup(parent->name);
1397 clk->parents[i] = clk_core_lookup(parent->name);
1174 return i;
1175 }
1176 }
1177
1178 return -EINVAL;
1179}
1180
1398 return i;
1399 }
1400 }
1401
1402 return -EINVAL;
1403}
1404
1181static void clk_reparent(struct clk *clk, struct clk *new_parent)
1405static void clk_reparent(struct clk_core *clk, struct clk_core *new_parent)
1182{
1183 hlist_del(&clk->child_node);
1184
1185 if (new_parent) {
1186 /* avoid duplicate POST_RATE_CHANGE notifications */
1187 if (new_parent->new_child == clk)
1188 new_parent->new_child = NULL;
1189
1190 hlist_add_head(&clk->child_node, &new_parent->children);
1191 } else {
1192 hlist_add_head(&clk->child_node, &clk_orphan_list);
1193 }
1194
1195 clk->parent = new_parent;
1196}
1197
1406{
1407 hlist_del(&clk->child_node);
1408
1409 if (new_parent) {
1410 /* avoid duplicate POST_RATE_CHANGE notifications */
1411 if (new_parent->new_child == clk)
1412 new_parent->new_child = NULL;
1413
1414 hlist_add_head(&clk->child_node, &new_parent->children);
1415 } else {
1416 hlist_add_head(&clk->child_node, &clk_orphan_list);
1417 }
1418
1419 clk->parent = new_parent;
1420}
1421
1198static struct clk *__clk_set_parent_before(struct clk *clk, struct clk *parent)
1422static struct clk_core *__clk_set_parent_before(struct clk_core *clk,
1423 struct clk_core *parent)
1199{
1200 unsigned long flags;
1424{
1425 unsigned long flags;
1201 struct clk *old_parent = clk->parent;
1426 struct clk_core *old_parent = clk->parent;
1202
1203 /*
1204 * Migrate prepare state between parents and prevent race with
1205 * clk_enable().
1206 *
1207 * If the clock is not prepared, then a race with
1208 * clk_enable/disable() is impossible since we already have the
1209 * prepare lock (future calls to clk_enable() need to be preceded by
1210 * a clk_prepare()).
1211 *
1212 * If the clock is prepared, migrate the prepared state to the new
1213 * parent and also protect against a race with clk_enable() by
1214 * forcing the clock and the new parent on. This ensures that all
1215 * future calls to clk_enable() are practically NOPs with respect to
1216 * hardware and software states.
1217 *
1218 * See also: Comment for clk_set_parent() below.
1219 */
1220 if (clk->prepare_count) {
1427
1428 /*
1429 * Migrate prepare state between parents and prevent race with
1430 * clk_enable().
1431 *
1432 * If the clock is not prepared, then a race with
1433 * clk_enable/disable() is impossible since we already have the
1434 * prepare lock (future calls to clk_enable() need to be preceded by
1435 * a clk_prepare()).
1436 *
1437 * If the clock is prepared, migrate the prepared state to the new
1438 * parent and also protect against a race with clk_enable() by
1439 * forcing the clock and the new parent on. This ensures that all
1440 * future calls to clk_enable() are practically NOPs with respect to
1441 * hardware and software states.
1442 *
1443 * See also: Comment for clk_set_parent() below.
1444 */
1445 if (clk->prepare_count) {
1221 __clk_prepare(parent);
1222 clk_enable(parent);
1223 clk_enable(clk);
1446 clk_core_prepare(parent);
1447 clk_core_enable(parent);
1448 clk_core_enable(clk);
1224 }
1225
1226 /* update the clk tree topology */
1227 flags = clk_enable_lock();
1228 clk_reparent(clk, parent);
1229 clk_enable_unlock(flags);
1230
1231 return old_parent;
1232}
1233
1449 }
1450
1451 /* update the clk tree topology */
1452 flags = clk_enable_lock();
1453 clk_reparent(clk, parent);
1454 clk_enable_unlock(flags);
1455
1456 return old_parent;
1457}
1458
1234static void __clk_set_parent_after(struct clk *clk, struct clk *parent,
1235 struct clk *old_parent)
1459static void __clk_set_parent_after(struct clk_core *core,
1460 struct clk_core *parent,
1461 struct clk_core *old_parent)
1236{
1237 /*
1238 * Finish the migration of prepare state and undo the changes done
1239 * for preventing a race with clk_enable().
1240 */
1462{
1463 /*
1464 * Finish the migration of prepare state and undo the changes done
1465 * for preventing a race with clk_enable().
1466 */
1241 if (clk->prepare_count) {
1242 clk_disable(clk);
1243 clk_disable(old_parent);
1244 __clk_unprepare(old_parent);
1467 if (core->prepare_count) {
1468 clk_core_disable(core);
1469 clk_core_disable(old_parent);
1470 clk_core_unprepare(old_parent);
1245 }
1246}
1247
1471 }
1472}
1473
1248static int __clk_set_parent(struct clk *clk, struct clk *parent, u8 p_index)
1474static int __clk_set_parent(struct clk_core *clk, struct clk_core *parent,
1475 u8 p_index)
1249{
1250 unsigned long flags;
1251 int ret = 0;
1476{
1477 unsigned long flags;
1478 int ret = 0;
1252 struct clk *old_parent;
1479 struct clk_core *old_parent;
1253
1254 old_parent = __clk_set_parent_before(clk, parent);
1255
1256 /* change clock input source */
1257 if (parent && clk->ops->set_parent)
1258 ret = clk->ops->set_parent(clk->hw, p_index);
1259
1260 if (ret) {
1261 flags = clk_enable_lock();
1262 clk_reparent(clk, old_parent);
1263 clk_enable_unlock(flags);
1264
1265 if (clk->prepare_count) {
1480
1481 old_parent = __clk_set_parent_before(clk, parent);
1482
1483 /* change clock input source */
1484 if (parent && clk->ops->set_parent)
1485 ret = clk->ops->set_parent(clk->hw, p_index);
1486
1487 if (ret) {
1488 flags = clk_enable_lock();
1489 clk_reparent(clk, old_parent);
1490 clk_enable_unlock(flags);
1491
1492 if (clk->prepare_count) {
1266 clk_disable(clk);
1267 clk_disable(parent);
1268 __clk_unprepare(parent);
1493 clk_core_disable(clk);
1494 clk_core_disable(parent);
1495 clk_core_unprepare(parent);
1269 }
1270 return ret;
1271 }
1272
1273 __clk_set_parent_after(clk, parent, old_parent);
1274
1275 return 0;
1276}

--- 9 unchanged lines hidden (view full) ---

1286 * Unlike clk_recalc_rates, clk_speculate_rates exists only for sending
1287 * pre-rate change notifications and returns early if no clks in the
1288 * subtree have subscribed to the notifications. Note that if a clk does not
1289 * implement the .recalc_rate callback then it is assumed that the clock will
1290 * take on the rate of its parent.
1291 *
1292 * Caller must hold prepare_lock.
1293 */
1496 }
1497 return ret;
1498 }
1499
1500 __clk_set_parent_after(clk, parent, old_parent);
1501
1502 return 0;
1503}

--- 9 unchanged lines hidden (view full) ---

1513 * Unlike clk_recalc_rates, clk_speculate_rates exists only for sending
1514 * pre-rate change notifications and returns early if no clks in the
1515 * subtree have subscribed to the notifications. Note that if a clk does not
1516 * implement the .recalc_rate callback then it is assumed that the clock will
1517 * take on the rate of its parent.
1518 *
1519 * Caller must hold prepare_lock.
1520 */
1294static int __clk_speculate_rates(struct clk *clk, unsigned long parent_rate)
1521static int __clk_speculate_rates(struct clk_core *clk,
1522 unsigned long parent_rate)
1295{
1523{
1296 struct clk *child;
1524 struct clk_core *child;
1297 unsigned long new_rate;
1298 int ret = NOTIFY_DONE;
1299
1300 new_rate = clk_recalc(clk, parent_rate);
1301
1302 /* abort rate change if a driver returns NOTIFY_BAD or NOTIFY_STOP */
1303 if (clk->notifier_count)
1304 ret = __clk_notify(clk, PRE_RATE_CHANGE, clk->rate, new_rate);

--- 9 unchanged lines hidden (view full) ---

1314 if (ret & NOTIFY_STOP_MASK)
1315 break;
1316 }
1317
1318out:
1319 return ret;
1320}
1321
1525 unsigned long new_rate;
1526 int ret = NOTIFY_DONE;
1527
1528 new_rate = clk_recalc(clk, parent_rate);
1529
1530 /* abort rate change if a driver returns NOTIFY_BAD or NOTIFY_STOP */
1531 if (clk->notifier_count)
1532 ret = __clk_notify(clk, PRE_RATE_CHANGE, clk->rate, new_rate);

--- 9 unchanged lines hidden (view full) ---

1542 if (ret & NOTIFY_STOP_MASK)
1543 break;
1544 }
1545
1546out:
1547 return ret;
1548}
1549
1322static void clk_calc_subtree(struct clk *clk, unsigned long new_rate,
1323 struct clk *new_parent, u8 p_index)
1550static void clk_calc_subtree(struct clk_core *clk, unsigned long new_rate,
1551 struct clk_core *new_parent, u8 p_index)
1324{
1552{
1325 struct clk *child;
1553 struct clk_core *child;
1326
1327 clk->new_rate = new_rate;
1328 clk->new_parent = new_parent;
1329 clk->new_parent_index = p_index;
1330 /* include clk in new parent's PRE_RATE_CHANGE notifications */
1331 clk->new_child = NULL;
1332 if (new_parent && new_parent != clk->parent)
1333 new_parent->new_child = clk;
1334
1335 hlist_for_each_entry(child, &clk->children, child_node) {
1336 child->new_rate = clk_recalc(child, new_rate);
1337 clk_calc_subtree(child, child->new_rate, NULL, 0);
1338 }
1339}
1340
1341/*
1342 * calculate the new rates returning the topmost clock that has to be
1343 * changed.
1344 */
1554
1555 clk->new_rate = new_rate;
1556 clk->new_parent = new_parent;
1557 clk->new_parent_index = p_index;
1558 /* include clk in new parent's PRE_RATE_CHANGE notifications */
1559 clk->new_child = NULL;
1560 if (new_parent && new_parent != clk->parent)
1561 new_parent->new_child = clk;
1562
1563 hlist_for_each_entry(child, &clk->children, child_node) {
1564 child->new_rate = clk_recalc(child, new_rate);
1565 clk_calc_subtree(child, child->new_rate, NULL, 0);
1566 }
1567}
1568
1569/*
1570 * calculate the new rates returning the topmost clock that has to be
1571 * changed.
1572 */
1345static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate)
1573static struct clk_core *clk_calc_new_rates(struct clk_core *clk,
1574 unsigned long rate)
1346{
1575{
1347 struct clk *top = clk;
1348 struct clk *old_parent, *parent;
1576 struct clk_core *top = clk;
1577 struct clk_core *old_parent, *parent;
1349 struct clk_hw *parent_hw;
1350 unsigned long best_parent_rate = 0;
1351 unsigned long new_rate;
1578 struct clk_hw *parent_hw;
1579 unsigned long best_parent_rate = 0;
1580 unsigned long new_rate;
1581 unsigned long min_rate;
1582 unsigned long max_rate;
1352 int p_index = 0;
1353
1354 /* sanity */
1355 if (IS_ERR_OR_NULL(clk))
1356 return NULL;
1357
1358 /* save parent rate, if it exists */
1359 parent = old_parent = clk->parent;
1360 if (parent)
1361 best_parent_rate = parent->rate;
1362
1583 int p_index = 0;
1584
1585 /* sanity */
1586 if (IS_ERR_OR_NULL(clk))
1587 return NULL;
1588
1589 /* save parent rate, if it exists */
1590 parent = old_parent = clk->parent;
1591 if (parent)
1592 best_parent_rate = parent->rate;
1593
1594 clk_core_get_boundaries(clk, &min_rate, &max_rate);
1595
1363 /* find the closest rate and parent clk/rate */
1364 if (clk->ops->determine_rate) {
1365 parent_hw = parent ? parent->hw : NULL;
1366 new_rate = clk->ops->determine_rate(clk->hw, rate,
1596 /* find the closest rate and parent clk/rate */
1597 if (clk->ops->determine_rate) {
1598 parent_hw = parent ? parent->hw : NULL;
1599 new_rate = clk->ops->determine_rate(clk->hw, rate,
1600 min_rate,
1601 max_rate,
1367 &best_parent_rate,
1368 &parent_hw);
1602 &best_parent_rate,
1603 &parent_hw);
1369 parent = parent_hw ? parent_hw->clk : NULL;
1604 parent = parent_hw ? parent_hw->core : NULL;
1370 } else if (clk->ops->round_rate) {
1371 new_rate = clk->ops->round_rate(clk->hw, rate,
1372 &best_parent_rate);
1605 } else if (clk->ops->round_rate) {
1606 new_rate = clk->ops->round_rate(clk->hw, rate,
1607 &best_parent_rate);
1608 if (new_rate < min_rate || new_rate > max_rate)
1609 return NULL;
1373 } else if (!parent || !(clk->flags & CLK_SET_RATE_PARENT)) {
1374 /* pass-through clock without adjustable parent */
1375 clk->new_rate = clk->rate;
1376 return NULL;
1377 } else {
1378 /* pass-through clock with adjustable parent */
1379 top = clk_calc_new_rates(parent, rate);
1380 new_rate = parent->new_rate;

--- 4 unchanged lines hidden (view full) ---

1385 if (parent != old_parent &&
1386 (clk->flags & CLK_SET_PARENT_GATE) && clk->prepare_count) {
1387 pr_debug("%s: %s not gated but wants to reparent\n",
1388 __func__, clk->name);
1389 return NULL;
1390 }
1391
1392 /* try finding the new parent index */
1610 } else if (!parent || !(clk->flags & CLK_SET_RATE_PARENT)) {
1611 /* pass-through clock without adjustable parent */
1612 clk->new_rate = clk->rate;
1613 return NULL;
1614 } else {
1615 /* pass-through clock with adjustable parent */
1616 top = clk_calc_new_rates(parent, rate);
1617 new_rate = parent->new_rate;

--- 4 unchanged lines hidden (view full) ---

1622 if (parent != old_parent &&
1623 (clk->flags & CLK_SET_PARENT_GATE) && clk->prepare_count) {
1624 pr_debug("%s: %s not gated but wants to reparent\n",
1625 __func__, clk->name);
1626 return NULL;
1627 }
1628
1629 /* try finding the new parent index */
1393 if (parent) {
1630 if (parent && clk->num_parents > 1) {
1394 p_index = clk_fetch_parent_index(clk, parent);
1395 if (p_index < 0) {
1396 pr_debug("%s: clk %s can not be parent of clk %s\n",
1397 __func__, parent->name, clk->name);
1398 return NULL;
1399 }
1400 }
1401

--- 7 unchanged lines hidden (view full) ---

1409 return top;
1410}
1411
1412/*
1413 * Notify about rate changes in a subtree. Always walk down the whole tree
1414 * so that in case of an error we can walk down the whole tree again and
1415 * abort the change.
1416 */
1631 p_index = clk_fetch_parent_index(clk, parent);
1632 if (p_index < 0) {
1633 pr_debug("%s: clk %s can not be parent of clk %s\n",
1634 __func__, parent->name, clk->name);
1635 return NULL;
1636 }
1637 }
1638

--- 7 unchanged lines hidden (view full) ---

1646 return top;
1647}
1648
1649/*
1650 * Notify about rate changes in a subtree. Always walk down the whole tree
1651 * so that in case of an error we can walk down the whole tree again and
1652 * abort the change.
1653 */
1417static struct clk *clk_propagate_rate_change(struct clk *clk, unsigned long event)
1654static struct clk_core *clk_propagate_rate_change(struct clk_core *clk,
1655 unsigned long event)
1418{
1656{
1419 struct clk *child, *tmp_clk, *fail_clk = NULL;
1657 struct clk_core *child, *tmp_clk, *fail_clk = NULL;
1420 int ret = NOTIFY_DONE;
1421
1422 if (clk->rate == clk->new_rate)
1423 return NULL;
1424
1425 if (clk->notifier_count) {
1426 ret = __clk_notify(clk, event, clk->rate, clk->new_rate);
1427 if (ret & NOTIFY_STOP_MASK)

--- 18 unchanged lines hidden (view full) ---

1446
1447 return fail_clk;
1448}
1449
1450/*
1451 * walk down a subtree and set the new rates notifying the rate
1452 * change on the way
1453 */
1658 int ret = NOTIFY_DONE;
1659
1660 if (clk->rate == clk->new_rate)
1661 return NULL;
1662
1663 if (clk->notifier_count) {
1664 ret = __clk_notify(clk, event, clk->rate, clk->new_rate);
1665 if (ret & NOTIFY_STOP_MASK)

--- 18 unchanged lines hidden (view full) ---

1684
1685 return fail_clk;
1686}
1687
1688/*
1689 * walk down a subtree and set the new rates notifying the rate
1690 * change on the way
1691 */
1454static void clk_change_rate(struct clk *clk)
1692static void clk_change_rate(struct clk_core *clk)
1455{
1693{
1456 struct clk *child;
1694 struct clk_core *child;
1457 struct hlist_node *tmp;
1458 unsigned long old_rate;
1459 unsigned long best_parent_rate = 0;
1460 bool skip_set_rate = false;
1695 struct hlist_node *tmp;
1696 unsigned long old_rate;
1697 unsigned long best_parent_rate = 0;
1698 bool skip_set_rate = false;
1461 struct clk *old_parent;
1699 struct clk_core *old_parent;
1462
1463 old_rate = clk->rate;
1464
1465 if (clk->new_parent)
1466 best_parent_rate = clk->new_parent->rate;
1467 else if (clk->parent)
1468 best_parent_rate = clk->parent->rate;
1469

--- 31 unchanged lines hidden (view full) ---

1501 clk_change_rate(child);
1502 }
1503
1504 /* handle the new child who might not be in clk->children yet */
1505 if (clk->new_child)
1506 clk_change_rate(clk->new_child);
1507}
1508
1700
1701 old_rate = clk->rate;
1702
1703 if (clk->new_parent)
1704 best_parent_rate = clk->new_parent->rate;
1705 else if (clk->parent)
1706 best_parent_rate = clk->parent->rate;
1707

--- 31 unchanged lines hidden (view full) ---

1739 clk_change_rate(child);
1740 }
1741
1742 /* handle the new child who might not be in clk->children yet */
1743 if (clk->new_child)
1744 clk_change_rate(clk->new_child);
1745}
1746
1747static int clk_core_set_rate_nolock(struct clk_core *clk,
1748 unsigned long req_rate)
1749{
1750 struct clk_core *top, *fail_clk;
1751 unsigned long rate = req_rate;
1752 int ret = 0;
1753
1754 if (!clk)
1755 return 0;
1756
1757 /* bail early if nothing to do */
1758 if (rate == clk_core_get_rate_nolock(clk))
1759 return 0;
1760
1761 if ((clk->flags & CLK_SET_RATE_GATE) && clk->prepare_count)
1762 return -EBUSY;
1763
1764 /* calculate new rates and get the topmost changed clock */
1765 top = clk_calc_new_rates(clk, rate);
1766 if (!top)
1767 return -EINVAL;
1768
1769 /* notify that we are about to change rates */
1770 fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE);
1771 if (fail_clk) {
1772 pr_debug("%s: failed to set %s rate\n", __func__,
1773 fail_clk->name);
1774 clk_propagate_rate_change(top, ABORT_RATE_CHANGE);
1775 return -EBUSY;
1776 }
1777
1778 /* change the rates */
1779 clk_change_rate(top);
1780
1781 clk->req_rate = req_rate;
1782
1783 return ret;
1784}
1785
1509/**
1510 * clk_set_rate - specify a new rate for clk
1511 * @clk: the clk whose rate is being changed
1512 * @rate: the new rate for clk
1513 *
1514 * In the simplest case clk_set_rate will only adjust the rate of clk.
1515 *
1516 * Setting the CLK_SET_RATE_PARENT flag allows the rate change operation to

--- 7 unchanged lines hidden (view full) ---

1524 *
1525 * Rate changes are accomplished via tree traversal that also recalculates the
1526 * rates for the clocks and fires off POST_RATE_CHANGE notifiers.
1527 *
1528 * Returns 0 on success, -EERROR otherwise.
1529 */
1530int clk_set_rate(struct clk *clk, unsigned long rate)
1531{
1786/**
1787 * clk_set_rate - specify a new rate for clk
1788 * @clk: the clk whose rate is being changed
1789 * @rate: the new rate for clk
1790 *
1791 * In the simplest case clk_set_rate will only adjust the rate of clk.
1792 *
1793 * Setting the CLK_SET_RATE_PARENT flag allows the rate change operation to

--- 7 unchanged lines hidden (view full) ---

1801 *
1802 * Rate changes are accomplished via tree traversal that also recalculates the
1803 * rates for the clocks and fires off POST_RATE_CHANGE notifiers.
1804 *
1805 * Returns 0 on success, -EERROR otherwise.
1806 */
1807int clk_set_rate(struct clk *clk, unsigned long rate)
1808{
1532 struct clk *top, *fail_clk;
1533 int ret = 0;
1809 int ret;
1534
1535 if (!clk)
1536 return 0;
1537
1538 /* prevent racing with updates to the clock topology */
1539 clk_prepare_lock();
1540
1810
1811 if (!clk)
1812 return 0;
1813
1814 /* prevent racing with updates to the clock topology */
1815 clk_prepare_lock();
1816
1541 /* bail early if nothing to do */
1542 if (rate == clk_get_rate(clk))
1543 goto out;
1817 ret = clk_core_set_rate_nolock(clk->core, rate);
1544
1818
1545 if ((clk->flags & CLK_SET_RATE_GATE) && clk->prepare_count) {
1546 ret = -EBUSY;
1547 goto out;
1548 }
1819 clk_prepare_unlock();
1549
1820
1550 /* calculate new rates and get the topmost changed clock */
1551 top = clk_calc_new_rates(clk, rate);
1552 if (!top) {
1553 ret = -EINVAL;
1554 goto out;
1555 }
1821 return ret;
1822}
1823EXPORT_SYMBOL_GPL(clk_set_rate);
1556
1824
1557 /* notify that we are about to change rates */
1558 fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE);
1559 if (fail_clk) {
1560 pr_debug("%s: failed to set %s rate\n", __func__,
1561 fail_clk->name);
1562 clk_propagate_rate_change(top, ABORT_RATE_CHANGE);
1563 ret = -EBUSY;
1564 goto out;
1825/**
1826 * clk_set_rate_range - set a rate range for a clock source
1827 * @clk: clock source
1828 * @min: desired minimum clock rate in Hz, inclusive
1829 * @max: desired maximum clock rate in Hz, inclusive
1830 *
1831 * Returns success (0) or negative errno.
1832 */
1833int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
1834{
1835 int ret = 0;
1836
1837 if (!clk)
1838 return 0;
1839
1840 if (min > max) {
1841 pr_err("%s: clk %s dev %s con %s: invalid range [%lu, %lu]\n",
1842 __func__, clk->core->name, clk->dev_id, clk->con_id,
1843 min, max);
1844 return -EINVAL;
1565 }
1566
1845 }
1846
1567 /* change the rates */
1568 clk_change_rate(top);
1847 clk_prepare_lock();
1569
1848
1570out:
1849 if (min != clk->min_rate || max != clk->max_rate) {
1850 clk->min_rate = min;
1851 clk->max_rate = max;
1852 ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
1853 }
1854
1571 clk_prepare_unlock();
1572
1573 return ret;
1574}
1855 clk_prepare_unlock();
1856
1857 return ret;
1858}
1575EXPORT_SYMBOL_GPL(clk_set_rate);
1859EXPORT_SYMBOL_GPL(clk_set_rate_range);
1576
1577/**
1860
1861/**
1862 * clk_set_min_rate - set a minimum clock rate for a clock source
1863 * @clk: clock source
1864 * @rate: desired minimum clock rate in Hz, inclusive
1865 *
1866 * Returns success (0) or negative errno.
1867 */
1868int clk_set_min_rate(struct clk *clk, unsigned long rate)
1869{
1870 if (!clk)
1871 return 0;
1872
1873 return clk_set_rate_range(clk, rate, clk->max_rate);
1874}
1875EXPORT_SYMBOL_GPL(clk_set_min_rate);
1876
1877/**
1878 * clk_set_max_rate - set a maximum clock rate for a clock source
1879 * @clk: clock source
1880 * @rate: desired maximum clock rate in Hz, inclusive
1881 *
1882 * Returns success (0) or negative errno.
1883 */
1884int clk_set_max_rate(struct clk *clk, unsigned long rate)
1885{
1886 if (!clk)
1887 return 0;
1888
1889 return clk_set_rate_range(clk, clk->min_rate, rate);
1890}
1891EXPORT_SYMBOL_GPL(clk_set_max_rate);
1892
1893/**
1578 * clk_get_parent - return the parent of a clk
1579 * @clk: the clk whose parent gets returned
1580 *
1581 * Simply returns clk->parent. Returns NULL if clk is NULL.
1582 */
1583struct clk *clk_get_parent(struct clk *clk)
1584{
1585 struct clk *parent;

--- 8 unchanged lines hidden (view full) ---

1594
1595/*
1596 * .get_parent is mandatory for clocks with multiple possible parents. It is
1597 * optional for single-parent clocks. Always call .get_parent if it is
1598 * available and WARN if it is missing for multi-parent clocks.
1599 *
1600 * For single-parent clocks without .get_parent, first check to see if the
1601 * .parents array exists, and if so use it to avoid an expensive tree
1894 * clk_get_parent - return the parent of a clk
1895 * @clk: the clk whose parent gets returned
1896 *
1897 * Simply returns clk->parent. Returns NULL if clk is NULL.
1898 */
1899struct clk *clk_get_parent(struct clk *clk)
1900{
1901 struct clk *parent;

--- 8 unchanged lines hidden (view full) ---

1910
1911/*
1912 * .get_parent is mandatory for clocks with multiple possible parents. It is
1913 * optional for single-parent clocks. Always call .get_parent if it is
1914 * available and WARN if it is missing for multi-parent clocks.
1915 *
1916 * For single-parent clocks without .get_parent, first check to see if the
1917 * .parents array exists, and if so use it to avoid an expensive tree
1602 * traversal. If .parents does not exist then walk the tree with __clk_lookup.
1918 * traversal. If .parents does not exist then walk the tree.
1603 */
1919 */
1604static struct clk *__clk_init_parent(struct clk *clk)
1920static struct clk_core *__clk_init_parent(struct clk_core *clk)
1605{
1921{
1606 struct clk *ret = NULL;
1922 struct clk_core *ret = NULL;
1607 u8 index;
1608
1609 /* handle the trivial cases */
1610
1611 if (!clk->num_parents)
1612 goto out;
1613
1614 if (clk->num_parents == 1) {
1615 if (IS_ERR_OR_NULL(clk->parent))
1923 u8 index;
1924
1925 /* handle the trivial cases */
1926
1927 if (!clk->num_parents)
1928 goto out;
1929
1930 if (clk->num_parents == 1) {
1931 if (IS_ERR_OR_NULL(clk->parent))
1616 clk->parent = __clk_lookup(clk->parent_names[0]);
1932 clk->parent = clk_core_lookup(clk->parent_names[0]);
1617 ret = clk->parent;
1618 goto out;
1619 }
1620
1621 if (!clk->ops->get_parent) {
1622 WARN(!clk->ops->get_parent,
1623 "%s: multi-parent clocks must implement .get_parent\n",
1624 __func__);
1625 goto out;
1626 };
1627
1628 /*
1629 * Do our best to cache parent clocks in clk->parents. This prevents
1933 ret = clk->parent;
1934 goto out;
1935 }
1936
1937 if (!clk->ops->get_parent) {
1938 WARN(!clk->ops->get_parent,
1939 "%s: multi-parent clocks must implement .get_parent\n",
1940 __func__);
1941 goto out;
1942 };
1943
1944 /*
1945 * Do our best to cache parent clocks in clk->parents. This prevents
1630 * unnecessary and expensive calls to __clk_lookup. We don't set
1631 * clk->parent here; that is done by the calling function
1946 * unnecessary and expensive lookups. We don't set clk->parent here;
1947 * that is done by the calling function.
1632 */
1633
1634 index = clk->ops->get_parent(clk->hw);
1635
1636 if (!clk->parents)
1637 clk->parents =
1638 kcalloc(clk->num_parents, sizeof(struct clk *),
1639 GFP_KERNEL);
1640
1948 */
1949
1950 index = clk->ops->get_parent(clk->hw);
1951
1952 if (!clk->parents)
1953 clk->parents =
1954 kcalloc(clk->num_parents, sizeof(struct clk *),
1955 GFP_KERNEL);
1956
1641 ret = clk_get_parent_by_index(clk, index);
1957 ret = clk_core_get_parent_by_index(clk, index);
1642
1643out:
1644 return ret;
1645}
1646
1958
1959out:
1960 return ret;
1961}
1962
1647void __clk_reparent(struct clk *clk, struct clk *new_parent)
1963static void clk_core_reparent(struct clk_core *clk,
1964 struct clk_core *new_parent)
1648{
1649 clk_reparent(clk, new_parent);
1650 __clk_recalc_accuracies(clk);
1651 __clk_recalc_rates(clk, POST_RATE_CHANGE);
1652}
1653
1654/**
1965{
1966 clk_reparent(clk, new_parent);
1967 __clk_recalc_accuracies(clk);
1968 __clk_recalc_rates(clk, POST_RATE_CHANGE);
1969}
1970
1971/**
1655 * clk_set_parent - switch the parent of a mux clk
1656 * @clk: the mux clk whose input we are switching
1657 * @parent: the new input to clk
1972 * clk_has_parent - check if a clock is a possible parent for another
1973 * @clk: clock source
1974 * @parent: parent clock source
1658 *
1975 *
1659 * Re-parent clk to use parent as its new input source. If clk is in
1660 * prepared state, the clk will get enabled for the duration of this call. If
1661 * that's not acceptable for a specific clk (Eg: the consumer can't handle
1662 * that, the reparenting is glitchy in hardware, etc), use the
1663 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
1976 * This function can be used in drivers that need to check that a clock can be
1977 * the parent of another without actually changing the parent.
1664 *
1978 *
1665 * After successfully changing clk's parent clk_set_parent will update the
1666 * clk topology, sysfs topology and propagate rate recalculation via
1667 * __clk_recalc_rates.
1668 *
1669 * Returns 0 on success, -EERROR otherwise.
1979 * Returns true if @parent is a possible parent for @clk, false otherwise.
1670 */
1980 */
1671int clk_set_parent(struct clk *clk, struct clk *parent)
1981bool clk_has_parent(struct clk *clk, struct clk *parent)
1672{
1982{
1983 struct clk_core *core, *parent_core;
1984 unsigned int i;
1985
1986 /* NULL clocks should be nops, so return success if either is NULL. */
1987 if (!clk || !parent)
1988 return true;
1989
1990 core = clk->core;
1991 parent_core = parent->core;
1992
1993 /* Optimize for the case where the parent is already the parent. */
1994 if (core->parent == parent_core)
1995 return true;
1996
1997 for (i = 0; i < core->num_parents; i++)
1998 if (strcmp(core->parent_names[i], parent_core->name) == 0)
1999 return true;
2000
2001 return false;
2002}
2003EXPORT_SYMBOL_GPL(clk_has_parent);
2004
2005static int clk_core_set_parent(struct clk_core *clk, struct clk_core *parent)
2006{
1673 int ret = 0;
1674 int p_index = 0;
1675 unsigned long p_rate = 0;
1676
1677 if (!clk)
1678 return 0;
1679
1680 /* verify ops for for multi-parent clks */

--- 42 unchanged lines hidden (view full) ---

1723 __clk_recalc_accuracies(clk);
1724 }
1725
1726out:
1727 clk_prepare_unlock();
1728
1729 return ret;
1730}
2007 int ret = 0;
2008 int p_index = 0;
2009 unsigned long p_rate = 0;
2010
2011 if (!clk)
2012 return 0;
2013
2014 /* verify ops for for multi-parent clks */

--- 42 unchanged lines hidden (view full) ---

2057 __clk_recalc_accuracies(clk);
2058 }
2059
2060out:
2061 clk_prepare_unlock();
2062
2063 return ret;
2064}
2065
2066/**
2067 * clk_set_parent - switch the parent of a mux clk
2068 * @clk: the mux clk whose input we are switching
2069 * @parent: the new input to clk
2070 *
2071 * Re-parent clk to use parent as its new input source. If clk is in
2072 * prepared state, the clk will get enabled for the duration of this call. If
2073 * that's not acceptable for a specific clk (Eg: the consumer can't handle
2074 * that, the reparenting is glitchy in hardware, etc), use the
2075 * CLK_SET_PARENT_GATE flag to allow reparenting only when clk is unprepared.
2076 *
2077 * After successfully changing clk's parent clk_set_parent will update the
2078 * clk topology, sysfs topology and propagate rate recalculation via
2079 * __clk_recalc_rates.
2080 *
2081 * Returns 0 on success, -EERROR otherwise.
2082 */
2083int clk_set_parent(struct clk *clk, struct clk *parent)
2084{
2085 if (!clk)
2086 return 0;
2087
2088 return clk_core_set_parent(clk->core, parent ? parent->core : NULL);
2089}
1731EXPORT_SYMBOL_GPL(clk_set_parent);
1732
1733/**
1734 * clk_set_phase - adjust the phase shift of a clock signal
1735 * @clk: clock signal source
1736 * @degrees: number of degrees the signal is shifted
1737 *
1738 * Shifts the phase of a clock signal by the specified

--- 20 unchanged lines hidden (view full) ---

1759
1760 /* sanity check degrees */
1761 degrees %= 360;
1762 if (degrees < 0)
1763 degrees += 360;
1764
1765 clk_prepare_lock();
1766
2090EXPORT_SYMBOL_GPL(clk_set_parent);
2091
2092/**
2093 * clk_set_phase - adjust the phase shift of a clock signal
2094 * @clk: clock signal source
2095 * @degrees: number of degrees the signal is shifted
2096 *
2097 * Shifts the phase of a clock signal by the specified

--- 20 unchanged lines hidden (view full) ---

2118
2119 /* sanity check degrees */
2120 degrees %= 360;
2121 if (degrees < 0)
2122 degrees += 360;
2123
2124 clk_prepare_lock();
2125
1767 if (!clk->ops->set_phase)
2126 if (!clk->core->ops->set_phase)
1768 goto out_unlock;
1769
2127 goto out_unlock;
2128
1770 ret = clk->ops->set_phase(clk->hw, degrees);
2129 ret = clk->core->ops->set_phase(clk->core->hw, degrees);
1771
1772 if (!ret)
2130
2131 if (!ret)
1773 clk->phase = degrees;
2132 clk->core->phase = degrees;
1774
1775out_unlock:
1776 clk_prepare_unlock();
1777
1778out:
1779 return ret;
1780}
2133
2134out_unlock:
2135 clk_prepare_unlock();
2136
2137out:
2138 return ret;
2139}
2140EXPORT_SYMBOL_GPL(clk_set_phase);
1781
2141
1782/**
1783 * clk_get_phase - return the phase shift of a clock signal
1784 * @clk: clock signal source
1785 *
1786 * Returns the phase shift of a clock node in degrees, otherwise returns
1787 * -EERROR.
1788 */
1789int clk_get_phase(struct clk *clk)
2142static int clk_core_get_phase(struct clk_core *clk)
1790{
1791 int ret = 0;
1792
1793 if (!clk)
1794 goto out;
1795
1796 clk_prepare_lock();
1797 ret = clk->phase;
1798 clk_prepare_unlock();
1799
1800out:
1801 return ret;
1802}
2143{
2144 int ret = 0;
2145
2146 if (!clk)
2147 goto out;
2148
2149 clk_prepare_lock();
2150 ret = clk->phase;
2151 clk_prepare_unlock();
2152
2153out:
2154 return ret;
2155}
2156EXPORT_SYMBOL_GPL(clk_get_phase);
1803
1804/**
2157
2158/**
2159 * clk_get_phase - return the phase shift of a clock signal
2160 * @clk: clock signal source
2161 *
2162 * Returns the phase shift of a clock node in degrees, otherwise returns
2163 * -EERROR.
2164 */
2165int clk_get_phase(struct clk *clk)
2166{
2167 if (!clk)
2168 return 0;
2169
2170 return clk_core_get_phase(clk->core);
2171}
2172
2173/**
1805 * __clk_init - initialize the data structures in a struct clk
1806 * @dev: device initializing this clk, placeholder for now
1807 * @clk: clk being initialized
1808 *
2174 * __clk_init - initialize the data structures in a struct clk
2175 * @dev: device initializing this clk, placeholder for now
2176 * @clk: clk being initialized
2177 *
1809 * Initializes the lists in struct clk, queries the hardware for the
2178 * Initializes the lists in struct clk_core, queries the hardware for the
1810 * parent and rate and sets them both.
1811 */
2179 * parent and rate and sets them both.
2180 */
1812int __clk_init(struct device *dev, struct clk *clk)
2181static int __clk_init(struct device *dev, struct clk *clk_user)
1813{
1814 int i, ret = 0;
2182{
2183 int i, ret = 0;
1815 struct clk *orphan;
2184 struct clk_core *orphan;
1816 struct hlist_node *tmp2;
2185 struct hlist_node *tmp2;
2186 struct clk_core *clk;
2187 unsigned long rate;
1817
2188
1818 if (!clk)
2189 if (!clk_user)
1819 return -EINVAL;
1820
2190 return -EINVAL;
2191
2192 clk = clk_user->core;
2193
1821 clk_prepare_lock();
1822
1823 /* check to see if a clock with this name is already registered */
2194 clk_prepare_lock();
2195
2196 /* check to see if a clock with this name is already registered */
1824 if (__clk_lookup(clk->name)) {
2197 if (clk_core_lookup(clk->name)) {
1825 pr_debug("%s: clk %s already initialized\n",
1826 __func__, clk->name);
1827 ret = -EEXIST;
1828 goto out;
1829 }
1830
1831 /* check that clk_ops are sane. See Documentation/clk.txt */
1832 if (clk->ops->set_rate &&

--- 35 unchanged lines hidden (view full) ---

1868 *
1869 * If clk->parents is not NULL we skip this entire block. This allows
1870 * for clock drivers to statically initialize clk->parents.
1871 */
1872 if (clk->num_parents > 1 && !clk->parents) {
1873 clk->parents = kcalloc(clk->num_parents, sizeof(struct clk *),
1874 GFP_KERNEL);
1875 /*
2198 pr_debug("%s: clk %s already initialized\n",
2199 __func__, clk->name);
2200 ret = -EEXIST;
2201 goto out;
2202 }
2203
2204 /* check that clk_ops are sane. See Documentation/clk.txt */
2205 if (clk->ops->set_rate &&

--- 35 unchanged lines hidden (view full) ---

2241 *
2242 * If clk->parents is not NULL we skip this entire block. This allows
2243 * for clock drivers to statically initialize clk->parents.
2244 */
2245 if (clk->num_parents > 1 && !clk->parents) {
2246 clk->parents = kcalloc(clk->num_parents, sizeof(struct clk *),
2247 GFP_KERNEL);
2248 /*
1876 * __clk_lookup returns NULL for parents that have not been
2249 * clk_core_lookup returns NULL for parents that have not been
1877 * clk_init'd; thus any access to clk->parents[] must check
1878 * for a NULL pointer. We can always perform lazy lookups for
1879 * missing parents later on.
1880 */
1881 if (clk->parents)
1882 for (i = 0; i < clk->num_parents; i++)
1883 clk->parents[i] =
2250 * clk_init'd; thus any access to clk->parents[] must check
2251 * for a NULL pointer. We can always perform lazy lookups for
2252 * missing parents later on.
2253 */
2254 if (clk->parents)
2255 for (i = 0; i < clk->num_parents; i++)
2256 clk->parents[i] =
1884 __clk_lookup(clk->parent_names[i]);
2257 clk_core_lookup(clk->parent_names[i]);
1885 }
1886
1887 clk->parent = __clk_init_parent(clk);
1888
1889 /*
1890 * Populate clk->parent if parent has already been __clk_init'd. If
1891 * parent has not yet been __clk_init'd then place clk in the orphan
1892 * list. If clk has set the CLK_IS_ROOT flag then place it in the root

--- 38 unchanged lines hidden (view full) ---

1931
1932 /*
1933 * Set clk's rate. The preferred method is to use .recalc_rate. For
1934 * simple clocks and lazy developers the default fallback is to use the
1935 * parent's rate. If a clock doesn't have a parent (or is orphaned)
1936 * then rate is set to zero.
1937 */
1938 if (clk->ops->recalc_rate)
2258 }
2259
2260 clk->parent = __clk_init_parent(clk);
2261
2262 /*
2263 * Populate clk->parent if parent has already been __clk_init'd. If
2264 * parent has not yet been __clk_init'd then place clk in the orphan
2265 * list. If clk has set the CLK_IS_ROOT flag then place it in the root

--- 38 unchanged lines hidden (view full) ---

2304
2305 /*
2306 * Set clk's rate. The preferred method is to use .recalc_rate. For
2307 * simple clocks and lazy developers the default fallback is to use the
2308 * parent's rate. If a clock doesn't have a parent (or is orphaned)
2309 * then rate is set to zero.
2310 */
2311 if (clk->ops->recalc_rate)
1939 clk->rate = clk->ops->recalc_rate(clk->hw,
1940 __clk_get_rate(clk->parent));
2312 rate = clk->ops->recalc_rate(clk->hw,
2313 clk_core_get_rate_nolock(clk->parent));
1941 else if (clk->parent)
2314 else if (clk->parent)
1942 clk->rate = clk->parent->rate;
2315 rate = clk->parent->rate;
1943 else
2316 else
1944 clk->rate = 0;
2317 rate = 0;
2318 clk->rate = clk->req_rate = rate;
1945
1946 /*
1947 * walk the list of orphan clocks and reparent any that are children of
1948 * this clock
1949 */
1950 hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) {
1951 if (orphan->num_parents && orphan->ops->get_parent) {
1952 i = orphan->ops->get_parent(orphan->hw);
1953 if (!strcmp(clk->name, orphan->parent_names[i]))
2319
2320 /*
2321 * walk the list of orphan clocks and reparent any that are children of
2322 * this clock
2323 */
2324 hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) {
2325 if (orphan->num_parents && orphan->ops->get_parent) {
2326 i = orphan->ops->get_parent(orphan->hw);
2327 if (!strcmp(clk->name, orphan->parent_names[i]))
1954 __clk_reparent(orphan, clk);
2328 clk_core_reparent(orphan, clk);
1955 continue;
1956 }
1957
1958 for (i = 0; i < orphan->num_parents; i++)
1959 if (!strcmp(clk->name, orphan->parent_names[i])) {
2329 continue;
2330 }
2331
2332 for (i = 0; i < orphan->num_parents; i++)
2333 if (!strcmp(clk->name, orphan->parent_names[i])) {
1960 __clk_reparent(orphan, clk);
2334 clk_core_reparent(orphan, clk);
1961 break;
1962 }
1963 }
1964
1965 /*
1966 * optional platform-specific magic
1967 *
1968 * The .init callback is not used by any of the basic clock types, but

--- 9 unchanged lines hidden (view full) ---

1978 clk_prepare_unlock();
1979
1980 if (!ret)
1981 clk_debug_register(clk);
1982
1983 return ret;
1984}
1985
2335 break;
2336 }
2337 }
2338
2339 /*
2340 * optional platform-specific magic
2341 *
2342 * The .init callback is not used by any of the basic clock types, but

--- 9 unchanged lines hidden (view full) ---

2352 clk_prepare_unlock();
2353
2354 if (!ret)
2355 clk_debug_register(clk);
2356
2357 return ret;
2358}
2359
1986/**
1987 * __clk_register - register a clock and return a cookie.
1988 *
1989 * Same as clk_register, except that the .clk field inside hw shall point to a
1990 * preallocated (generally statically allocated) struct clk. None of the fields
1991 * of the struct clk need to be initialized.
1992 *
1993 * The data pointed to by .init and .clk field shall NOT be marked as init
1994 * data.
1995 *
1996 * __clk_register is only exposed via clk-private.h and is intended for use with
1997 * very large numbers of clocks that need to be statically initialized. It is
1998 * a layering violation to include clk-private.h from any code which implements
1999 * a clock's .ops; as such any statically initialized clock data MUST be in a
2000 * separate C file from the logic that implements its operations. Returns 0
2001 * on success, otherwise an error code.
2002 */
2003struct clk *__clk_register(struct device *dev, struct clk_hw *hw)
2360struct clk *__clk_create_clk(struct clk_hw *hw, const char *dev_id,
2361 const char *con_id)
2004{
2362{
2005 int ret;
2006 struct clk *clk;
2007
2363 struct clk *clk;
2364
2008 clk = hw->clk;
2009 clk->name = hw->init->name;
2010 clk->ops = hw->init->ops;
2011 clk->hw = hw;
2012 clk->flags = hw->init->flags;
2013 clk->parent_names = hw->init->parent_names;
2014 clk->num_parents = hw->init->num_parents;
2015 if (dev && dev->driver)
2016 clk->owner = dev->driver->owner;
2017 else
2018 clk->owner = NULL;
2365 /* This is to allow this function to be chained to others */
2366 if (!hw || IS_ERR(hw))
2367 return (struct clk *) hw;
2019
2368
2020 ret = __clk_init(dev, clk);
2021 if (ret)
2022 return ERR_PTR(ret);
2369 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
2370 if (!clk)
2371 return ERR_PTR(-ENOMEM);
2023
2372
2373 clk->core = hw->core;
2374 clk->dev_id = dev_id;
2375 clk->con_id = con_id;
2376 clk->max_rate = ULONG_MAX;
2377
2378 clk_prepare_lock();
2379 hlist_add_head(&clk->child_node, &hw->core->clks);
2380 clk_prepare_unlock();
2381
2024 return clk;
2025}
2382 return clk;
2383}
2026EXPORT_SYMBOL_GPL(__clk_register);
2027
2384
2385void __clk_free_clk(struct clk *clk)
2386{
2387 clk_prepare_lock();
2388 hlist_del(&clk->child_node);
2389 clk_prepare_unlock();
2390
2391 kfree(clk);
2392}
2393
2028/**
2029 * clk_register - allocate a new clock, register it and return an opaque cookie
2030 * @dev: device that is registering this clock
2031 * @hw: link to hardware-specific clock data
2032 *
2033 * clk_register is the primary interface for populating the clock tree with new
2034 * clock nodes. It returns a pointer to the newly allocated struct clk which
2035 * cannot be dereferenced by driver code but may be used in conjuction with the
2036 * rest of the clock API. In the event of an error clk_register will return an
2037 * error code; drivers must test for an error code after calling clk_register.
2038 */
2039struct clk *clk_register(struct device *dev, struct clk_hw *hw)
2040{
2041 int i, ret;
2394/**
2395 * clk_register - allocate a new clock, register it and return an opaque cookie
2396 * @dev: device that is registering this clock
2397 * @hw: link to hardware-specific clock data
2398 *
2399 * clk_register is the primary interface for populating the clock tree with new
2400 * clock nodes. It returns a pointer to the newly allocated struct clk which
2401 * cannot be dereferenced by driver code but may be used in conjuction with the
2402 * rest of the clock API. In the event of an error clk_register will return an
2403 * error code; drivers must test for an error code after calling clk_register.
2404 */
2405struct clk *clk_register(struct device *dev, struct clk_hw *hw)
2406{
2407 int i, ret;
2042 struct clk *clk;
2408 struct clk_core *clk;
2043
2044 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
2045 if (!clk) {
2046 pr_err("%s: could not allocate clk\n", __func__);
2047 ret = -ENOMEM;
2048 goto fail_out;
2049 }
2050

--- 4 unchanged lines hidden (view full) ---

2055 goto fail_name;
2056 }
2057 clk->ops = hw->init->ops;
2058 if (dev && dev->driver)
2059 clk->owner = dev->driver->owner;
2060 clk->hw = hw;
2061 clk->flags = hw->init->flags;
2062 clk->num_parents = hw->init->num_parents;
2409
2410 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
2411 if (!clk) {
2412 pr_err("%s: could not allocate clk\n", __func__);
2413 ret = -ENOMEM;
2414 goto fail_out;
2415 }
2416

--- 4 unchanged lines hidden (view full) ---

2421 goto fail_name;
2422 }
2423 clk->ops = hw->init->ops;
2424 if (dev && dev->driver)
2425 clk->owner = dev->driver->owner;
2426 clk->hw = hw;
2427 clk->flags = hw->init->flags;
2428 clk->num_parents = hw->init->num_parents;
2063 hw->clk = clk;
2429 hw->core = clk;
2064
2065 /* allocate local copy in case parent_names is __initdata */
2066 clk->parent_names = kcalloc(clk->num_parents, sizeof(char *),
2067 GFP_KERNEL);
2068
2069 if (!clk->parent_names) {
2070 pr_err("%s: could not allocate clk->parent_names\n", __func__);
2071 ret = -ENOMEM;

--- 7 unchanged lines hidden (view full) ---

2079 GFP_KERNEL);
2080 if (!clk->parent_names[i]) {
2081 pr_err("%s: could not copy parent_names\n", __func__);
2082 ret = -ENOMEM;
2083 goto fail_parent_names_copy;
2084 }
2085 }
2086
2430
2431 /* allocate local copy in case parent_names is __initdata */
2432 clk->parent_names = kcalloc(clk->num_parents, sizeof(char *),
2433 GFP_KERNEL);
2434
2435 if (!clk->parent_names) {
2436 pr_err("%s: could not allocate clk->parent_names\n", __func__);
2437 ret = -ENOMEM;

--- 7 unchanged lines hidden (view full) ---

2445 GFP_KERNEL);
2446 if (!clk->parent_names[i]) {
2447 pr_err("%s: could not copy parent_names\n", __func__);
2448 ret = -ENOMEM;
2449 goto fail_parent_names_copy;
2450 }
2451 }
2452
2087 ret = __clk_init(dev, clk);
2453 INIT_HLIST_HEAD(&clk->clks);
2454
2455 hw->clk = __clk_create_clk(hw, NULL, NULL);
2456 if (IS_ERR(hw->clk)) {
2457 pr_err("%s: could not allocate per-user clk\n", __func__);
2458 ret = PTR_ERR(hw->clk);
2459 goto fail_parent_names_copy;
2460 }
2461
2462 ret = __clk_init(dev, hw->clk);
2088 if (!ret)
2463 if (!ret)
2089 return clk;
2464 return hw->clk;
2090
2465
2466 __clk_free_clk(hw->clk);
2467 hw->clk = NULL;
2468
2091fail_parent_names_copy:
2092 while (--i >= 0)
2093 kfree(clk->parent_names[i]);
2094 kfree(clk->parent_names);
2095fail_parent_names:
2096 kfree(clk->name);
2097fail_name:
2098 kfree(clk);
2099fail_out:
2100 return ERR_PTR(ret);
2101}
2102EXPORT_SYMBOL_GPL(clk_register);
2103
2104/*
2105 * Free memory allocated for a clock.
2106 * Caller must hold prepare_lock.
2107 */
2108static void __clk_release(struct kref *ref)
2109{
2469fail_parent_names_copy:
2470 while (--i >= 0)
2471 kfree(clk->parent_names[i]);
2472 kfree(clk->parent_names);
2473fail_parent_names:
2474 kfree(clk->name);
2475fail_name:
2476 kfree(clk);
2477fail_out:
2478 return ERR_PTR(ret);
2479}
2480EXPORT_SYMBOL_GPL(clk_register);
2481
2482/*
2483 * Free memory allocated for a clock.
2484 * Caller must hold prepare_lock.
2485 */
2486static void __clk_release(struct kref *ref)
2487{
2110 struct clk *clk = container_of(ref, struct clk, ref);
2488 struct clk_core *clk = container_of(ref, struct clk_core, ref);
2111 int i = clk->num_parents;
2112
2113 kfree(clk->parents);
2114 while (--i >= 0)
2115 kfree(clk->parent_names[i]);
2116
2117 kfree(clk->parent_names);
2118 kfree(clk->name);

--- 41 unchanged lines hidden (view full) ---

2160 */
2161void clk_unregister(struct clk *clk)
2162{
2163 unsigned long flags;
2164
2165 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2166 return;
2167
2489 int i = clk->num_parents;
2490
2491 kfree(clk->parents);
2492 while (--i >= 0)
2493 kfree(clk->parent_names[i]);
2494
2495 kfree(clk->parent_names);
2496 kfree(clk->name);

--- 41 unchanged lines hidden (view full) ---

2538 */
2539void clk_unregister(struct clk *clk)
2540{
2541 unsigned long flags;
2542
2543 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2544 return;
2545
2168 clk_debug_unregister(clk);
2546 clk_debug_unregister(clk->core);
2169
2170 clk_prepare_lock();
2171
2547
2548 clk_prepare_lock();
2549
2172 if (clk->ops == &clk_nodrv_ops) {
2173 pr_err("%s: unregistered clock: %s\n", __func__, clk->name);
2550 if (clk->core->ops == &clk_nodrv_ops) {
2551 pr_err("%s: unregistered clock: %s\n", __func__,
2552 clk->core->name);
2174 return;
2175 }
2176 /*
2177 * Assign empty clock ops for consumers that might still hold
2178 * a reference to this clock.
2179 */
2180 flags = clk_enable_lock();
2553 return;
2554 }
2555 /*
2556 * Assign empty clock ops for consumers that might still hold
2557 * a reference to this clock.
2558 */
2559 flags = clk_enable_lock();
2181 clk->ops = &clk_nodrv_ops;
2560 clk->core->ops = &clk_nodrv_ops;
2182 clk_enable_unlock(flags);
2183
2561 clk_enable_unlock(flags);
2562
2184 if (!hlist_empty(&clk->children)) {
2185 struct clk *child;
2563 if (!hlist_empty(&clk->core->children)) {
2564 struct clk_core *child;
2186 struct hlist_node *t;
2187
2188 /* Reparent all children to the orphan list. */
2565 struct hlist_node *t;
2566
2567 /* Reparent all children to the orphan list. */
2189 hlist_for_each_entry_safe(child, t, &clk->children, child_node)
2190 clk_set_parent(child, NULL);
2568 hlist_for_each_entry_safe(child, t, &clk->core->children,
2569 child_node)
2570 clk_core_set_parent(child, NULL);
2191 }
2192
2571 }
2572
2193 hlist_del_init(&clk->child_node);
2573 hlist_del_init(&clk->core->child_node);
2194
2574
2195 if (clk->prepare_count)
2575 if (clk->core->prepare_count)
2196 pr_warn("%s: unregistering prepared clock: %s\n",
2576 pr_warn("%s: unregistering prepared clock: %s\n",
2197 __func__, clk->name);
2198 kref_put(&clk->ref, __clk_release);
2577 __func__, clk->core->name);
2578 kref_put(&clk->core->ref, __clk_release);
2199
2200 clk_prepare_unlock();
2201}
2202EXPORT_SYMBOL_GPL(clk_unregister);
2203
2204static void devm_clk_release(struct device *dev, void *res)
2205{
2206 clk_unregister(*(struct clk **)res);

--- 51 unchanged lines hidden (view full) ---

2258}
2259EXPORT_SYMBOL_GPL(devm_clk_unregister);
2260
2261/*
2262 * clkdev helpers
2263 */
2264int __clk_get(struct clk *clk)
2265{
2579
2580 clk_prepare_unlock();
2581}
2582EXPORT_SYMBOL_GPL(clk_unregister);
2583
2584static void devm_clk_release(struct device *dev, void *res)
2585{
2586 clk_unregister(*(struct clk **)res);

--- 51 unchanged lines hidden (view full) ---

2638}
2639EXPORT_SYMBOL_GPL(devm_clk_unregister);
2640
2641/*
2642 * clkdev helpers
2643 */
2644int __clk_get(struct clk *clk)
2645{
2266 if (clk) {
2267 if (!try_module_get(clk->owner))
2646 struct clk_core *core = !clk ? NULL : clk->core;
2647
2648 if (core) {
2649 if (!try_module_get(core->owner))
2268 return 0;
2269
2650 return 0;
2651
2270 kref_get(&clk->ref);
2652 kref_get(&core->ref);
2271 }
2272 return 1;
2273}
2274
2275void __clk_put(struct clk *clk)
2276{
2277 struct module *owner;
2278
2279 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2280 return;
2281
2282 clk_prepare_lock();
2653 }
2654 return 1;
2655}
2656
2657void __clk_put(struct clk *clk)
2658{
2659 struct module *owner;
2660
2661 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2662 return;
2663
2664 clk_prepare_lock();
2283 owner = clk->owner;
2284 kref_put(&clk->ref, __clk_release);
2665
2666 hlist_del(&clk->child_node);
2667 clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
2668 owner = clk->core->owner;
2669 kref_put(&clk->core->ref, __clk_release);
2670
2285 clk_prepare_unlock();
2286
2287 module_put(owner);
2671 clk_prepare_unlock();
2672
2673 module_put(owner);
2674
2675 kfree(clk);
2288}
2289
2290/*** clk rate change notifiers ***/
2291
2292/**
2293 * clk_notifier_register - add a clk rate change notifier
2294 * @clk: struct clk * to watch
2295 * @nb: struct notifier_block * with callback info

--- 38 unchanged lines hidden (view full) ---

2334 cn->clk = clk;
2335 srcu_init_notifier_head(&cn->notifier_head);
2336
2337 list_add(&cn->node, &clk_notifier_list);
2338 }
2339
2340 ret = srcu_notifier_chain_register(&cn->notifier_head, nb);
2341
2676}
2677
2678/*** clk rate change notifiers ***/
2679
2680/**
2681 * clk_notifier_register - add a clk rate change notifier
2682 * @clk: struct clk * to watch
2683 * @nb: struct notifier_block * with callback info

--- 38 unchanged lines hidden (view full) ---

2722 cn->clk = clk;
2723 srcu_init_notifier_head(&cn->notifier_head);
2724
2725 list_add(&cn->node, &clk_notifier_list);
2726 }
2727
2728 ret = srcu_notifier_chain_register(&cn->notifier_head, nb);
2729
2342 clk->notifier_count++;
2730 clk->core->notifier_count++;
2343
2344out:
2345 clk_prepare_unlock();
2346
2347 return ret;
2348}
2349EXPORT_SYMBOL_GPL(clk_notifier_register);
2350

--- 20 unchanged lines hidden (view full) ---

2371
2372 list_for_each_entry(cn, &clk_notifier_list, node)
2373 if (cn->clk == clk)
2374 break;
2375
2376 if (cn->clk == clk) {
2377 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb);
2378
2731
2732out:
2733 clk_prepare_unlock();
2734
2735 return ret;
2736}
2737EXPORT_SYMBOL_GPL(clk_notifier_register);
2738

--- 20 unchanged lines hidden (view full) ---

2759
2760 list_for_each_entry(cn, &clk_notifier_list, node)
2761 if (cn->clk == clk)
2762 break;
2763
2764 if (cn->clk == clk) {
2765 ret = srcu_notifier_chain_unregister(&cn->notifier_head, nb);
2766
2379 clk->notifier_count--;
2767 clk->core->notifier_count--;
2380
2381 /* XXX the notifier code should handle this better */
2382 if (!cn->notifier_head.head) {
2383 srcu_cleanup_notifier_head(&cn->notifier_head);
2384 list_del(&cn->node);
2385 kfree(cn);
2386 }
2387

--- 113 unchanged lines hidden (view full) ---

2501 kfree(cp);
2502 break;
2503 }
2504 }
2505 mutex_unlock(&of_clk_mutex);
2506}
2507EXPORT_SYMBOL_GPL(of_clk_del_provider);
2508
2768
2769 /* XXX the notifier code should handle this better */
2770 if (!cn->notifier_head.head) {
2771 srcu_cleanup_notifier_head(&cn->notifier_head);
2772 list_del(&cn->node);
2773 kfree(cn);
2774 }
2775

--- 113 unchanged lines hidden (view full) ---

2889 kfree(cp);
2890 break;
2891 }
2892 }
2893 mutex_unlock(&of_clk_mutex);
2894}
2895EXPORT_SYMBOL_GPL(of_clk_del_provider);
2896
2509struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec)
2897struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec,
2898 const char *dev_id, const char *con_id)
2510{
2511 struct of_clk_provider *provider;
2512 struct clk *clk = ERR_PTR(-EPROBE_DEFER);
2513
2514 /* Check if we have such a provider in our array */
2515 list_for_each_entry(provider, &of_clk_providers, link) {
2516 if (provider->node == clkspec->np)
2517 clk = provider->get(clkspec, provider->data);
2899{
2900 struct of_clk_provider *provider;
2901 struct clk *clk = ERR_PTR(-EPROBE_DEFER);
2902
2903 /* Check if we have such a provider in our array */
2904 list_for_each_entry(provider, &of_clk_providers, link) {
2905 if (provider->node == clkspec->np)
2906 clk = provider->get(clkspec, provider->data);
2518 if (!IS_ERR(clk))
2907 if (!IS_ERR(clk)) {
2908 clk = __clk_create_clk(__clk_get_hw(clk), dev_id,
2909 con_id);
2910
2911 if (!IS_ERR(clk) && !__clk_get(clk)) {
2912 __clk_free_clk(clk);
2913 clk = ERR_PTR(-ENOENT);
2914 }
2915
2519 break;
2916 break;
2917 }
2520 }
2521
2522 return clk;
2523}
2524
2525struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
2526{
2527 struct clk *clk;
2528
2529 mutex_lock(&of_clk_mutex);
2918 }
2919
2920 return clk;
2921}
2922
2923struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
2924{
2925 struct clk *clk;
2926
2927 mutex_lock(&of_clk_mutex);
2530 clk = __of_clk_get_from_provider(clkspec);
2928 clk = __of_clk_get_from_provider(clkspec, NULL, __func__);
2531 mutex_unlock(&of_clk_mutex);
2532
2533 return clk;
2534}
2535
2536int of_clk_get_parent_count(struct device_node *np)
2537{
2538 return of_count_phandle_with_args(np, "clocks", "#clock-cells");

--- 143 unchanged lines hidden ---
2929 mutex_unlock(&of_clk_mutex);
2930
2931 return clk;
2932}
2933
2934int of_clk_get_parent_count(struct device_node *np)
2935{
2936 return of_count_phandle_with_args(np, "clocks", "#clock-cells");

--- 143 unchanged lines hidden ---