blob: c53205c574d1051e8705671636f19f049d1ed294 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Tony Lindgrenb9158552005-07-10 19:58:14 +01002 * linux/arch/arm/plat-omap/clock.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +03004 * Copyright (C) 2004 - 2008 Nokia corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
6 *
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00007 * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/kernel.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000014#include <linux/init.h>
15#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/list.h>
17#include <linux/errno.h>
18#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080019#include <linux/string.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000020#include <linux/clk.h>
Arjan van de Ven00431702006-01-12 18:42:23 +000021#include <linux/mutex.h>
Tony Lindgrenb824efa2006-04-02 17:46:20 +010022#include <linux/platform_device.h>
Russell Kingb851cb22008-05-22 16:38:50 +010023#include <linux/cpufreq.h>
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +030024#include <linux/debugfs.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/clock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Juha Yrjola7df34502006-06-26 16:16:22 -070029static LIST_HEAD(clocks);
Arjan van de Ven00431702006-01-12 18:42:23 +000030static DEFINE_MUTEX(clocks_mutex);
Juha Yrjola7df34502006-06-26 16:16:22 -070031static DEFINE_SPINLOCK(clockfw_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000033static struct clk_functions *arch_clock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000035/*-------------------------------------------------------------------------
Tony Lindgrenf07adc52006-01-17 15:27:09 -080036 * Standard clock functions defined in include/linux/clk.h
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000037 *-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Tony Lindgrenb824efa2006-04-02 17:46:20 +010039/*
40 * Returns a clock. Note that we first try to use device id on the bus
41 * and clock name. If this fails, we try to use clock name only.
42 */
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000043struct clk * clk_get(struct device *dev, const char *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 struct clk *p, *clk = ERR_PTR(-ENOENT);
Tony Lindgrenb824efa2006-04-02 17:46:20 +010046 int idno;
47
48 if (dev == NULL || dev->bus != &platform_bus_type)
49 idno = -1;
50 else
51 idno = to_platform_device(dev)->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Arjan van de Ven00431702006-01-12 18:42:23 +000053 mutex_lock(&clocks_mutex);
Tony Lindgrenb824efa2006-04-02 17:46:20 +010054
55 list_for_each_entry(p, &clocks, node) {
Russell Kingeee5b192008-11-04 21:42:54 +000056 if (p->id == idno && strcmp(id, p->name) == 0) {
Tony Lindgrenb824efa2006-04-02 17:46:20 +010057 clk = p;
Tony Lindgren67d4d832006-04-09 22:21:05 +010058 goto found;
Tony Lindgrenb824efa2006-04-02 17:46:20 +010059 }
60 }
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 list_for_each_entry(p, &clocks, node) {
Russell Kingeee5b192008-11-04 21:42:54 +000063 if (strcmp(id, p->name) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 clk = p;
65 break;
66 }
67 }
Tony Lindgrenb824efa2006-04-02 17:46:20 +010068
Tony Lindgren67d4d832006-04-09 22:21:05 +010069found:
Arjan van de Ven00431702006-01-12 18:42:23 +000070 mutex_unlock(&clocks_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 return clk;
73}
74EXPORT_SYMBOL(clk_get);
75
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000076int clk_enable(struct clk *clk)
77{
78 unsigned long flags;
79 int ret = 0;
80
Tony Lindgrenb824efa2006-04-02 17:46:20 +010081 if (clk == NULL || IS_ERR(clk))
82 return -EINVAL;
83
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000084 spin_lock_irqsave(&clockfw_lock, flags);
Tony Lindgrenf07adc52006-01-17 15:27:09 -080085 if (arch_clock->clk_enable)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000086 ret = arch_clock->clk_enable(clk);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000087 spin_unlock_irqrestore(&clockfw_lock, flags);
88
89 return ret;
90}
91EXPORT_SYMBOL(clk_enable);
92
93void clk_disable(struct clk *clk)
94{
95 unsigned long flags;
96
Tony Lindgrenb824efa2006-04-02 17:46:20 +010097 if (clk == NULL || IS_ERR(clk))
98 return;
99
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000100 spin_lock_irqsave(&clockfw_lock, flags);
Tony Lindgren7cf95772007-08-07 05:20:00 -0700101 if (clk->usecount == 0) {
102 printk(KERN_ERR "Trying disable clock %s with 0 usecount\n",
103 clk->name);
104 WARN_ON(1);
105 goto out;
106 }
107
Tony Lindgrenf07adc52006-01-17 15:27:09 -0800108 if (arch_clock->clk_disable)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000109 arch_clock->clk_disable(clk);
Tony Lindgren7cf95772007-08-07 05:20:00 -0700110
111out:
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000112 spin_unlock_irqrestore(&clockfw_lock, flags);
113}
114EXPORT_SYMBOL(clk_disable);
115
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000116int clk_get_usecount(struct clk *clk)
117{
118 unsigned long flags;
119 int ret = 0;
120
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100121 if (clk == NULL || IS_ERR(clk))
122 return 0;
123
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000124 spin_lock_irqsave(&clockfw_lock, flags);
125 ret = clk->usecount;
126 spin_unlock_irqrestore(&clockfw_lock, flags);
127
128 return ret;
129}
130EXPORT_SYMBOL(clk_get_usecount);
131
132unsigned long clk_get_rate(struct clk *clk)
133{
134 unsigned long flags;
135 unsigned long ret = 0;
136
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100137 if (clk == NULL || IS_ERR(clk))
138 return 0;
139
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000140 spin_lock_irqsave(&clockfw_lock, flags);
141 ret = clk->rate;
142 spin_unlock_irqrestore(&clockfw_lock, flags);
143
144 return ret;
145}
146EXPORT_SYMBOL(clk_get_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148void clk_put(struct clk *clk)
149{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151EXPORT_SYMBOL(clk_put);
152
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000153/*-------------------------------------------------------------------------
Tony Lindgrenf07adc52006-01-17 15:27:09 -0800154 * Optional clock functions defined in include/linux/clk.h
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000155 *-------------------------------------------------------------------------*/
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157long clk_round_rate(struct clk *clk, unsigned long rate)
158{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000159 unsigned long flags;
160 long ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100162 if (clk == NULL || IS_ERR(clk))
163 return ret;
164
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000165 spin_lock_irqsave(&clockfw_lock, flags);
166 if (arch_clock->clk_round_rate)
167 ret = arch_clock->clk_round_rate(clk, rate);
168 spin_unlock_irqrestore(&clockfw_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000170 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172EXPORT_SYMBOL(clk_round_rate);
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174int clk_set_rate(struct clk *clk, unsigned long rate)
175{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000176 unsigned long flags;
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100177 int ret = -EINVAL;
178
179 if (clk == NULL || IS_ERR(clk))
180 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000182 spin_lock_irqsave(&clockfw_lock, flags);
183 if (arch_clock->clk_set_rate)
184 ret = arch_clock->clk_set_rate(clk, rate);
185 spin_unlock_irqrestore(&clockfw_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 return ret;
188}
189EXPORT_SYMBOL(clk_set_rate);
190
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000191int clk_set_parent(struct clk *clk, struct clk *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000193 unsigned long flags;
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100194 int ret = -EINVAL;
195
196 if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent))
197 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000199 spin_lock_irqsave(&clockfw_lock, flags);
200 if (arch_clock->clk_set_parent)
201 ret = arch_clock->clk_set_parent(clk, parent);
202 spin_unlock_irqrestore(&clockfw_lock, flags);
203
204 return ret;
205}
206EXPORT_SYMBOL(clk_set_parent);
207
208struct clk *clk_get_parent(struct clk *clk)
209{
210 unsigned long flags;
211 struct clk * ret = NULL;
212
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100213 if (clk == NULL || IS_ERR(clk))
214 return ret;
215
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000216 spin_lock_irqsave(&clockfw_lock, flags);
217 if (arch_clock->clk_get_parent)
218 ret = arch_clock->clk_get_parent(clk);
219 spin_unlock_irqrestore(&clockfw_lock, flags);
220
221 return ret;
222}
223EXPORT_SYMBOL(clk_get_parent);
224
225/*-------------------------------------------------------------------------
226 * OMAP specific clock functions shared between omap1 and omap2
227 *-------------------------------------------------------------------------*/
228
229unsigned int __initdata mpurate;
230
231/*
232 * By default we use the rate set by the bootloader.
233 * You can override this with mpurate= cmdline option.
234 */
235static int __init omap_clk_setup(char *str)
236{
237 get_option(&str, &mpurate);
238
239 if (!mpurate)
240 return 1;
241
242 if (mpurate < 1000)
243 mpurate *= 1000000;
244
245 return 1;
246}
247__setup("mpurate=", omap_clk_setup);
248
249/* Used for clocks that always have same value as the parent clock */
250void followparent_recalc(struct clk *clk)
251{
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100252 if (clk == NULL || IS_ERR(clk))
253 return;
254
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000255 clk->rate = clk->parent->rate;
Imre Deakb1465bf2007-03-06 03:52:01 -0800256 if (unlikely(clk->flags & RATE_PROPAGATES))
257 propagate_rate(clk);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000258}
259
260/* Propagate rate to children */
261void propagate_rate(struct clk * tclk)
262{
263 struct clk *clkp;
264
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100265 if (tclk == NULL || IS_ERR(tclk))
266 return;
267
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000268 list_for_each_entry(clkp, &clocks, node) {
269 if (likely(clkp->parent != tclk))
270 continue;
271 if (likely((u32)clkp->recalc))
272 clkp->recalc(clkp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
Paul Walmsley6b8858a2008-03-18 10:35:15 +0200276/**
277 * recalculate_root_clocks - recalculate and propagate all root clocks
278 *
279 * Recalculates all root clocks (clocks with no parent), which if the
280 * clock's .recalc is set correctly, should also propagate their rates.
281 * Called at init.
282 */
283void recalculate_root_clocks(void)
284{
285 struct clk *clkp;
286
287 list_for_each_entry(clkp, &clocks, node) {
288 if (unlikely(!clkp->parent) && likely((u32)clkp->recalc))
289 clkp->recalc(clkp);
290 }
291}
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293int clk_register(struct clk *clk)
294{
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100295 if (clk == NULL || IS_ERR(clk))
296 return -EINVAL;
297
Arjan van de Ven00431702006-01-12 18:42:23 +0000298 mutex_lock(&clocks_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 list_add(&clk->node, &clocks);
300 if (clk->init)
301 clk->init(clk);
Arjan van de Ven00431702006-01-12 18:42:23 +0000302 mutex_unlock(&clocks_mutex);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return 0;
305}
306EXPORT_SYMBOL(clk_register);
307
308void clk_unregister(struct clk *clk)
309{
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100310 if (clk == NULL || IS_ERR(clk))
311 return;
312
Arjan van de Ven00431702006-01-12 18:42:23 +0000313 mutex_lock(&clocks_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 list_del(&clk->node);
Arjan van de Ven00431702006-01-12 18:42:23 +0000315 mutex_unlock(&clocks_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317EXPORT_SYMBOL(clk_unregister);
318
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000319void clk_deny_idle(struct clk *clk)
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100320{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000321 unsigned long flags;
322
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100323 if (clk == NULL || IS_ERR(clk))
324 return;
325
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000326 spin_lock_irqsave(&clockfw_lock, flags);
327 if (arch_clock->clk_deny_idle)
328 arch_clock->clk_deny_idle(clk);
329 spin_unlock_irqrestore(&clockfw_lock, flags);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100330}
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000331EXPORT_SYMBOL(clk_deny_idle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000333void clk_allow_idle(struct clk *clk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000335 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100337 if (clk == NULL || IS_ERR(clk))
338 return;
339
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000340 spin_lock_irqsave(&clockfw_lock, flags);
341 if (arch_clock->clk_allow_idle)
342 arch_clock->clk_allow_idle(clk);
343 spin_unlock_irqrestore(&clockfw_lock, flags);
344}
345EXPORT_SYMBOL(clk_allow_idle);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100346
Paul Walmsley6b8858a2008-03-18 10:35:15 +0200347void clk_enable_init_clocks(void)
348{
349 struct clk *clkp;
350
351 list_for_each_entry(clkp, &clocks, node) {
352 if (clkp->flags & ENABLE_ON_INIT)
353 clk_enable(clkp);
354 }
355}
356EXPORT_SYMBOL(clk_enable_init_clocks);
357
Russell King897dcde2008-11-04 16:35:03 +0000358/*
359 * Low level helpers
360 */
361static int clkll_enable_null(struct clk *clk)
362{
363 return 0;
364}
365
366static void clkll_disable_null(struct clk *clk)
367{
368}
369
370const struct clkops clkops_null = {
371 .enable = clkll_enable_null,
372 .disable = clkll_disable_null,
373};
374
Paul Walmsley6b8858a2008-03-18 10:35:15 +0200375#ifdef CONFIG_CPU_FREQ
376void clk_init_cpufreq_table(struct cpufreq_frequency_table **table)
377{
378 unsigned long flags;
379
380 spin_lock_irqsave(&clockfw_lock, flags);
381 if (arch_clock->clk_init_cpufreq_table)
382 arch_clock->clk_init_cpufreq_table(table);
383 spin_unlock_irqrestore(&clockfw_lock, flags);
384}
385EXPORT_SYMBOL(clk_init_cpufreq_table);
386#endif
387
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000388/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300390#ifdef CONFIG_OMAP_RESET_CLOCKS
391/*
392 * Disable any unused clocks left on by the bootloader
393 */
394static int __init clk_disable_unused(void)
395{
396 struct clk *ck;
397 unsigned long flags;
398
399 list_for_each_entry(ck, &clocks, node) {
Russell King897dcde2008-11-04 16:35:03 +0000400 if (ck->ops == &clkops_null)
401 continue;
402
403 if (ck->usecount > 0 || ck->enable_reg == 0)
Tony Lindgren90afd5c2006-09-25 13:27:20 +0300404 continue;
405
406 spin_lock_irqsave(&clockfw_lock, flags);
407 if (arch_clock->clk_disable_unused)
408 arch_clock->clk_disable_unused(ck);
409 spin_unlock_irqrestore(&clockfw_lock, flags);
410 }
411
412 return 0;
413}
414late_initcall(clk_disable_unused);
415#endif
416
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000417int __init clk_init(struct clk_functions * custom_clocks)
418{
419 if (!custom_clocks) {
420 printk(KERN_ERR "No custom clock functions registered\n");
421 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000424 arch_clock = custom_clocks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 return 0;
427}
Paul Walmsley6b8858a2008-03-18 10:35:15 +0200428
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +0300429#if defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS)
430/*
431 * debugfs support to trace clock tree hierarchy and attributes
432 */
433static struct dentry *clk_debugfs_root;
434
435static int clk_debugfs_register_one(struct clk *c)
436{
437 int err;
438 struct dentry *d, *child;
439 struct clk *pa = c->parent;
440 char s[255];
441 char *p = s;
442
443 p += sprintf(p, "%s", c->name);
444 if (c->id != 0)
445 sprintf(p, ":%d", c->id);
446 d = debugfs_create_dir(s, pa ? pa->dent : clk_debugfs_root);
Zhaoleie621f262008-11-04 13:35:07 -0800447 if (!d)
448 return -ENOMEM;
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +0300449 c->dent = d;
450
451 d = debugfs_create_u8("usecount", S_IRUGO, c->dent, (u8 *)&c->usecount);
Zhaoleie621f262008-11-04 13:35:07 -0800452 if (!d) {
453 err = -ENOMEM;
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +0300454 goto err_out;
455 }
456 d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate);
Zhaoleie621f262008-11-04 13:35:07 -0800457 if (!d) {
458 err = -ENOMEM;
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +0300459 goto err_out;
460 }
461 d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags);
Zhaoleie621f262008-11-04 13:35:07 -0800462 if (!d) {
463 err = -ENOMEM;
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +0300464 goto err_out;
465 }
466 return 0;
467
468err_out:
469 d = c->dent;
470 list_for_each_entry(child, &d->d_subdirs, d_u.d_child)
471 debugfs_remove(child);
472 debugfs_remove(c->dent);
473 return err;
474}
475
476static int clk_debugfs_register(struct clk *c)
477{
478 int err;
479 struct clk *pa = c->parent;
480
481 if (pa && !pa->dent) {
482 err = clk_debugfs_register(pa);
483 if (err)
484 return err;
485 }
486
487 if (!c->dent) {
488 err = clk_debugfs_register_one(c);
489 if (err)
490 return err;
491 }
492 return 0;
493}
494
495static int __init clk_debugfs_init(void)
496{
497 struct clk *c;
498 struct dentry *d;
499 int err;
500
501 d = debugfs_create_dir("clock", NULL);
Zhaoleie621f262008-11-04 13:35:07 -0800502 if (!d)
503 return -ENOMEM;
Hiroshi DOYU137b3ee2008-07-03 12:24:41 +0300504 clk_debugfs_root = d;
505
506 list_for_each_entry(c, &clocks, node) {
507 err = clk_debugfs_register(c);
508 if (err)
509 goto err_out;
510 }
511 return 0;
512err_out:
513 debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */
514 return err;
515}
516late_initcall(clk_debugfs_init);
517
518#endif /* defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS) */