blob: 29b6c7fa90d91883c49ac7f082316c91587a9946 [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>
20#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010021#include <linux/io.h>
Sekhar Norid6a61562009-08-31 15:48:03 +053022#include <linux/delay.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010023
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/hardware.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010025
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/psc.h>
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070027#include <mach/cputype.h>
Vladimir Barinov3e062b02007-06-05 16:36:55 +010028#include "clock.h"
29
Vladimir Barinov3e062b02007-06-05 16:36:55 +010030static LIST_HEAD(clocks);
31static DEFINE_MUTEX(clocks_mutex);
32static DEFINE_SPINLOCK(clockfw_lock);
33
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070034static unsigned psc_domain(struct clk *clk)
Vladimir Barinov3e062b02007-06-05 16:36:55 +010035{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070036 return (clk->flags & PSC_DSP)
37 ? DAVINCI_GPSC_DSPDOMAIN
38 : DAVINCI_GPSC_ARMDOMAIN;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010039}
Vladimir Barinov3e062b02007-06-05 16:36:55 +010040
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070041static void __clk_enable(struct clk *clk)
Vladimir Barinov3e062b02007-06-05 16:36:55 +010042{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070043 if (clk->parent)
44 __clk_enable(clk->parent);
45 if (clk->usecount++ == 0 && (clk->flags & CLK_PSC))
Sergei Shtylyov789a7852009-09-30 19:48:03 +040046 davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc, 1);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010047}
48
49static void __clk_disable(struct clk *clk)
50{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070051 if (WARN_ON(clk->usecount == 0))
Vladimir Barinov3e062b02007-06-05 16:36:55 +010052 return;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070053 if (--clk->usecount == 0 && !(clk->flags & CLK_PLL))
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 {
380 locktime = 20;
381 }
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
393 /*
394 * Wait for 4 OSCIN/CLKIN cycles to ensure that the PLLC has switched
395 * to bypass mode. Delay of 1us ensures we are good for all > 4MHz
396 * OSCIN/CLKIN inputs. Typically the input is ~25MHz.
397 */
398 udelay(1);
399
400 /* Reset and enable PLL */
401 ctrl &= ~(PLLCTL_PLLRST | PLLCTL_PLLDIS);
402 __raw_writel(ctrl, pll->base + PLLCTL);
403
404 if (pll->flags & PLL_HAS_PREDIV)
405 __raw_writel(prediv, pll->base + PREDIV);
406
407 __raw_writel(mult, pll->base + PLLM);
408
409 if (pll->flags & PLL_HAS_POSTDIV)
410 __raw_writel(postdiv, pll->base + POSTDIV);
411
412 /*
413 * Wait for PLL to reset properly, OMAP-L138 datasheet says
414 * 'min' time = 125ns
415 */
416 udelay(1);
417
418 /* Bring PLL out of reset */
419 ctrl |= PLLCTL_PLLRST;
420 __raw_writel(ctrl, pll->base + PLLCTL);
421
422 udelay(locktime);
423
424 /* Remove PLL from bypass mode */
425 ctrl |= PLLCTL_PLLEN;
426 __raw_writel(ctrl, pll->base + PLLCTL);
427
428 return 0;
429}
430EXPORT_SYMBOL(davinci_set_pllrate);
431
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700432int __init davinci_clk_init(struct davinci_clk *clocks)
433 {
434 struct davinci_clk *c;
435 struct clk *clk;
436
437 for (c = clocks; c->lk.clk; c++) {
438 clk = c->lk.clk;
439
Sekhar Noride381a92009-08-31 15:48:02 +0530440 if (!clk->recalc) {
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700441
Sekhar Noride381a92009-08-31 15:48:02 +0530442 /* Check if clock is a PLL */
443 if (clk->pll_data)
444 clk->recalc = clk_pllclk_recalc;
445
446 /* Else, if it is a PLL-derived clock */
447 else if (clk->flags & CLK_PLL)
448 clk->recalc = clk_sysclk_recalc;
449
450 /* Otherwise, it is a leaf clock (PSC clock) */
451 else if (clk->parent)
452 clk->recalc = clk_leafclk_recalc;
453 }
454
455 if (clk->recalc)
456 clk->rate = clk->recalc(clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700457
458 if (clk->lpsc)
459 clk->flags |= CLK_PSC;
460
461 clkdev_add(&c->lk);
462 clk_register(clk);
463
464 /* Turn on clocks that Linux doesn't otherwise manage */
465 if (clk->flags & ALWAYS_ENABLED)
466 clk_enable(clk);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100467 }
468
469 return 0;
470}
471
472#ifdef CONFIG_PROC_FS
473#include <linux/proc_fs.h>
474#include <linux/seq_file.h>
475
476static void *davinci_ck_start(struct seq_file *m, loff_t *pos)
477{
478 return *pos < 1 ? (void *)1 : NULL;
479}
480
481static void *davinci_ck_next(struct seq_file *m, void *v, loff_t *pos)
482{
483 ++*pos;
484 return NULL;
485}
486
487static void davinci_ck_stop(struct seq_file *m, void *v)
488{
489}
490
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700491#define CLKNAME_MAX 10 /* longest clock name */
492#define NEST_DELTA 2
493#define NEST_MAX 4
494
495static void
496dump_clock(struct seq_file *s, unsigned nest, struct clk *parent)
497{
498 char *state;
499 char buf[CLKNAME_MAX + NEST_DELTA * NEST_MAX];
500 struct clk *clk;
501 unsigned i;
502
503 if (parent->flags & CLK_PLL)
504 state = "pll";
505 else if (parent->flags & CLK_PSC)
506 state = "psc";
507 else
508 state = "";
509
510 /* <nest spaces> name <pad to end> */
511 memset(buf, ' ', sizeof(buf) - 1);
512 buf[sizeof(buf) - 1] = 0;
513 i = strlen(parent->name);
514 memcpy(buf + nest, parent->name,
515 min(i, (unsigned)(sizeof(buf) - 1 - nest)));
516
517 seq_printf(s, "%s users=%2d %-3s %9ld Hz\n",
518 buf, parent->usecount, state, clk_get_rate(parent));
519 /* REVISIT show device associations too */
520
521 /* cost is now small, but not linear... */
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530522 list_for_each_entry(clk, &parent->children, childnode) {
523 dump_clock(s, nest + NEST_DELTA, clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700524 }
525}
526
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100527static int davinci_ck_show(struct seq_file *m, void *v)
528{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700529 /* Show clock tree; we know the main oscillator is first.
530 * We trust nonzero usecounts equate to PSC enables...
531 */
532 mutex_lock(&clocks_mutex);
533 if (!list_empty(&clocks))
534 dump_clock(m, 0, list_first_entry(&clocks, struct clk, node));
535 mutex_unlock(&clocks_mutex);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100536
537 return 0;
538}
539
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100540static const struct seq_operations davinci_ck_op = {
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100541 .start = davinci_ck_start,
542 .next = davinci_ck_next,
543 .stop = davinci_ck_stop,
544 .show = davinci_ck_show
545};
546
547static int davinci_ck_open(struct inode *inode, struct file *file)
548{
549 return seq_open(file, &davinci_ck_op);
550}
551
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100552static const struct file_operations proc_davinci_ck_operations = {
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100553 .open = davinci_ck_open,
554 .read = seq_read,
555 .llseek = seq_lseek,
556 .release = seq_release,
557};
558
559static int __init davinci_ck_proc_init(void)
560{
Denis V. Lunev40ad35d2008-04-29 01:02:21 -0700561 proc_create("davinci_clocks", 0, NULL, &proc_davinci_ck_operations);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100562 return 0;
563
564}
565__initcall(davinci_ck_proc_init);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700566#endif /* CONFIG_DEBUG_PROC_FS */