2 * linux/arch/arm/mach-sa1100/clock.c
4 #include <linux/module.h>
5 #include <linux/kernel.h>
6 #include <linux/list.h>
7 #include <linux/errno.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/hardware.h>
22 static LIST_HEAD(clocks);
23 static DEFINE_MUTEX(clocks_mutex);
24 static DEFINE_SPINLOCK(clocks_lock);
26 static struct clk *clk_lookup(struct device *dev, const char *id)
30 list_for_each_entry(p, &clocks, node)
31 if (strcmp(id, p->name) == 0 && p->dev == dev)
37 struct clk *clk_get(struct device *dev, const char *id)
39 struct clk *p, *clk = ERR_PTR(-ENOENT);
41 mutex_lock(&clocks_mutex);
42 p = clk_lookup(dev, id);
44 p = clk_lookup(NULL, id);
47 mutex_unlock(&clocks_mutex);
51 EXPORT_SYMBOL(clk_get);
53 void clk_put(struct clk *clk)
56 EXPORT_SYMBOL(clk_put);
58 int clk_enable(struct clk *clk)
62 spin_lock_irqsave(&clocks_lock, flags);
63 if (clk->enabled++ == 0)
64 clk->ops->enable(clk);
65 spin_unlock_irqrestore(&clocks_lock, flags);
72 EXPORT_SYMBOL(clk_enable);
74 void clk_disable(struct clk *clk)
78 WARN_ON(clk->enabled == 0);
80 spin_lock_irqsave(&clocks_lock, flags);
81 if (--clk->enabled == 0)
82 clk->ops->disable(clk);
83 spin_unlock_irqrestore(&clocks_lock, flags);
85 EXPORT_SYMBOL(clk_disable);
87 unsigned long clk_get_rate(struct clk *clk)
92 if (clk->ops->getrate)
93 rate = clk->ops->getrate(clk);
97 EXPORT_SYMBOL(clk_get_rate);
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 const struct clkops clk_gpio27_ops = {
110 .enable = clk_gpio27_enable,
111 .disable = clk_gpio27_disable,
115 void clk_cken_enable(struct clk *clk)
117 CKEN |= 1 << clk->cken;
120 void clk_cken_disable(struct clk *clk)
122 CKEN &= ~(1 << clk->cken);
125 const struct clkops clk_cken_ops = {
126 .enable = clk_cken_enable,
127 .disable = clk_cken_disable,
130 static struct clk common_clks[] = {
132 .name = "GPIO27_CLK",
133 .ops = &clk_gpio27_ops,
138 void clks_register(struct clk *clks, size_t num)
142 mutex_lock(&clocks_mutex);
143 for (i = 0; i < num; i++)
144 list_add(&clks[i].node, &clocks);
145 mutex_unlock(&clocks_mutex);
148 static int __init clk_init(void)
150 clks_register(common_clks, ARRAY_SIZE(common_clks));
153 arch_initcall(clk_init);