blob: dab3c6347a8f2d8e80bafba18b6916f8f97161f9 [file] [log] [blame]
Russell King97d654f2006-03-15 15:54:37 +00001/*
2 * linux/arch/arm/mach-sa1100/clock.c
3 */
4#include <linux/module.h>
5#include <linux/kernel.h>
Russell King5e1dbdb42008-11-08 20:48:27 +00006#include <linux/device.h>
Russell King97d654f2006-03-15 15:54:37 +00007#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>
Russell Kingd0a9d752007-04-22 10:08:58 +010013#include <linux/mutex.h>
Russell King97d654f2006-03-15 15:54:37 +000014
Russell Kinga09e64f2008-08-05 16:14:15 +010015#include <mach/hardware.h>
Russell King97d654f2006-03-15 15:54:37 +000016
Russell Kingd0a9d752007-04-22 10:08:58 +010017/*
Russell King5e1dbdb42008-11-08 20:48:27 +000018 * Very simple clock implementation - we only have one clock to deal with.
Russell Kingd0a9d752007-04-22 10:08:58 +010019 */
Russell King97d654f2006-03-15 15:54:37 +000020struct clk {
Russell King97d654f2006-03-15 15:54:37 +000021 unsigned int enabled;
Russell King97d654f2006-03-15 15:54:37 +000022};
23
Russell King97d654f2006-03-15 15:54:37 +000024static void clk_gpio27_enable(void)
25{
26 /*
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)
29 */
30 GAFR |= GPIO_32_768kHz;
31 GPDR |= GPIO_32_768kHz;
32 TUCR = TUCR_3_6864MHz;
33}
34
35static void clk_gpio27_disable(void)
36{
37 TUCR = 0;
38 GPDR &= ~GPIO_32_768kHz;
39 GAFR &= ~GPIO_32_768kHz;
40}
41
Russell King5e1dbdb42008-11-08 20:48:27 +000042static struct clk clk_gpio27;
Russell King97d654f2006-03-15 15:54:37 +000043
Russell King5e1dbdb42008-11-08 20:48:27 +000044static DEFINE_SPINLOCK(clocks_lock);
45
46struct clk *clk_get(struct device *dev, const char *id)
Russell King97d654f2006-03-15 15:54:37 +000047{
Russell King5e1dbdb42008-11-08 20:48:27 +000048 const char *devname = dev_name(dev);
49
50 return strcmp(devname, "sa1111.0") ? ERR_PTR(-ENOENT) : &clk_gpio27;
51}
52EXPORT_SYMBOL(clk_get);
53
54void clk_put(struct clk *clk)
55{
56}
57EXPORT_SYMBOL(clk_put);
58
59int clk_enable(struct clk *clk)
60{
61 unsigned long flags;
62
63 spin_lock_irqsave(&clocks_lock, flags);
64 if (clk->enabled++ == 0)
65 clk_gpio27_enable();
66 spin_unlock_irqrestore(&clocks_lock, flags);
Russell King97d654f2006-03-15 15:54:37 +000067 return 0;
68}
Russell King5e1dbdb42008-11-08 20:48:27 +000069EXPORT_SYMBOL(clk_enable);
Russell King97d654f2006-03-15 15:54:37 +000070
Russell King5e1dbdb42008-11-08 20:48:27 +000071void clk_disable(struct clk *clk)
Russell King97d654f2006-03-15 15:54:37 +000072{
Russell King5e1dbdb42008-11-08 20:48:27 +000073 unsigned long flags;
Russell King97d654f2006-03-15 15:54:37 +000074
Russell King5e1dbdb42008-11-08 20:48:27 +000075 WARN_ON(clk->enabled == 0);
76
77 spin_lock_irqsave(&clocks_lock, flags);
78 if (--clk->enabled == 0)
79 clk_gpio27_disable();
80 spin_unlock_irqrestore(&clocks_lock, flags);
Russell King97d654f2006-03-15 15:54:37 +000081}
Russell King5e1dbdb42008-11-08 20:48:27 +000082EXPORT_SYMBOL(clk_disable);
83
84unsigned long clk_get_rate(struct clk *clk)
85{
86 return 3686400;
87}
88EXPORT_SYMBOL(clk_get_rate);