sync hh.org
[hh.org.git] / arch / arm / mach-pxa / clock.c
blob8e89bf5ca126a9163280a7d43efbc946999e6f4d
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>
13 #include <asm/arch/pxa-regs.h>
14 #include <asm/hardware.h>
15 #include <asm/semaphore.h>
17 #include <asm/arch/clock.h>
19 static LIST_HEAD(clocks);
20 static DECLARE_MUTEX(clocks_sem);
21 static DEFINE_SPINLOCK(clocks_lock);
23 struct clk *clk_get(struct device *dev, const char *id)
25 struct clk *p, *clk = ERR_PTR(-ENOENT);
27 down(&clocks_sem);
28 list_for_each_entry(p, &clocks, node) {
29 if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
30 clk = p;
31 break;
34 up(&clocks_sem);
36 return clk;
38 EXPORT_SYMBOL(clk_get);
40 void clk_put(struct clk *clk)
42 module_put(clk->owner);
44 EXPORT_SYMBOL(clk_put);
46 int clk_enable(struct clk *clk)
48 unsigned long flags;
50 spin_lock_irqsave(&clocks_lock, flags);
51 if (clk->enabled++ == 0)
52 clk->enable(clk);
53 spin_unlock_irqrestore(&clocks_lock, flags);
54 return 0;
56 EXPORT_SYMBOL(clk_enable);
58 void clk_disable(struct clk *clk)
60 unsigned long flags;
62 WARN_ON(clk->enabled == 0);
64 spin_lock_irqsave(&clocks_lock, flags);
65 if (--clk->enabled == 0)
66 clk->disable(clk);
67 spin_unlock_irqrestore(&clocks_lock, flags);
69 EXPORT_SYMBOL(clk_disable);
71 unsigned long clk_get_rate(struct clk *clk)
73 if (clk->rate != 0)
74 return clk->rate;
76 while (clk->parent != NULL && clk->rate == 0)
77 clk = clk->parent;
79 return clk->rate;
81 EXPORT_SYMBOL(clk_get_rate);
83 struct clk *clk_get_parent(struct clk *clk)
85 return clk->parent;
87 EXPORT_SYMBOL(clk_get_parent);
89 int clk_set_parent(struct clk *clk, struct clk *parent)
91 down(&clocks_sem);
92 clk->parent = parent;
93 up(&clocks_sem);
95 return 0;
97 EXPORT_SYMBOL(clk_set_parent);
100 static void clk_gpio27_enable(struct clk *clk)
102 pxa_gpio_mode(GPIO11_3_6MHz_MD);
105 static void clk_gpio27_disable(struct clk *clk)
109 static struct clk clk_gpio27 = {
110 .name = "GPIO27_CLK",
111 .rate = 3686400,
112 .enable = clk_gpio27_enable,
113 .disable = clk_gpio27_disable,
116 int clk_register(struct clk *clk)
118 down(&clocks_sem);
119 list_add(&clk->node, &clocks);
120 up(&clocks_sem);
121 return 0;
123 EXPORT_SYMBOL(clk_register);
125 void clk_unregister(struct clk *clk)
127 down(&clocks_sem);
128 list_del(&clk->node);
129 up(&clocks_sem);
131 EXPORT_SYMBOL(clk_unregister);
133 static int __init clk_init(void)
135 clk_register(&clk_gpio27);
136 return 0;
138 arch_initcall(clk_init);