RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / mach-sa1100 / clock.c
blobdab3c6347a8f2d8e80bafba18b6916f8f97161f9
1 /*
2 * linux/arch/arm/mach-sa1100/clock.c
3 */
4 #include <linux/module.h>
5 #include <linux/kernel.h>
6 #include <linux/device.h>
7 #include <linux/list.h>
8 #include <linux/errno.h>
9 #include <linux/err.h>
10 #include <linux/string.h>
11 #include <linux/clk.h>
12 #include <linux/spinlock.h>
13 #include <linux/mutex.h>
15 #include <mach/hardware.h>
18 * Very simple clock implementation - we only have one clock to deal with.
20 struct clk {
21 unsigned int enabled;
24 static void clk_gpio27_enable(void)
27 * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
28 * (SA-1110 Developer's Manual, section 9.1.2.1)
30 GAFR |= GPIO_32_768kHz;
31 GPDR |= GPIO_32_768kHz;
32 TUCR = TUCR_3_6864MHz;
35 static void clk_gpio27_disable(void)
37 TUCR = 0;
38 GPDR &= ~GPIO_32_768kHz;
39 GAFR &= ~GPIO_32_768kHz;
42 static struct clk clk_gpio27;
44 static DEFINE_SPINLOCK(clocks_lock);
46 struct clk *clk_get(struct device *dev, const char *id)
48 const char *devname = dev_name(dev);
50 return strcmp(devname, "sa1111.0") ? ERR_PTR(-ENOENT) : &clk_gpio27;
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_gpio27_enable();
66 spin_unlock_irqrestore(&clocks_lock, flags);
67 return 0;
69 EXPORT_SYMBOL(clk_enable);
71 void clk_disable(struct clk *clk)
73 unsigned long flags;
75 WARN_ON(clk->enabled == 0);
77 spin_lock_irqsave(&clocks_lock, flags);
78 if (--clk->enabled == 0)
79 clk_gpio27_disable();
80 spin_unlock_irqrestore(&clocks_lock, flags);
82 EXPORT_SYMBOL(clk_disable);
84 unsigned long clk_get_rate(struct clk *clk)
86 return 3686400;
88 EXPORT_SYMBOL(clk_get_rate);