blob: 8184fe2d71c34c55c9d783645424c5073ce66d31 [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 King97d654f2006-03-15 15:54:37 +00006#include <linux/clk.h>
7#include <linux/spinlock.h>
Russell Kinga6dba202007-08-20 10:18:02 +01008#include <linux/delay.h>
Russell King97d654f2006-03-15 15:54:37 +00009
Russell King8c3abc72008-11-08 20:25:21 +000010#include <asm/clkdev.h>
Russell King97d654f2006-03-15 15:54:37 +000011
Russell Kinga6dba202007-08-20 10:18:02 +010012#include "clock.h"
Russell King97d654f2006-03-15 15:54:37 +000013
Russell King97d654f2006-03-15 15:54:37 +000014static DEFINE_SPINLOCK(clocks_lock);
15
Russell King97d654f2006-03-15 15:54:37 +000016int clk_enable(struct clk *clk)
17{
18 unsigned long flags;
19
20 spin_lock_irqsave(&clocks_lock, flags);
21 if (clk->enabled++ == 0)
Russell Kinga6dba202007-08-20 10:18:02 +010022 clk->ops->enable(clk);
Russell King97d654f2006-03-15 15:54:37 +000023 spin_unlock_irqrestore(&clocks_lock, flags);
Russell Kinga6dba202007-08-20 10:18:02 +010024
25 if (clk->delay)
26 udelay(clk->delay);
27
Russell King97d654f2006-03-15 15:54:37 +000028 return 0;
29}
30EXPORT_SYMBOL(clk_enable);
31
32void clk_disable(struct clk *clk)
33{
34 unsigned long flags;
35
36 WARN_ON(clk->enabled == 0);
37
38 spin_lock_irqsave(&clocks_lock, flags);
39 if (--clk->enabled == 0)
Russell Kinga6dba202007-08-20 10:18:02 +010040 clk->ops->disable(clk);
Russell King97d654f2006-03-15 15:54:37 +000041 spin_unlock_irqrestore(&clocks_lock, flags);
42}
43EXPORT_SYMBOL(clk_disable);
44
45unsigned long clk_get_rate(struct clk *clk)
46{
Russell Kinga6dba202007-08-20 10:18:02 +010047 unsigned long rate;
48
49 rate = clk->rate;
50 if (clk->ops->getrate)
51 rate = clk->ops->getrate(clk);
52
53 return rate;
Russell King97d654f2006-03-15 15:54:37 +000054}
55EXPORT_SYMBOL(clk_get_rate);
56
Eric Miao40298132010-11-22 10:49:55 +080057void clk_dummy_enable(struct clk *clk)
Russell King97d654f2006-03-15 15:54:37 +000058{
Russell Kinga6dba202007-08-20 10:18:02 +010059}
60
Eric Miao40298132010-11-22 10:49:55 +080061void clk_dummy_disable(struct clk *clk)
Russell Kinga6dba202007-08-20 10:18:02 +010062{
Russell Kinga6dba202007-08-20 10:18:02 +010063}
64
Eric Miao40298132010-11-22 10:49:55 +080065const struct clkops clk_dummy_ops = {
66 .enable = clk_dummy_enable,
67 .disable = clk_dummy_disable,
68};
69
70struct clk clk_dummy = {
71 .ops = &clk_dummy_ops,
Russell Kinga6dba202007-08-20 10:18:02 +010072};