blob: e7696fcf05d8309e499d1205710371eb1b212e59 [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))
Mark A. Greerd81d1882009-04-15 12:39:33 -070046 davinci_psc_config(psc_domain(clk), clk->psc_ctlr,
47 clk->lpsc, 1);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010048}
49
50static void __clk_disable(struct clk *clk)
51{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070052 if (WARN_ON(clk->usecount == 0))
Vladimir Barinov3e062b02007-06-05 16:36:55 +010053 return;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070054 if (--clk->usecount == 0 && !(clk->flags & CLK_PLL))
Mark A. Greerd81d1882009-04-15 12:39:33 -070055 davinci_psc_config(psc_domain(clk), clk->psc_ctlr,
56 clk->lpsc, 0);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070057 if (clk->parent)
58 __clk_disable(clk->parent);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010059}
60
61int clk_enable(struct clk *clk)
62{
63 unsigned long flags;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010064
65 if (clk == NULL || IS_ERR(clk))
66 return -EINVAL;
67
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070068 spin_lock_irqsave(&clockfw_lock, flags);
69 __clk_enable(clk);
70 spin_unlock_irqrestore(&clockfw_lock, flags);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010071
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070072 return 0;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010073}
74EXPORT_SYMBOL(clk_enable);
75
76void clk_disable(struct clk *clk)
77{
78 unsigned long flags;
79
80 if (clk == NULL || IS_ERR(clk))
81 return;
82
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070083 spin_lock_irqsave(&clockfw_lock, flags);
84 __clk_disable(clk);
85 spin_unlock_irqrestore(&clockfw_lock, flags);
Vladimir Barinov3e062b02007-06-05 16:36:55 +010086}
87EXPORT_SYMBOL(clk_disable);
88
89unsigned long clk_get_rate(struct clk *clk)
90{
91 if (clk == NULL || IS_ERR(clk))
92 return -EINVAL;
93
Kevin Hilmanc5b736d2009-03-20 17:29:01 -070094 return clk->rate;
Vladimir Barinov3e062b02007-06-05 16:36:55 +010095}
96EXPORT_SYMBOL(clk_get_rate);
97
98long clk_round_rate(struct clk *clk, unsigned long rate)
99{
100 if (clk == NULL || IS_ERR(clk))
101 return -EINVAL;
102
Sekhar Norid6a61562009-08-31 15:48:03 +0530103 if (clk->round_rate)
104 return clk->round_rate(clk, rate);
105
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700106 return clk->rate;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100107}
108EXPORT_SYMBOL(clk_round_rate);
109
Sekhar Norid6a61562009-08-31 15:48:03 +0530110/* Propagate rate to children */
111static void propagate_rate(struct clk *root)
112{
113 struct clk *clk;
114
115 list_for_each_entry(clk, &root->children, childnode) {
116 if (clk->recalc)
117 clk->rate = clk->recalc(clk);
118 propagate_rate(clk);
119 }
120}
121
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100122int clk_set_rate(struct clk *clk, unsigned long rate)
123{
Sekhar Norid6a61562009-08-31 15:48:03 +0530124 unsigned long flags;
125 int ret = -EINVAL;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100126
Sekhar Norid6a61562009-08-31 15:48:03 +0530127 if (clk == NULL || IS_ERR(clk))
128 return ret;
129
130 spin_lock_irqsave(&clockfw_lock, flags);
131 if (clk->set_rate)
132 ret = clk->set_rate(clk, rate);
133 if (ret == 0) {
134 if (clk->recalc)
135 clk->rate = clk->recalc(clk);
136 propagate_rate(clk);
137 }
138 spin_unlock_irqrestore(&clockfw_lock, flags);
139
140 return ret;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100141}
142EXPORT_SYMBOL(clk_set_rate);
143
Sekhar Norib82a51e2009-08-31 15:48:04 +0530144int clk_set_parent(struct clk *clk, struct clk *parent)
145{
146 unsigned long flags;
147
148 if (clk == NULL || IS_ERR(clk))
149 return -EINVAL;
150
151 /* Cannot change parent on enabled clock */
152 if (WARN_ON(clk->usecount))
153 return -EINVAL;
154
155 mutex_lock(&clocks_mutex);
156 clk->parent = parent;
157 list_del_init(&clk->childnode);
158 list_add(&clk->childnode, &clk->parent->children);
159 mutex_unlock(&clocks_mutex);
160
161 spin_lock_irqsave(&clockfw_lock, flags);
162 if (clk->recalc)
163 clk->rate = clk->recalc(clk);
164 propagate_rate(clk);
165 spin_unlock_irqrestore(&clockfw_lock, flags);
166
167 return 0;
168}
169EXPORT_SYMBOL(clk_set_parent);
170
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100171int clk_register(struct clk *clk)
172{
173 if (clk == NULL || IS_ERR(clk))
174 return -EINVAL;
175
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700176 if (WARN(clk->parent && !clk->parent->rate,
177 "CLK: %s parent %s has no rate!\n",
178 clk->name, clk->parent->name))
179 return -EINVAL;
180
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530181 INIT_LIST_HEAD(&clk->children);
182
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100183 mutex_lock(&clocks_mutex);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700184 list_add_tail(&clk->node, &clocks);
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530185 if (clk->parent)
186 list_add_tail(&clk->childnode, &clk->parent->children);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100187 mutex_unlock(&clocks_mutex);
188
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700189 /* If rate is already set, use it */
190 if (clk->rate)
191 return 0;
192
Sekhar Noride381a92009-08-31 15:48:02 +0530193 /* Else, see if there is a way to calculate it */
194 if (clk->recalc)
195 clk->rate = clk->recalc(clk);
196
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700197 /* Otherwise, default to parent rate */
Sekhar Noride381a92009-08-31 15:48:02 +0530198 else if (clk->parent)
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700199 clk->rate = clk->parent->rate;
200
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100201 return 0;
202}
203EXPORT_SYMBOL(clk_register);
204
205void clk_unregister(struct clk *clk)
206{
207 if (clk == NULL || IS_ERR(clk))
208 return;
209
210 mutex_lock(&clocks_mutex);
211 list_del(&clk->node);
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530212 list_del(&clk->childnode);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100213 mutex_unlock(&clocks_mutex);
214}
215EXPORT_SYMBOL(clk_unregister);
216
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700217#ifdef CONFIG_DAVINCI_RESET_CLOCKS
218/*
219 * Disable any unused clocks left on by the bootloader
220 */
221static int __init clk_disable_unused(void)
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100222{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700223 struct clk *ck;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100224
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700225 spin_lock_irq(&clockfw_lock);
226 list_for_each_entry(ck, &clocks, node) {
227 if (ck->usecount > 0)
228 continue;
229 if (!(ck->flags & CLK_PSC))
230 continue;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100231
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700232 /* ignore if in Disabled or SwRstDisable states */
Mark A. Greerd81d1882009-04-15 12:39:33 -0700233 if (!davinci_psc_is_clk_active(ck->psc_ctlr, ck->lpsc))
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700234 continue;
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100235
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700236 pr_info("Clocks: disable unused %s\n", ck->name);
Mark A. Greerd81d1882009-04-15 12:39:33 -0700237 davinci_psc_config(psc_domain(ck), ck->psc_ctlr, ck->lpsc, 0);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700238 }
239 spin_unlock_irq(&clockfw_lock);
240
241 return 0;
242}
243late_initcall(clk_disable_unused);
244#endif
245
Sekhar Noride381a92009-08-31 15:48:02 +0530246static unsigned long clk_sysclk_recalc(struct clk *clk)
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700247{
248 u32 v, plldiv;
249 struct pll_data *pll;
Sekhar Noride381a92009-08-31 15:48:02 +0530250 unsigned long rate = clk->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700251
252 /* If this is the PLL base clock, no more calculations needed */
253 if (clk->pll_data)
Sekhar Noride381a92009-08-31 15:48:02 +0530254 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700255
256 if (WARN_ON(!clk->parent))
Sekhar Noride381a92009-08-31 15:48:02 +0530257 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700258
Sekhar Noride381a92009-08-31 15:48:02 +0530259 rate = clk->parent->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700260
261 /* Otherwise, the parent must be a PLL */
262 if (WARN_ON(!clk->parent->pll_data))
Sekhar Noride381a92009-08-31 15:48:02 +0530263 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700264
265 pll = clk->parent->pll_data;
266
267 /* If pre-PLL, source clock is before the multiplier and divider(s) */
268 if (clk->flags & PRE_PLL)
Sekhar Noride381a92009-08-31 15:48:02 +0530269 rate = pll->input_rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700270
271 if (!clk->div_reg)
Sekhar Noride381a92009-08-31 15:48:02 +0530272 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700273
274 v = __raw_readl(pll->base + clk->div_reg);
275 if (v & PLLDIV_EN) {
276 plldiv = (v & PLLDIV_RATIO_MASK) + 1;
277 if (plldiv)
Sekhar Noride381a92009-08-31 15:48:02 +0530278 rate /= plldiv;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700279 }
Sekhar Noride381a92009-08-31 15:48:02 +0530280
281 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700282}
283
Sekhar Noride381a92009-08-31 15:48:02 +0530284static unsigned long clk_leafclk_recalc(struct clk *clk)
285{
286 if (WARN_ON(!clk->parent))
287 return clk->rate;
288
289 return clk->parent->rate;
290}
291
292static unsigned long clk_pllclk_recalc(struct clk *clk)
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700293{
294 u32 ctrl, mult = 1, prediv = 1, postdiv = 1;
295 u8 bypass;
296 struct pll_data *pll = clk->pll_data;
Sekhar Noride381a92009-08-31 15:48:02 +0530297 unsigned long rate = clk->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700298
299 pll->base = IO_ADDRESS(pll->phys_base);
300 ctrl = __raw_readl(pll->base + PLLCTL);
Sekhar Noride381a92009-08-31 15:48:02 +0530301 rate = pll->input_rate = clk->parent->rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700302
303 if (ctrl & PLLCTL_PLLEN) {
304 bypass = 0;
305 mult = __raw_readl(pll->base + PLLM);
Sandeep Paulrajfb8fcb82009-06-11 09:41:05 -0400306 if (cpu_is_davinci_dm365())
307 mult = 2 * (mult & PLLM_PLLM_MASK);
308 else
309 mult = (mult & PLLM_PLLM_MASK) + 1;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700310 } else
311 bypass = 1;
312
313 if (pll->flags & PLL_HAS_PREDIV) {
314 prediv = __raw_readl(pll->base + PREDIV);
315 if (prediv & PLLDIV_EN)
316 prediv = (prediv & PLLDIV_RATIO_MASK) + 1;
317 else
318 prediv = 1;
319 }
320
321 /* pre-divider is fixed, but (some?) chips won't report that */
322 if (cpu_is_davinci_dm355() && pll->num == 1)
323 prediv = 8;
324
325 if (pll->flags & PLL_HAS_POSTDIV) {
326 postdiv = __raw_readl(pll->base + POSTDIV);
327 if (postdiv & PLLDIV_EN)
328 postdiv = (postdiv & PLLDIV_RATIO_MASK) + 1;
329 else
330 postdiv = 1;
331 }
332
333 if (!bypass) {
Sekhar Noride381a92009-08-31 15:48:02 +0530334 rate /= prediv;
335 rate *= mult;
336 rate /= postdiv;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700337 }
338
339 pr_debug("PLL%d: input = %lu MHz [ ",
340 pll->num, clk->parent->rate / 1000000);
341 if (bypass)
342 pr_debug("bypass ");
343 if (prediv > 1)
344 pr_debug("/ %d ", prediv);
345 if (mult > 1)
346 pr_debug("* %d ", mult);
347 if (postdiv > 1)
348 pr_debug("/ %d ", postdiv);
Sekhar Noride381a92009-08-31 15:48:02 +0530349 pr_debug("] --> %lu MHz output.\n", rate / 1000000);
350
351 return rate;
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700352}
353
Sekhar Norid6a61562009-08-31 15:48:03 +0530354/**
355 * davinci_set_pllrate - set the output rate of a given PLL.
356 *
357 * Note: Currently tested to work with OMAP-L138 only.
358 *
359 * @pll: pll whose rate needs to be changed.
360 * @prediv: The pre divider value. Passing 0 disables the pre-divider.
361 * @pllm: The multiplier value. Passing 0 leads to multiply-by-one.
362 * @postdiv: The post divider value. Passing 0 disables the post-divider.
363 */
364int davinci_set_pllrate(struct pll_data *pll, unsigned int prediv,
365 unsigned int mult, unsigned int postdiv)
366{
367 u32 ctrl;
368 unsigned int locktime;
369
370 if (pll->base == NULL)
371 return -EINVAL;
372
373 /*
374 * PLL lock time required per OMAP-L138 datasheet is
375 * (2000 * prediv)/sqrt(pllm) OSCIN cycles. We approximate sqrt(pllm)
376 * as 4 and OSCIN cycle as 25 MHz.
377 */
378 if (prediv) {
379 locktime = ((2000 * prediv) / 100);
380 prediv = (prediv - 1) | PLLDIV_EN;
381 } else {
382 locktime = 20;
383 }
384 if (postdiv)
385 postdiv = (postdiv - 1) | PLLDIV_EN;
386 if (mult)
387 mult = mult - 1;
388
389 ctrl = __raw_readl(pll->base + PLLCTL);
390
391 /* Switch the PLL to bypass mode */
392 ctrl &= ~(PLLCTL_PLLENSRC | PLLCTL_PLLEN);
393 __raw_writel(ctrl, pll->base + PLLCTL);
394
395 /*
396 * Wait for 4 OSCIN/CLKIN cycles to ensure that the PLLC has switched
397 * to bypass mode. Delay of 1us ensures we are good for all > 4MHz
398 * OSCIN/CLKIN inputs. Typically the input is ~25MHz.
399 */
400 udelay(1);
401
402 /* Reset and enable PLL */
403 ctrl &= ~(PLLCTL_PLLRST | PLLCTL_PLLDIS);
404 __raw_writel(ctrl, pll->base + PLLCTL);
405
406 if (pll->flags & PLL_HAS_PREDIV)
407 __raw_writel(prediv, pll->base + PREDIV);
408
409 __raw_writel(mult, pll->base + PLLM);
410
411 if (pll->flags & PLL_HAS_POSTDIV)
412 __raw_writel(postdiv, pll->base + POSTDIV);
413
414 /*
415 * Wait for PLL to reset properly, OMAP-L138 datasheet says
416 * 'min' time = 125ns
417 */
418 udelay(1);
419
420 /* Bring PLL out of reset */
421 ctrl |= PLLCTL_PLLRST;
422 __raw_writel(ctrl, pll->base + PLLCTL);
423
424 udelay(locktime);
425
426 /* Remove PLL from bypass mode */
427 ctrl |= PLLCTL_PLLEN;
428 __raw_writel(ctrl, pll->base + PLLCTL);
429
430 return 0;
431}
432EXPORT_SYMBOL(davinci_set_pllrate);
433
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700434int __init davinci_clk_init(struct davinci_clk *clocks)
435 {
436 struct davinci_clk *c;
437 struct clk *clk;
438
439 for (c = clocks; c->lk.clk; c++) {
440 clk = c->lk.clk;
441
Sekhar Noride381a92009-08-31 15:48:02 +0530442 if (!clk->recalc) {
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700443
Sekhar Noride381a92009-08-31 15:48:02 +0530444 /* Check if clock is a PLL */
445 if (clk->pll_data)
446 clk->recalc = clk_pllclk_recalc;
447
448 /* Else, if it is a PLL-derived clock */
449 else if (clk->flags & CLK_PLL)
450 clk->recalc = clk_sysclk_recalc;
451
452 /* Otherwise, it is a leaf clock (PSC clock) */
453 else if (clk->parent)
454 clk->recalc = clk_leafclk_recalc;
455 }
456
457 if (clk->recalc)
458 clk->rate = clk->recalc(clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700459
460 if (clk->lpsc)
461 clk->flags |= CLK_PSC;
462
463 clkdev_add(&c->lk);
464 clk_register(clk);
465
466 /* Turn on clocks that Linux doesn't otherwise manage */
467 if (clk->flags & ALWAYS_ENABLED)
468 clk_enable(clk);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100469 }
470
471 return 0;
472}
473
474#ifdef CONFIG_PROC_FS
475#include <linux/proc_fs.h>
476#include <linux/seq_file.h>
477
478static void *davinci_ck_start(struct seq_file *m, loff_t *pos)
479{
480 return *pos < 1 ? (void *)1 : NULL;
481}
482
483static void *davinci_ck_next(struct seq_file *m, void *v, loff_t *pos)
484{
485 ++*pos;
486 return NULL;
487}
488
489static void davinci_ck_stop(struct seq_file *m, void *v)
490{
491}
492
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700493#define CLKNAME_MAX 10 /* longest clock name */
494#define NEST_DELTA 2
495#define NEST_MAX 4
496
497static void
498dump_clock(struct seq_file *s, unsigned nest, struct clk *parent)
499{
500 char *state;
501 char buf[CLKNAME_MAX + NEST_DELTA * NEST_MAX];
502 struct clk *clk;
503 unsigned i;
504
505 if (parent->flags & CLK_PLL)
506 state = "pll";
507 else if (parent->flags & CLK_PSC)
508 state = "psc";
509 else
510 state = "";
511
512 /* <nest spaces> name <pad to end> */
513 memset(buf, ' ', sizeof(buf) - 1);
514 buf[sizeof(buf) - 1] = 0;
515 i = strlen(parent->name);
516 memcpy(buf + nest, parent->name,
517 min(i, (unsigned)(sizeof(buf) - 1 - nest)));
518
519 seq_printf(s, "%s users=%2d %-3s %9ld Hz\n",
520 buf, parent->usecount, state, clk_get_rate(parent));
521 /* REVISIT show device associations too */
522
523 /* cost is now small, but not linear... */
Sekhar Norif02bf3b2009-08-31 15:48:01 +0530524 list_for_each_entry(clk, &parent->children, childnode) {
525 dump_clock(s, nest + NEST_DELTA, clk);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700526 }
527}
528
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100529static int davinci_ck_show(struct seq_file *m, void *v)
530{
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700531 /* Show clock tree; we know the main oscillator is first.
532 * We trust nonzero usecounts equate to PSC enables...
533 */
534 mutex_lock(&clocks_mutex);
535 if (!list_empty(&clocks))
536 dump_clock(m, 0, list_first_entry(&clocks, struct clk, node));
537 mutex_unlock(&clocks_mutex);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100538
539 return 0;
540}
541
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100542static const struct seq_operations davinci_ck_op = {
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100543 .start = davinci_ck_start,
544 .next = davinci_ck_next,
545 .stop = davinci_ck_stop,
546 .show = davinci_ck_show
547};
548
549static int davinci_ck_open(struct inode *inode, struct file *file)
550{
551 return seq_open(file, &davinci_ck_op);
552}
553
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100554static const struct file_operations proc_davinci_ck_operations = {
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100555 .open = davinci_ck_open,
556 .read = seq_read,
557 .llseek = seq_lseek,
558 .release = seq_release,
559};
560
561static int __init davinci_ck_proc_init(void)
562{
Denis V. Lunev40ad35d2008-04-29 01:02:21 -0700563 proc_create("davinci_clocks", 0, NULL, &proc_davinci_ck_operations);
Vladimir Barinov3e062b02007-06-05 16:36:55 +0100564 return 0;
565
566}
567__initcall(davinci_ck_proc_init);
Kevin Hilmanc5b736d2009-03-20 17:29:01 -0700568#endif /* CONFIG_DEBUG_PROC_FS */