Linux 2.6.31.6
[linux/fpc-iii.git] / arch / arm / mach-mmp / clock.c
blob2d9cc5a7122fad0cb167f1a569073e0ece95e3fb
1 /*
2 * linux/arch/arm/mach-mmp/clock.c
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/list.h>
12 #include <linux/spinlock.h>
13 #include <linux/clk.h>
14 #include <linux/io.h>
16 #include <mach/regs-apbc.h>
17 #include "clock.h"
19 static void apbc_clk_enable(struct clk *clk)
21 uint32_t clk_rst;
23 clk_rst = APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(clk->fnclksel);
24 __raw_writel(clk_rst, clk->clk_rst);
27 static void apbc_clk_disable(struct clk *clk)
29 __raw_writel(0, clk->clk_rst);
32 struct clkops apbc_clk_ops = {
33 .enable = apbc_clk_enable,
34 .disable = apbc_clk_disable,
37 static DEFINE_SPINLOCK(clocks_lock);
39 int clk_enable(struct clk *clk)
41 unsigned long flags;
43 spin_lock_irqsave(&clocks_lock, flags);
44 if (clk->enabled++ == 0)
45 clk->ops->enable(clk);
46 spin_unlock_irqrestore(&clocks_lock, flags);
47 return 0;
49 EXPORT_SYMBOL(clk_enable);
51 void clk_disable(struct clk *clk)
53 unsigned long flags;
55 WARN_ON(clk->enabled == 0);
57 spin_lock_irqsave(&clocks_lock, flags);
58 if (--clk->enabled == 0)
59 clk->ops->disable(clk);
60 spin_unlock_irqrestore(&clocks_lock, flags);
62 EXPORT_SYMBOL(clk_disable);
64 unsigned long clk_get_rate(struct clk *clk)
66 unsigned long rate;
68 if (clk->ops->getrate)
69 rate = clk->ops->getrate(clk);
70 else
71 rate = clk->rate;
73 return rate;
75 EXPORT_SYMBOL(clk_get_rate);
77 void clks_register(struct clk_lookup *clks, size_t num)
79 int i;
81 for (i = 0; i < num; i++)
82 clkdev_add(&clks[i]);