blob: 123839332d50bfe42cc444230e9394a55d7a7687 [file] [log] [blame]
Vladimir Barinov3e062b02007-06-05 16:36:55 +01001/*
Kevin Hilmanc5b736d2009-03-20 17:29:01 -07002 * Clock and PLL control for DaVinci devices
Vladimir Barinov3e062b02007-06-05 16:36:55 +01003 *
Kevin Hilmanc5b736d2009-03-20 17:29:01 -07004 * Copyright (C) 2006-2007 Texas Instruments.
5 * Copyright (C) 2008-2009 Deep Root Systems, LLC
Vladimir Barinov3e062b02007-06-05 16:36:55 +01006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/errno.h>
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070017#include <linux/clk.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010018#include <linux/err.h>
19#include <linux/mutex.h>
Russell Kingfced80c2008-09-06 12:10:45 +010020#include <linux/io.h>
Sekhar Norid6a61562009-08-31 15:48:03 +053021#include <linux/delay.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010022
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/psc.h>
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070026#include <mach/cputype.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010027#include "clock.h"
28
Vladimir Barinov3e062b02007-06-05 16:36:55 +010029static LIST_HEAD(clocks);
30static DEFINE_MUTEX(clocks_mutex);
31static DEFINE_SPINLOCK(clockfw_lock);
32
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070033static unsigned psc_domain(struct clk *clk)
Vladimir Barinov3e062b02007-06-05 16:36:55 +010034{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070035 return (clk->flags & PSC_DSP)
36 ? DAVINCI_GPSC_DSPDOMAIN
37 : DAVINCI_GPSC_ARMDOMAIN;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010038}
Vladimir Barinov3e062b02007-06-05 16:36:55 +010039
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070040static void __clk_enable(struct clk *clk)
Vladimir Barinov3e062b02007-06-05 16:36:55 +010041{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070042 if (clk->parent)
43 __clk_enable(clk->parent);
44 if (clk->usecount++ == 0 && (clk->flags & CLK_PSC))
Sergei Shtylyov789a7852009-09-30 19:48:03 +040045 davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc, 1);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010046}
47
48static void __clk_disable(struct clk *clk)
49{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070050 if (WARN_ON(clk->usecount == 0))
Vladimir Barinov3e062b02007-06-05 16:36:55 +010051 return;
Chaithrika U S679f9212009-12-15 18:02:58 +053052 if (--clk->usecount == 0 && !(clk->flags & CLK_PLL) &&
53 (clk->flags & CLK_PSC))
Sergei Shtylyov789a7852009-09-30 19:48:03 +040054 davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc, 0);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070055 if (clk->parent)
56 __clk_disable(clk->parent);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010057}
58
59int clk_enable(struct clk *clk)
60{
61 unsigned long flags;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010062
63 if (clk == NULL || IS_ERR(clk))
64 return -EINVAL;
65
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070066 spin_lock_irqsave(&clockfw_lock, flags);
67 __clk_enable(clk);
68 spin_unlock_irqrestore(&clockfw_lock, flags);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010069
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070070 return 0;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010071}
72EXPORT_SYMBOL(clk_enable);
73
74void clk_disable(struct clk *clk)
75{
76 unsigned long flags;
77
78 if (clk == NULL || IS_ERR(clk))
79 return;
80
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070081 spin_lock_irqsave(&clockfw_lock, flags);
82 __clk_disable(clk);
83 spin_unlock_irqrestore(&clockfw_lock, flags);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010084}
85EXPORT_SYMBOL(clk_disable);
86
87unsigned long clk_get_rate(struct clk *clk)
88{
89 if (clk == NULL || IS_ERR(clk))
90 return -EINVAL;
91
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070092 return clk->rate;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010093}
94EXPORT_SYMBOL(clk_get_rate);
95
96long clk_round_rate(struct clk *clk, unsigned long rate)
97{
98 if (clk == NULL || IS_ERR(clk))
99 return -EINVAL;
100
Sekhar Norid6a61562009-08-31 15:48:03 +0530101 if (clk->round_rate)
102 return clk->round_rate(clk, rate);
103
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700104 return clk->rate;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100105}
106EXPORT_SYMBOL(clk_round_rate);
107
Sekhar Norid6a61562009-08-31 15:48:03 +0530108/* Propagate rate to children */
109static void propagate_rate(struct clk *root)
110{
111 struct clk *clk;
112
113 list_for_each_entry(clk, &root->children, childnode) {
114 if (clk->recalc)
115 clk->rate = clk->recalc(clk);
116 propagate_rate(clk);
117 }
118}
119
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100120int clk_set_rate(struct clk *clk, unsigned long rate)
121{
Sekhar Norid6a61562009-08-31 15:48:03 +0530122 unsigned long flags;
123 int ret = -EINVAL;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100124
Sekhar Norid6a61562009-08-31 15:48:03 +0530125 if (clk == NULL || IS_ERR(clk))
126 return ret;
127
128 spin_lock_irqsave(&clockfw_lock, flags);
129 if (clk->set_rate)
130 ret = clk->set_rate(clk, rate);
131 if (ret == 0) {
132 if (clk->recalc)
133 clk->rate = clk->recalc(clk);
134 propagate_rate(clk);
135 }
136 spin_unlock_irqrestore(&clockfw_lock, flags);
137
138 return ret;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100139}
140EXPORT_SYMBOL(clk_set_rate);
141
Sekhar Norib82a51e2009-08-31 15:48:04 +0530142int clk_set_parent(struct clk *clk, struct clk *parent)
143{
144 unsigned long flags;
145
146 if (clk == NULL || IS_ERR(clk))
147 return -EINVAL;
148
149 /* Cannot change parent on enabled clock */
150 if (WARN_ON(clk->usecount))
151 return -EINVAL;
152
153 mutex_lock(&clocks_mutex);
154 clk->parent = parent;
155 list_del_init(&clk->childnode);
156 list_add(&clk->childnode, &clk->parent->children);
157 mutex_unlock(&clocks_mutex);
158
159 spin_lock_irqsave(&clockfw_lock, flags);
160 if (clk->recalc)
161 clk->rate = clk->recalc(clk);
162 propagate_rate(clk);
163 spin_unlock_irqrestore(&clockfw_lock, flags);
164
165 return 0;
166}
167EXPORT_SYMBOL(clk_set_parent);
168
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100169int clk_register(struct clk *clk)
170{
171 if (clk == NULL || IS_ERR(clk))
172 return -EINVAL;
173
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700174 if (WARN(clk->parent && !clk->parent->rate,
175 "CLK: %s parent %s has no rate!\n",
176 clk->name, clk->parent->name))
177 return -EINVAL;
178
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530179 INIT_LIST_HEAD(&clk->children);
180
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100181 mutex_lock(&clocks_mutex);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700182 list_add_tail(&clk->node, &clocks);
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530183 if (clk->parent)
184 list_add_tail(&clk->childnode, &clk->parent->children);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100185 mutex_unlock(&clocks_mutex);
186
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700187 /* If rate is already set, use it */
188 if (clk->rate)
189 return 0;
190
Sekhar Noride381a92009-08-31 15:48:02 +0530191 /* Else, see if there is a way to calculate it */
192 if (clk->recalc)
193 clk->rate = clk->recalc(clk);
194
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700195 /* Otherwise, default to parent rate */
Sekhar Noride381a92009-08-31 15:48:02 +0530196 else if (clk->parent)
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700197 clk->rate = clk->parent->rate;
198
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100199 return 0;
200}
201EXPORT_SYMBOL(clk_register);
202
203void clk_unregister(struct clk *clk)
204{
205 if (clk == NULL || IS_ERR(clk))
206 return;
207
208 mutex_lock(&clocks_mutex);
209 list_del(&clk->node);
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530210 list_del(&clk->childnode);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100211 mutex_unlock(&clocks_mutex);
212}
213EXPORT_SYMBOL(clk_unregister);
214
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700215#ifdef CONFIG_DAVINCI_RESET_CLOCKS
216/*
217 * Disable any unused clocks left on by the bootloader
218 */
219static int __init clk_disable_unused(void)
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100220{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700221 struct clk *ck;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100222
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700223 spin_lock_irq(&clockfw_lock);
224 list_for_each_entry(ck, &clocks, node) {
225 if (ck->usecount > 0)
226 continue;
227 if (!(ck->flags & CLK_PSC))
228 continue;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100229
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700230 /* ignore if in Disabled or SwRstDisable states */
Sergei Shtylyov789a7852009-09-30 19:48:03 +0400231 if (!davinci_psc_is_clk_active(ck->gpsc, ck->lpsc))
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700232 continue;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100233
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700234 pr_info("Clocks: disable unused %s\n", ck->name);
Sergei Shtylyov789a7852009-09-30 19:48:03 +0400235 davinci_psc_config(psc_domain(ck), ck->gpsc, ck->lpsc, 0);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700236 }
237 spin_unlock_irq(&clockfw_lock);
238
239 return 0;
240}
241late_initcall(clk_disable_unused);
242#endif
243
Sekhar Noride381a92009-08-31 15:48:02 +0530244static unsigned long clk_sysclk_recalc(struct clk *clk)
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700245{
246 u32 v, plldiv;
247 struct pll_data *pll;
Sekhar Noride381a92009-08-31 15:48:02 +0530248 unsigned long rate = clk->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700249
250 /* If this is the PLL base clock, no more calculations needed */
251 if (clk->pll_data)
Sekhar Noride381a92009-08-31 15:48:02 +0530252 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700253
254 if (WARN_ON(!clk->parent))
Sekhar Noride381a92009-08-31 15:48:02 +0530255 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700256
Sekhar Noride381a92009-08-31 15:48:02 +0530257 rate = clk->parent->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700258
259 /* Otherwise, the parent must be a PLL */
260 if (WARN_ON(!clk->parent->pll_data))
Sekhar Noride381a92009-08-31 15:48:02 +0530261 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700262
263 pll = clk->parent->pll_data;
264
265 /* If pre-PLL, source clock is before the multiplier and divider(s) */
266 if (clk->flags & PRE_PLL)
Sekhar Noride381a92009-08-31 15:48:02 +0530267 rate = pll->input_rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700268
269 if (!clk->div_reg)
Sekhar Noride381a92009-08-31 15:48:02 +0530270 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700271
272 v = __raw_readl(pll->base + clk->div_reg);
273 if (v & PLLDIV_EN) {
274 plldiv = (v & PLLDIV_RATIO_MASK) + 1;
275 if (plldiv)
Sekhar Noride381a92009-08-31 15:48:02 +0530276 rate /= plldiv;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700277 }
Sekhar Noride381a92009-08-31 15:48:02 +0530278
279 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700280}
281
Sekhar Noride381a92009-08-31 15:48:02 +0530282static unsigned long clk_leafclk_recalc(struct clk *clk)
283{
284 if (WARN_ON(!clk->parent))
285 return clk->rate;
286
287 return clk->parent->rate;
288}
289
290static unsigned long clk_pllclk_recalc(struct clk *clk)
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700291{
292 u32 ctrl, mult = 1, prediv = 1, postdiv = 1;
293 u8 bypass;
294 struct pll_data *pll = clk->pll_data;
Sekhar Noride381a92009-08-31 15:48:02 +0530295 unsigned long rate = clk->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700296
297 pll->base = IO_ADDRESS(pll->phys_base);
298 ctrl = __raw_readl(pll->base + PLLCTL);
Sekhar Noride381a92009-08-31 15:48:02 +0530299 rate = pll->input_rate = clk->parent->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700300
301 if (ctrl & PLLCTL_PLLEN) {
302 bypass = 0;
303 mult = __raw_readl(pll->base + PLLM);
Sandeep Paulrajfb8fcb82009-06-11 09:41:05 -0400304 if (cpu_is_davinci_dm365())
305 mult = 2 * (mult & PLLM_PLLM_MASK);
306 else
307 mult = (mult & PLLM_PLLM_MASK) + 1;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700308 } else
309 bypass = 1;
310
311 if (pll->flags & PLL_HAS_PREDIV) {
312 prediv = __raw_readl(pll->base + PREDIV);
313 if (prediv & PLLDIV_EN)
314 prediv = (prediv & PLLDIV_RATIO_MASK) + 1;
315 else
316 prediv = 1;
317 }
318
319 /* pre-divider is fixed, but (some?) chips won't report that */
320 if (cpu_is_davinci_dm355() && pll->num == 1)
321 prediv = 8;
322
323 if (pll->flags & PLL_HAS_POSTDIV) {
324 postdiv = __raw_readl(pll->base + POSTDIV);
325 if (postdiv & PLLDIV_EN)
326 postdiv = (postdiv & PLLDIV_RATIO_MASK) + 1;
327 else
328 postdiv = 1;
329 }
330
331 if (!bypass) {
Sekhar Noride381a92009-08-31 15:48:02 +0530332 rate /= prediv;
333 rate *= mult;
334 rate /= postdiv;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700335 }
336
337 pr_debug("PLL%d: input = %lu MHz [ ",
338 pll->num, clk->parent->rate / 1000000);
339 if (bypass)
340 pr_debug("bypass ");
341 if (prediv > 1)
342 pr_debug("/ %d ", prediv);
343 if (mult > 1)
344 pr_debug("* %d ", mult);
345 if (postdiv > 1)
346 pr_debug("/ %d ", postdiv);
Sekhar Noride381a92009-08-31 15:48:02 +0530347 pr_debug("] --> %lu MHz output.\n", rate / 1000000);
348
349 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700350}
351
Sekhar Norid6a61562009-08-31 15:48:03 +0530352/**
353 * davinci_set_pllrate - set the output rate of a given PLL.
354 *
355 * Note: Currently tested to work with OMAP-L138 only.
356 *
357 * @pll: pll whose rate needs to be changed.
358 * @prediv: The pre divider value. Passing 0 disables the pre-divider.
359 * @pllm: The multiplier value. Passing 0 leads to multiply-by-one.
360 * @postdiv: The post divider value. Passing 0 disables the post-divider.
361 */
362int davinci_set_pllrate(struct pll_data *pll, unsigned int prediv,
363 unsigned int mult, unsigned int postdiv)
364{
365 u32 ctrl;
366 unsigned int locktime;
367
368 if (pll->base == NULL)
369 return -EINVAL;
370
371 /*
372 * PLL lock time required per OMAP-L138 datasheet is
373 * (2000 * prediv)/sqrt(pllm) OSCIN cycles. We approximate sqrt(pllm)
374 * as 4 and OSCIN cycle as 25 MHz.
375 */
376 if (prediv) {
377 locktime = ((2000 * prediv) / 100);
378 prediv = (prediv - 1) | PLLDIV_EN;
379 } else {
Sekhar Nori9a219a92009-11-16 17:21:33 +0530380 locktime = PLL_LOCK_TIME;
Sekhar Norid6a61562009-08-31 15:48:03 +0530381 }
382 if (postdiv)
383 postdiv = (postdiv - 1) | PLLDIV_EN;
384 if (mult)
385 mult = mult - 1;
386
387 ctrl = __raw_readl(pll->base + PLLCTL);
388
389 /* Switch the PLL to bypass mode */
390 ctrl &= ~(PLLCTL_PLLENSRC | PLLCTL_PLLEN);
391 __raw_writel(ctrl, pll->base + PLLCTL);
392
Sekhar Nori9a219a92009-11-16 17:21:33 +0530393 udelay(PLL_BYPASS_TIME);
Sekhar Norid6a61562009-08-31 15:48:03 +0530394
395 /* Reset and enable PLL */
396 ctrl &= ~(PLLCTL_PLLRST | PLLCTL_PLLDIS);
397 __raw_writel(ctrl, pll->base + PLLCTL);
398
399 if (pll->flags & PLL_HAS_PREDIV)
400 __raw_writel(prediv, pll->base + PREDIV);
401
402 __raw_writel(mult, pll->base + PLLM);
403
404 if (pll->flags & PLL_HAS_POSTDIV)
405 __raw_writel(postdiv, pll->base + POSTDIV);
406
Sekhar Nori9a219a92009-11-16 17:21:33 +0530407 udelay(PLL_RESET_TIME);
Sekhar Norid6a61562009-08-31 15:48:03 +0530408
409 /* Bring PLL out of reset */
410 ctrl |= PLLCTL_PLLRST;
411 __raw_writel(ctrl, pll->base + PLLCTL);
412
413 udelay(locktime);
414
415 /* Remove PLL from bypass mode */
416 ctrl |= PLLCTL_PLLEN;
417 __raw_writel(ctrl, pll->base + PLLCTL);
418
419 return 0;
420}
421EXPORT_SYMBOL(davinci_set_pllrate);
422
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700423int __init davinci_clk_init(struct davinci_clk *clocks)
424 {
425 struct davinci_clk *c;
426 struct clk *clk;
427
428 for (c = clocks; c->lk.clk; c++) {
429 clk = c->lk.clk;
430
Sekhar Noride381a92009-08-31 15:48:02 +0530431 if (!clk->recalc) {
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700432
Sekhar Noride381a92009-08-31 15:48:02 +0530433 /* Check if clock is a PLL */
434 if (clk->pll_data)
435 clk->recalc = clk_pllclk_recalc;
436
437 /* Else, if it is a PLL-derived clock */
438 else if (clk->flags & CLK_PLL)
439 clk->recalc = clk_sysclk_recalc;
440
441 /* Otherwise, it is a leaf clock (PSC clock) */
442 else if (clk->parent)
443 clk->recalc = clk_leafclk_recalc;
444 }
445
446 if (clk->recalc)
447 clk->rate = clk->recalc(clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700448
449 if (clk->lpsc)
450 clk->flags |= CLK_PSC;
451
452 clkdev_add(&c->lk);
453 clk_register(clk);
454
455 /* Turn on clocks that Linux doesn't otherwise manage */
456 if (clk->flags & ALWAYS_ENABLED)
457 clk_enable(clk);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100458 }
459
460 return 0;
461}
462
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530463#ifdef CONFIG_DEBUG_FS
464
465#include <linux/debugfs.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100466#include <linux/seq_file.h>
467
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700468#define CLKNAME_MAX 10 /* longest clock name */
469#define NEST_DELTA 2
470#define NEST_MAX 4
471
472static void
473dump_clock(struct seq_file *s, unsigned nest, struct clk *parent)
474{
475 char *state;
476 char buf[CLKNAME_MAX + NEST_DELTA * NEST_MAX];
477 struct clk *clk;
478 unsigned i;
479
480 if (parent->flags & CLK_PLL)
481 state = "pll";
482 else if (parent->flags & CLK_PSC)
483 state = "psc";
484 else
485 state = "";
486
487 /* <nest spaces> name <pad to end> */
488 memset(buf, ' ', sizeof(buf) - 1);
489 buf[sizeof(buf) - 1] = 0;
490 i = strlen(parent->name);
491 memcpy(buf + nest, parent->name,
492 min(i, (unsigned)(sizeof(buf) - 1 - nest)));
493
494 seq_printf(s, "%s users=%2d %-3s %9ld Hz\n",
495 buf, parent->usecount, state, clk_get_rate(parent));
496 /* REVISIT show device associations too */
497
498 /* cost is now small, but not linear... */
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530499 list_for_each_entry(clk, &parent->children, childnode) {
500 dump_clock(s, nest + NEST_DELTA, clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700501 }
502}
503
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100504static int davinci_ck_show(struct seq_file *m, void *v)
505{
Sekhar Norif979aa62009-12-03 15:36:51 +0530506 struct clk *clk;
507
508 /*
509 * Show clock tree; We trust nonzero usecounts equate to PSC enables...
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700510 */
511 mutex_lock(&clocks_mutex);
Sekhar Norif979aa62009-12-03 15:36:51 +0530512 list_for_each_entry(clk, &clocks, node)
513 if (!clk->parent)
514 dump_clock(m, 0, clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700515 mutex_unlock(&clocks_mutex);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100516
517 return 0;
518}
519
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100520static int davinci_ck_open(struct inode *inode, struct file *file)
521{
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530522 return single_open(file, davinci_ck_show, NULL);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100523}
524
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530525static const struct file_operations davinci_ck_operations = {
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100526 .open = davinci_ck_open,
527 .read = seq_read,
528 .llseek = seq_lseek,
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530529 .release = single_release,
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100530};
531
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530532static int __init davinci_clk_debugfs_init(void)
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100533{
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530534 debugfs_create_file("davinci_clocks", S_IFREG | S_IRUGO, NULL, NULL,
535 &davinci_ck_operations);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100536 return 0;
537
538}
Sekhar Nori2f72e8d2009-12-03 15:36:52 +0530539device_initcall(davinci_clk_debugfs_init);
540#endif /* CONFIG_DEBUG_FS */