per_cpu: fix DEFINE_PER_CPU_SHARED_ALIGNED for modules
[linux-2.6/mini2440.git] / arch / arm / mach-pxa / clock.c
blobe97dc59813c86af131d2b86395a5326cbb49fc7f
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>
12 #include <linux/platform_device.h>
13 #include <linux/delay.h>
15 #include <asm/arch/pxa-regs.h>
16 #include <asm/arch/pxa2xx-gpio.h>
17 #include <asm/hardware.h>
19 #include "devices.h"
20 #include "generic.h"
21 #include "clock.h"
23 static LIST_HEAD(clocks);
24 static DEFINE_MUTEX(clocks_mutex);
25 static DEFINE_SPINLOCK(clocks_lock);
27 static struct clk *clk_lookup(struct device *dev, const char *id)
29 struct clk *p;
31 list_for_each_entry(p, &clocks, node)
32 if (strcmp(id, p->name) == 0 && p->dev == dev)
33 return p;
35 return NULL;
38 struct clk *clk_get(struct device *dev, const char *id)
40 struct clk *p, *clk = ERR_PTR(-ENOENT);
42 mutex_lock(&clocks_mutex);
43 p = clk_lookup(dev, id);
44 if (!p)
45 p = clk_lookup(NULL, id);
46 if (p)
47 clk = p;
48 mutex_unlock(&clocks_mutex);
50 return clk;
52 EXPORT_SYMBOL(clk_get);
54 void clk_put(struct clk *clk)
57 EXPORT_SYMBOL(clk_put);
59 int clk_enable(struct clk *clk)
61 unsigned long flags;
63 spin_lock_irqsave(&clocks_lock, flags);
64 if (clk->enabled++ == 0)
65 clk->ops->enable(clk);
66 spin_unlock_irqrestore(&clocks_lock, flags);
68 if (clk->delay)
69 udelay(clk->delay);
71 return 0;
73 EXPORT_SYMBOL(clk_enable);
75 void clk_disable(struct clk *clk)
77 unsigned long flags;
79 WARN_ON(clk->enabled == 0);
81 spin_lock_irqsave(&clocks_lock, flags);
82 if (--clk->enabled == 0)
83 clk->ops->disable(clk);
84 spin_unlock_irqrestore(&clocks_lock, flags);
86 EXPORT_SYMBOL(clk_disable);
88 unsigned long clk_get_rate(struct clk *clk)
90 unsigned long rate;
92 rate = clk->rate;
93 if (clk->ops->getrate)
94 rate = clk->ops->getrate(clk);
96 return rate;
98 EXPORT_SYMBOL(clk_get_rate);
101 static void clk_gpio27_enable(struct clk *clk)
103 pxa_gpio_mode(GPIO11_3_6MHz_MD);
106 static void clk_gpio27_disable(struct clk *clk)
110 static const struct clkops clk_gpio27_ops = {
111 .enable = clk_gpio27_enable,
112 .disable = clk_gpio27_disable,
116 void clk_cken_enable(struct clk *clk)
118 CKEN |= 1 << clk->cken;
121 void clk_cken_disable(struct clk *clk)
123 CKEN &= ~(1 << clk->cken);
126 const struct clkops clk_cken_ops = {
127 .enable = clk_cken_enable,
128 .disable = clk_cken_disable,
131 static struct clk common_clks[] = {
133 .name = "GPIO27_CLK",
134 .ops = &clk_gpio27_ops,
135 .rate = 3686400,
139 void clks_register(struct clk *clks, size_t num)
141 int i;
143 mutex_lock(&clocks_mutex);
144 for (i = 0; i < num; i++)
145 list_add(&clks[i].node, &clocks);
146 mutex_unlock(&clocks_mutex);
149 static int __init clk_init(void)
151 clks_register(common_clks, ARRAY_SIZE(common_clks));
152 return 0;
154 arch_initcall(clk_init);