ACPICA: Add support for zero-length buffer-to-string conversions
[linux-2.6/mini2440.git] / arch / arm / mach-pxa / clock.c
blobca8e205381577ab07f05fec6e573f77554672c3c
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 <mach/pxa2xx-regs.h>
16 #include <mach/pxa2xx-gpio.h>
17 #include <mach/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 if (!IS_ERR(clk) && clk->ops == NULL)
51 clk = clk->other;
53 return clk;
55 EXPORT_SYMBOL(clk_get);
57 void clk_put(struct clk *clk)
60 EXPORT_SYMBOL(clk_put);
62 int clk_enable(struct clk *clk)
64 unsigned long flags;
66 spin_lock_irqsave(&clocks_lock, flags);
67 if (clk->enabled++ == 0)
68 clk->ops->enable(clk);
69 spin_unlock_irqrestore(&clocks_lock, flags);
71 if (clk->delay)
72 udelay(clk->delay);
74 return 0;
76 EXPORT_SYMBOL(clk_enable);
78 void clk_disable(struct clk *clk)
80 unsigned long flags;
82 WARN_ON(clk->enabled == 0);
84 spin_lock_irqsave(&clocks_lock, flags);
85 if (--clk->enabled == 0)
86 clk->ops->disable(clk);
87 spin_unlock_irqrestore(&clocks_lock, flags);
89 EXPORT_SYMBOL(clk_disable);
91 unsigned long clk_get_rate(struct clk *clk)
93 unsigned long rate;
95 rate = clk->rate;
96 if (clk->ops->getrate)
97 rate = clk->ops->getrate(clk);
99 return rate;
101 EXPORT_SYMBOL(clk_get_rate);
104 void clk_cken_enable(struct clk *clk)
106 CKEN |= 1 << clk->cken;
109 void clk_cken_disable(struct clk *clk)
111 CKEN &= ~(1 << clk->cken);
114 const struct clkops clk_cken_ops = {
115 .enable = clk_cken_enable,
116 .disable = clk_cken_disable,
119 void clks_register(struct clk *clks, size_t num)
121 int i;
123 mutex_lock(&clocks_mutex);
124 for (i = 0; i < num; i++)
125 list_add(&clks[i].node, &clocks);
126 mutex_unlock(&clocks_mutex);
129 int clk_add_alias(char *alias, struct device *alias_dev, char *id,
130 struct device *dev)
132 struct clk *r = clk_lookup(dev, id);
133 struct clk *new;
135 if (!r)
136 return -ENODEV;
138 new = kzalloc(sizeof(struct clk), GFP_KERNEL);
140 if (!new)
141 return -ENOMEM;
143 new->name = alias;
144 new->dev = alias_dev;
145 new->other = r;
147 mutex_lock(&clocks_mutex);
148 list_add(&new->node, &clocks);
149 mutex_unlock(&clocks_mutex);
151 return 0;