Commit | Line | Data |
---|---|---|
97d654f8 RK |
1 | /* |
2 | * linux/arch/arm/mach-sa1100/clock.c | |
3 | */ | |
4 | #include <linux/module.h> | |
5 | #include <linux/kernel.h> | |
6 | #include <linux/list.h> | |
7 | #include <linux/errno.h> | |
8 | #include <linux/err.h> | |
9 | #include <linux/string.h> | |
10 | #include <linux/clk.h> | |
11 | #include <linux/spinlock.h> | |
a6dba20c RK |
12 | #include <linux/platform_device.h> |
13 | #include <linux/delay.h> | |
97d654f8 | 14 | |
8c3abc7d | 15 | #include <asm/clkdev.h> |
a09e64fb | 16 | #include <mach/pxa2xx-regs.h> |
a09e64fb | 17 | #include <mach/hardware.h> |
97d654f8 | 18 | |
a6dba20c RK |
19 | #include "devices.h" |
20 | #include "generic.h" | |
21 | #include "clock.h" | |
97d654f8 | 22 | |
97d654f8 RK |
23 | static DEFINE_SPINLOCK(clocks_lock); |
24 | ||
97d654f8 RK |
25 | int clk_enable(struct clk *clk) |
26 | { | |
27 | unsigned long flags; | |
28 | ||
29 | spin_lock_irqsave(&clocks_lock, flags); | |
30 | if (clk->enabled++ == 0) | |
a6dba20c | 31 | clk->ops->enable(clk); |
97d654f8 | 32 | spin_unlock_irqrestore(&clocks_lock, flags); |
a6dba20c RK |
33 | |
34 | if (clk->delay) | |
35 | udelay(clk->delay); | |
36 | ||
97d654f8 RK |
37 | return 0; |
38 | } | |
39 | EXPORT_SYMBOL(clk_enable); | |
40 | ||
41 | void clk_disable(struct clk *clk) | |
42 | { | |
43 | unsigned long flags; | |
44 | ||
45 | WARN_ON(clk->enabled == 0); | |
46 | ||
47 | spin_lock_irqsave(&clocks_lock, flags); | |
48 | if (--clk->enabled == 0) | |
a6dba20c | 49 | clk->ops->disable(clk); |
97d654f8 RK |
50 | spin_unlock_irqrestore(&clocks_lock, flags); |
51 | } | |
52 | EXPORT_SYMBOL(clk_disable); | |
53 | ||
54 | unsigned long clk_get_rate(struct clk *clk) | |
55 | { | |
a6dba20c RK |
56 | unsigned long rate; |
57 | ||
58 | rate = clk->rate; | |
59 | if (clk->ops->getrate) | |
60 | rate = clk->ops->getrate(clk); | |
61 | ||
62 | return rate; | |
97d654f8 RK |
63 | } |
64 | EXPORT_SYMBOL(clk_get_rate); | |
65 | ||
66 | ||
a6dba20c | 67 | void clk_cken_enable(struct clk *clk) |
97d654f8 | 68 | { |
a6dba20c | 69 | CKEN |= 1 << clk->cken; |
97d654f8 | 70 | } |
97d654f8 | 71 | |
a6dba20c | 72 | void clk_cken_disable(struct clk *clk) |
97d654f8 | 73 | { |
a6dba20c RK |
74 | CKEN &= ~(1 << clk->cken); |
75 | } | |
76 | ||
77 | const struct clkops clk_cken_ops = { | |
78 | .enable = clk_cken_enable, | |
79 | .disable = clk_cken_disable, | |
80 | }; |