blob: 165aa9c748f6bb419cd0a8d84d50a8970346d1b2 [file] [log] [blame]
Colin Crossd8611962010-01-28 16:40:29 -08001/*
2 *
3 * Copyright (C) 2010 Google, Inc.
4 *
5 * Author:
6 * Colin Cross <ccross@google.com>
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/kernel.h>
20#include <linux/clk.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010021#include <linux/clkdev.h>
Colin Cross4729fd72011-02-12 16:43:05 -080022#include <linux/debugfs.h>
23#include <linux/delay.h>
24#include <linux/init.h>
25#include <linux/list.h>
26#include <linux/module.h>
27#include <linux/sched.h>
28#include <linux/seq_file.h>
29#include <linux/slab.h>
30
31#include <mach/clk.h>
Colin Crossd8611962010-01-28 16:40:29 -080032
Colin Cross71fc84c2010-06-07 20:49:46 -070033#include "board.h"
Colin Cross41cfe362011-02-12 15:52:04 -080034#include "clock.h"
Colin Crossd8611962010-01-28 16:40:29 -080035
Colin Cross4729fd72011-02-12 16:43:05 -080036/*
37 * Locking:
38 *
39 * Each struct clk has a spinlock.
40 *
41 * To avoid AB-BA locking problems, locks must always be traversed from child
42 * clock to parent clock. For example, when enabling a clock, the clock's lock
43 * is taken, and then clk_enable is called on the parent, which take's the
44 * parent clock's lock. There is one exceptions to this ordering: When dumping
45 * the clock tree through debugfs. In this case, clk_lock_all is called,
46 * which attemps to iterate through the entire list of clocks and take every
47 * clock lock. If any call to spin_trylock fails, all locked clocks are
48 * unlocked, and the process is retried. When all the locks are held,
49 * the only clock operation that can be called is clk_get_rate_all_locked.
50 *
51 * Within a single clock, no clock operation can call another clock operation
52 * on itself, except for clk_get_rate_locked and clk_set_rate_locked. Any
53 * clock operation can call any other clock operation on any of it's possible
54 * parents.
55 *
56 * An additional mutex, clock_list_lock, is used to protect the list of all
57 * clocks.
58 *
59 * The clock operations must lock internally to protect against
60 * read-modify-write on registers that are shared by multiple clocks
61 */
62static DEFINE_MUTEX(clock_list_lock);
Colin Crossd8611962010-01-28 16:40:29 -080063static LIST_HEAD(clocks);
64
Colin Crossd8611962010-01-28 16:40:29 -080065struct clk *tegra_get_clock_by_name(const char *name)
66{
67 struct clk *c;
68 struct clk *ret = NULL;
Colin Cross4729fd72011-02-12 16:43:05 -080069 mutex_lock(&clock_list_lock);
Colin Crossd8611962010-01-28 16:40:29 -080070 list_for_each_entry(c, &clocks, node) {
71 if (strcmp(c->name, name) == 0) {
72 ret = c;
73 break;
74 }
75 }
Colin Cross4729fd72011-02-12 16:43:05 -080076 mutex_unlock(&clock_list_lock);
Colin Crossd8611962010-01-28 16:40:29 -080077 return ret;
78}
79
Colin Cross4729fd72011-02-12 16:43:05 -080080/* Must be called with c->spinlock held */
81static unsigned long clk_predict_rate_from_parent(struct clk *c, struct clk *p)
Colin Cross71fc84c2010-06-07 20:49:46 -070082{
83 u64 rate;
84
Colin Cross4729fd72011-02-12 16:43:05 -080085 rate = clk_get_rate(p);
Colin Cross71fc84c2010-06-07 20:49:46 -070086
87 if (c->mul != 0 && c->div != 0) {
Colin Cross4729fd72011-02-12 16:43:05 -080088 rate *= c->mul;
Colin Cross71fc84c2010-06-07 20:49:46 -070089 do_div(rate, c->div);
90 }
91
Colin Cross4729fd72011-02-12 16:43:05 -080092 return rate;
Colin Cross71fc84c2010-06-07 20:49:46 -070093}
94
Colin Cross4729fd72011-02-12 16:43:05 -080095/* Must be called with c->spinlock held */
96unsigned long clk_get_rate_locked(struct clk *c)
97{
98 unsigned long rate;
99
100 if (c->parent)
101 rate = clk_predict_rate_from_parent(c, c->parent);
102 else
103 rate = c->rate;
104
105 return rate;
106}
107
108unsigned long clk_get_rate(struct clk *c)
109{
110 unsigned long flags;
111 unsigned long rate;
112
113 spin_lock_irqsave(&c->spinlock, flags);
114
115 rate = clk_get_rate_locked(c);
116
117 spin_unlock_irqrestore(&c->spinlock, flags);
118
119 return rate;
120}
121EXPORT_SYMBOL(clk_get_rate);
122
Colin Crossd8611962010-01-28 16:40:29 -0800123int clk_reparent(struct clk *c, struct clk *parent)
124{
Colin Crossd8611962010-01-28 16:40:29 -0800125 c->parent = parent;
Colin Crossd8611962010-01-28 16:40:29 -0800126 return 0;
127}
128
Colin Crossd8611962010-01-28 16:40:29 -0800129void clk_init(struct clk *c)
130{
Colin Cross4729fd72011-02-12 16:43:05 -0800131 spin_lock_init(&c->spinlock);
Colin Crossd8611962010-01-28 16:40:29 -0800132
133 if (c->ops && c->ops->init)
134 c->ops->init(c);
135
Colin Crossf0355302010-10-13 19:16:02 -0700136 if (!c->ops || !c->ops->enable) {
137 c->refcnt++;
Colin Cross4db4afb2011-02-20 23:35:07 -0800138 c->set = true;
Colin Crossf0355302010-10-13 19:16:02 -0700139 if (c->parent)
140 c->state = c->parent->state;
141 else
142 c->state = ON;
143 }
144
Colin Cross4729fd72011-02-12 16:43:05 -0800145 mutex_lock(&clock_list_lock);
Colin Crossd8611962010-01-28 16:40:29 -0800146 list_add(&c->node, &clocks);
Colin Cross4729fd72011-02-12 16:43:05 -0800147 mutex_unlock(&clock_list_lock);
Colin Crossd8611962010-01-28 16:40:29 -0800148}
149
Colin Cross4729fd72011-02-12 16:43:05 -0800150int clk_enable(struct clk *c)
Colin Crossd8611962010-01-28 16:40:29 -0800151{
Colin Cross4729fd72011-02-12 16:43:05 -0800152 int ret = 0;
153 unsigned long flags;
154
155 spin_lock_irqsave(&c->spinlock, flags);
Colin Crossbd41ef52010-09-08 20:01:04 -0700156
Colin Crossd8611962010-01-28 16:40:29 -0800157 if (c->refcnt == 0) {
158 if (c->parent) {
Colin Cross4729fd72011-02-12 16:43:05 -0800159 ret = clk_enable(c->parent);
Colin Crossd8611962010-01-28 16:40:29 -0800160 if (ret)
Colin Cross4729fd72011-02-12 16:43:05 -0800161 goto out;
Colin Crossd8611962010-01-28 16:40:29 -0800162 }
163
164 if (c->ops && c->ops->enable) {
165 ret = c->ops->enable(c);
166 if (ret) {
167 if (c->parent)
Colin Cross4729fd72011-02-12 16:43:05 -0800168 clk_disable(c->parent);
169 goto out;
Colin Crossd8611962010-01-28 16:40:29 -0800170 }
171 c->state = ON;
Colin Cross4db4afb2011-02-20 23:35:07 -0800172 c->set = true;
Colin Crossd8611962010-01-28 16:40:29 -0800173 }
174 }
175 c->refcnt++;
Colin Cross4729fd72011-02-12 16:43:05 -0800176out:
177 spin_unlock_irqrestore(&c->spinlock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800178 return ret;
179}
180EXPORT_SYMBOL(clk_enable);
181
Colin Cross4729fd72011-02-12 16:43:05 -0800182void clk_disable(struct clk *c)
Colin Crossd8611962010-01-28 16:40:29 -0800183{
Colin Cross4729fd72011-02-12 16:43:05 -0800184 unsigned long flags;
185
186 spin_lock_irqsave(&c->spinlock, flags);
187
Colin Crossd8611962010-01-28 16:40:29 -0800188 if (c->refcnt == 0) {
189 WARN(1, "Attempting to disable clock %s with refcnt 0", c->name);
Colin Cross4729fd72011-02-12 16:43:05 -0800190 spin_unlock_irqrestore(&c->spinlock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800191 return;
192 }
193 if (c->refcnt == 1) {
194 if (c->ops && c->ops->disable)
195 c->ops->disable(c);
196
197 if (c->parent)
Colin Cross4729fd72011-02-12 16:43:05 -0800198 clk_disable(c->parent);
Colin Crossd8611962010-01-28 16:40:29 -0800199
200 c->state = OFF;
201 }
202 c->refcnt--;
Colin Crossd8611962010-01-28 16:40:29 -0800203
Colin Cross4729fd72011-02-12 16:43:05 -0800204 spin_unlock_irqrestore(&c->spinlock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800205}
206EXPORT_SYMBOL(clk_disable);
207
Colin Crossd8611962010-01-28 16:40:29 -0800208int clk_set_parent(struct clk *c, struct clk *parent)
209{
210 int ret;
211 unsigned long flags;
Colin Cross4729fd72011-02-12 16:43:05 -0800212 unsigned long new_rate;
213 unsigned long old_rate;
214
215 spin_lock_irqsave(&c->spinlock, flags);
216
217 if (!c->ops || !c->ops->set_parent) {
218 ret = -ENOSYS;
219 goto out;
220 }
221
222 new_rate = clk_predict_rate_from_parent(c, parent);
223 old_rate = clk_get_rate_locked(c);
224
225 ret = c->ops->set_parent(c, parent);
226 if (ret)
227 goto out;
228
229out:
230 spin_unlock_irqrestore(&c->spinlock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800231 return ret;
232}
233EXPORT_SYMBOL(clk_set_parent);
234
235struct clk *clk_get_parent(struct clk *c)
236{
237 return c->parent;
238}
239EXPORT_SYMBOL(clk_get_parent);
240
Colin Cross71fc84c2010-06-07 20:49:46 -0700241int clk_set_rate_locked(struct clk *c, unsigned long rate)
242{
Colin Cross4729fd72011-02-12 16:43:05 -0800243 if (!c->ops || !c->ops->set_rate)
244 return -ENOSYS;
Colin Cross71fc84c2010-06-07 20:49:46 -0700245
246 if (rate > c->max_rate)
247 rate = c->max_rate;
248
Colin Cross4729fd72011-02-12 16:43:05 -0800249 return c->ops->set_rate(c, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -0700250}
251
Colin Crossd8611962010-01-28 16:40:29 -0800252int clk_set_rate(struct clk *c, unsigned long rate)
253{
Colin Cross4729fd72011-02-12 16:43:05 -0800254 int ret;
Colin Crossd8611962010-01-28 16:40:29 -0800255 unsigned long flags;
256
Colin Cross4729fd72011-02-12 16:43:05 -0800257 spin_lock_irqsave(&c->spinlock, flags);
258
Colin Cross71fc84c2010-06-07 20:49:46 -0700259 ret = clk_set_rate_locked(c, rate);
Colin Cross4729fd72011-02-12 16:43:05 -0800260
261 spin_unlock_irqrestore(&c->spinlock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800262
263 return ret;
264}
265EXPORT_SYMBOL(clk_set_rate);
266
Colin Cross4729fd72011-02-12 16:43:05 -0800267
268/* Must be called with clocks lock and all indvidual clock locks held */
269unsigned long clk_get_rate_all_locked(struct clk *c)
Colin Crossd8611962010-01-28 16:40:29 -0800270{
Colin Cross4729fd72011-02-12 16:43:05 -0800271 u64 rate;
272 int mul = 1;
273 int div = 1;
274 struct clk *p = c;
Colin Crossd8611962010-01-28 16:40:29 -0800275
Colin Cross4729fd72011-02-12 16:43:05 -0800276 while (p) {
277 c = p;
278 if (c->mul != 0 && c->div != 0) {
279 mul *= c->mul;
280 div *= c->div;
281 }
282 p = c->parent;
283 }
Colin Crossd8611962010-01-28 16:40:29 -0800284
Colin Cross4729fd72011-02-12 16:43:05 -0800285 rate = c->rate;
286 rate *= mul;
287 do_div(rate, div);
Colin Crossd8611962010-01-28 16:40:29 -0800288
Colin Cross4729fd72011-02-12 16:43:05 -0800289 return rate;
Colin Crossd8611962010-01-28 16:40:29 -0800290}
Colin Crossd8611962010-01-28 16:40:29 -0800291
Colin Cross71fc84c2010-06-07 20:49:46 -0700292long clk_round_rate(struct clk *c, unsigned long rate)
293{
Colin Cross4729fd72011-02-12 16:43:05 -0800294 unsigned long flags;
295 long ret;
296
297 spin_lock_irqsave(&c->spinlock, flags);
298
299 if (!c->ops || !c->ops->round_rate) {
300 ret = -ENOSYS;
301 goto out;
302 }
Colin Cross71fc84c2010-06-07 20:49:46 -0700303
304 if (rate > c->max_rate)
305 rate = c->max_rate;
306
Colin Cross4729fd72011-02-12 16:43:05 -0800307 ret = c->ops->round_rate(c, rate);
308
309out:
310 spin_unlock_irqrestore(&c->spinlock, flags);
311 return ret;
Colin Cross71fc84c2010-06-07 20:49:46 -0700312}
313EXPORT_SYMBOL(clk_round_rate);
314
Colin Crossd8611962010-01-28 16:40:29 -0800315static int tegra_clk_init_one_from_table(struct tegra_clk_init_table *table)
316{
317 struct clk *c;
318 struct clk *p;
319
320 int ret = 0;
321
322 c = tegra_get_clock_by_name(table->name);
323
324 if (!c) {
325 pr_warning("Unable to initialize clock %s\n",
326 table->name);
327 return -ENODEV;
328 }
329
330 if (table->parent) {
331 p = tegra_get_clock_by_name(table->parent);
332 if (!p) {
333 pr_warning("Unable to find parent %s of clock %s\n",
334 table->parent, table->name);
335 return -ENODEV;
336 }
337
338 if (c->parent != p) {
339 ret = clk_set_parent(c, p);
340 if (ret) {
341 pr_warning("Unable to set parent %s of clock %s: %d\n",
342 table->parent, table->name, ret);
343 return -EINVAL;
344 }
345 }
346 }
347
348 if (table->rate && table->rate != clk_get_rate(c)) {
349 ret = clk_set_rate(c, table->rate);
350 if (ret) {
351 pr_warning("Unable to set clock %s to rate %lu: %d\n",
352 table->name, table->rate, ret);
353 return -EINVAL;
354 }
355 }
356
357 if (table->enabled) {
358 ret = clk_enable(c);
359 if (ret) {
360 pr_warning("Unable to enable clock %s: %d\n",
361 table->name, ret);
362 return -EINVAL;
363 }
364 }
365
366 return 0;
367}
368
369void tegra_clk_init_from_table(struct tegra_clk_init_table *table)
370{
371 for (; table->name; table++)
372 tegra_clk_init_one_from_table(table);
373}
374EXPORT_SYMBOL(tegra_clk_init_from_table);
375
376void tegra_periph_reset_deassert(struct clk *c)
377{
378 tegra2_periph_reset_deassert(c);
379}
380EXPORT_SYMBOL(tegra_periph_reset_deassert);
381
382void tegra_periph_reset_assert(struct clk *c)
383{
384 tegra2_periph_reset_assert(c);
385}
386EXPORT_SYMBOL(tegra_periph_reset_assert);
387
Colin Cross71fc84c2010-06-07 20:49:46 -0700388void __init tegra_init_clock(void)
Colin Crossd8611962010-01-28 16:40:29 -0800389{
390 tegra2_init_clocks();
Colin Cross71fc84c2010-06-07 20:49:46 -0700391}
392
Colin Cross9743b382011-02-12 18:24:32 -0800393/*
394 * The SDMMC controllers have extra bits in the clock source register that
395 * adjust the delay between the clock and data to compenstate for delays
396 * on the PCB.
397 */
398void tegra_sdmmc_tap_delay(struct clk *c, int delay)
399{
400 unsigned long flags;
401
402 spin_lock_irqsave(&c->spinlock, flags);
403 tegra2_sdmmc_tap_delay(c, delay);
404 spin_unlock_irqrestore(&c->spinlock, flags);
405}
406
Colin Crossd8611962010-01-28 16:40:29 -0800407#ifdef CONFIG_DEBUG_FS
Colin Cross4729fd72011-02-12 16:43:05 -0800408
409static int __clk_lock_all_spinlocks(void)
410{
411 struct clk *c;
412
413 list_for_each_entry(c, &clocks, node)
414 if (!spin_trylock(&c->spinlock))
415 goto unlock_spinlocks;
416
417 return 0;
418
419unlock_spinlocks:
420 list_for_each_entry_continue_reverse(c, &clocks, node)
421 spin_unlock(&c->spinlock);
422
423 return -EAGAIN;
424}
425
426static void __clk_unlock_all_spinlocks(void)
427{
428 struct clk *c;
429
430 list_for_each_entry_reverse(c, &clocks, node)
431 spin_unlock(&c->spinlock);
432}
433
434/*
435 * This function retries until it can take all locks, and may take
436 * an arbitrarily long time to complete.
437 * Must be called with irqs enabled, returns with irqs disabled
438 * Must be called with clock_list_lock held
439 */
440static void clk_lock_all(void)
441{
442 int ret;
443retry:
444 local_irq_disable();
445
446 ret = __clk_lock_all_spinlocks();
447 if (ret)
448 goto failed_spinlocks;
449
450 /* All locks taken successfully, return */
451 return;
452
453failed_spinlocks:
454 local_irq_enable();
455 yield();
456 goto retry;
457}
458
459/*
460 * Unlocks all clocks after a clk_lock_all
461 * Must be called with irqs disabled, returns with irqs enabled
462 * Must be called with clock_list_lock held
463 */
464static void clk_unlock_all(void)
465{
466 __clk_unlock_all_spinlocks();
467
468 local_irq_enable();
469}
470
Colin Crossd8611962010-01-28 16:40:29 -0800471static struct dentry *clk_debugfs_root;
472
473
474static void clock_tree_show_one(struct seq_file *s, struct clk *c, int level)
475{
476 struct clk *child;
Colin Crossd8611962010-01-28 16:40:29 -0800477 const char *state = "uninit";
Colin Cross71fc84c2010-06-07 20:49:46 -0700478 char div[8] = {0};
Colin Crossd8611962010-01-28 16:40:29 -0800479
480 if (c->state == ON)
481 state = "on";
482 else if (c->state == OFF)
483 state = "off";
484
485 if (c->mul != 0 && c->div != 0) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700486 if (c->mul > c->div) {
487 int mul = c->mul / c->div;
488 int mul2 = (c->mul * 10 / c->div) % 10;
489 int mul3 = (c->mul * 10) % c->div;
490 if (mul2 == 0 && mul3 == 0)
491 snprintf(div, sizeof(div), "x%d", mul);
492 else if (mul3 == 0)
493 snprintf(div, sizeof(div), "x%d.%d", mul, mul2);
494 else
495 snprintf(div, sizeof(div), "x%d.%d..", mul, mul2);
496 } else {
Colin Crossd8611962010-01-28 16:40:29 -0800497 snprintf(div, sizeof(div), "%d%s", c->div / c->mul,
498 (c->div % c->mul) ? ".5" : "");
Colin Cross71fc84c2010-06-07 20:49:46 -0700499 }
Colin Crossd8611962010-01-28 16:40:29 -0800500 }
501
Colin Cross71fc84c2010-06-07 20:49:46 -0700502 seq_printf(s, "%*s%c%c%-*s %-6s %-3d %-8s %-10lu\n",
503 level * 3 + 1, "",
504 c->rate > c->max_rate ? '!' : ' ',
505 !c->set ? '*' : ' ',
Colin Crossd8611962010-01-28 16:40:29 -0800506 30 - level * 3, c->name,
Colin Cross4729fd72011-02-12 16:43:05 -0800507 state, c->refcnt, div, clk_get_rate_all_locked(c));
508
509 list_for_each_entry(child, &clocks, node) {
510 if (child->parent != c)
511 continue;
512
Colin Crossd8611962010-01-28 16:40:29 -0800513 clock_tree_show_one(s, child, level + 1);
514 }
515}
516
517static int clock_tree_show(struct seq_file *s, void *data)
518{
519 struct clk *c;
Colin Cross71fc84c2010-06-07 20:49:46 -0700520 seq_printf(s, " clock state ref div rate\n");
521 seq_printf(s, "--------------------------------------------------------------\n");
Colin Cross4729fd72011-02-12 16:43:05 -0800522
523 mutex_lock(&clock_list_lock);
524
525 clk_lock_all();
526
Colin Crossd8611962010-01-28 16:40:29 -0800527 list_for_each_entry(c, &clocks, node)
528 if (c->parent == NULL)
529 clock_tree_show_one(s, c, 0);
Colin Cross4729fd72011-02-12 16:43:05 -0800530
531 clk_unlock_all();
532
533 mutex_unlock(&clock_list_lock);
Colin Crossd8611962010-01-28 16:40:29 -0800534 return 0;
535}
536
537static int clock_tree_open(struct inode *inode, struct file *file)
538{
539 return single_open(file, clock_tree_show, inode->i_private);
540}
541
542static const struct file_operations clock_tree_fops = {
543 .open = clock_tree_open,
544 .read = seq_read,
545 .llseek = seq_lseek,
546 .release = single_release,
547};
548
549static int possible_parents_show(struct seq_file *s, void *data)
550{
551 struct clk *c = s->private;
552 int i;
553
554 for (i = 0; c->inputs[i].input; i++) {
555 char *first = (i == 0) ? "" : " ";
556 seq_printf(s, "%s%s", first, c->inputs[i].input->name);
557 }
558 seq_printf(s, "\n");
559 return 0;
560}
561
562static int possible_parents_open(struct inode *inode, struct file *file)
563{
564 return single_open(file, possible_parents_show, inode->i_private);
565}
566
567static const struct file_operations possible_parents_fops = {
568 .open = possible_parents_open,
569 .read = seq_read,
570 .llseek = seq_lseek,
571 .release = single_release,
572};
573
574static int clk_debugfs_register_one(struct clk *c)
575{
576 struct dentry *d, *child, *child_tmp;
577
578 d = debugfs_create_dir(c->name, clk_debugfs_root);
579 if (!d)
580 return -ENOMEM;
581 c->dent = d;
582
583 d = debugfs_create_u8("refcnt", S_IRUGO, c->dent, (u8 *)&c->refcnt);
584 if (!d)
585 goto err_out;
586
587 d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate);
588 if (!d)
589 goto err_out;
590
591 d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags);
592 if (!d)
593 goto err_out;
594
595 if (c->inputs) {
596 d = debugfs_create_file("possible_parents", S_IRUGO, c->dent,
597 c, &possible_parents_fops);
598 if (!d)
599 goto err_out;
600 }
601
602 return 0;
603
604err_out:
605 d = c->dent;
606 list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
607 debugfs_remove(child);
608 debugfs_remove(c->dent);
609 return -ENOMEM;
610}
611
612static int clk_debugfs_register(struct clk *c)
613{
614 int err;
615 struct clk *pa = c->parent;
616
617 if (pa && !pa->dent) {
618 err = clk_debugfs_register(pa);
619 if (err)
620 return err;
621 }
622
623 if (!c->dent) {
624 err = clk_debugfs_register_one(c);
625 if (err)
626 return err;
627 }
628 return 0;
629}
630
631static int __init clk_debugfs_init(void)
632{
633 struct clk *c;
634 struct dentry *d;
635 int err = -ENOMEM;
636
637 d = debugfs_create_dir("clock", NULL);
638 if (!d)
639 return -ENOMEM;
640 clk_debugfs_root = d;
641
642 d = debugfs_create_file("clock_tree", S_IRUGO, clk_debugfs_root, NULL,
643 &clock_tree_fops);
644 if (!d)
645 goto err_out;
646
647 list_for_each_entry(c, &clocks, node) {
648 err = clk_debugfs_register(c);
649 if (err)
650 goto err_out;
651 }
652 return 0;
653err_out:
654 debugfs_remove_recursive(clk_debugfs_root);
655 return err;
656}
657
658late_initcall(clk_debugfs_init);
659#endif