blob: d5152220ce947607f072b47ae01d21419170c3b3 [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>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +01009#include <linux/clkdev.h>
Russell King97d654f2006-03-15 15:54:37 +000010
Russell Kinga6dba202007-08-20 10:18:02 +010011#include "clock.h"
Russell King97d654f2006-03-15 15:54:37 +000012
Russell King97d654f2006-03-15 15:54:37 +000013static DEFINE_SPINLOCK(clocks_lock);
14
Russell King97d654f2006-03-15 15:54:37 +000015int clk_enable(struct clk *clk)
16{
17 unsigned long flags;
18
19 spin_lock_irqsave(&clocks_lock, flags);
20 if (clk->enabled++ == 0)
Russell Kinga6dba202007-08-20 10:18:02 +010021 clk->ops->enable(clk);
Russell King97d654f2006-03-15 15:54:37 +000022 spin_unlock_irqrestore(&clocks_lock, flags);
Russell Kinga6dba202007-08-20 10:18:02 +010023
24 if (clk->delay)
25 udelay(clk->delay);
26
Russell King97d654f2006-03-15 15:54:37 +000027 return 0;
28}
29EXPORT_SYMBOL(clk_enable);
30
31void clk_disable(struct clk *clk)
32{
33 unsigned long flags;
34
35 WARN_ON(clk->enabled == 0);
36
37 spin_lock_irqsave(&clocks_lock, flags);
38 if (--clk->enabled == 0)
Russell Kinga6dba202007-08-20 10:18:02 +010039 clk->ops->disable(clk);
Russell King97d654f2006-03-15 15:54:37 +000040 spin_unlock_irqrestore(&clocks_lock, flags);
41}
42EXPORT_SYMBOL(clk_disable);
43
44unsigned long clk_get_rate(struct clk *clk)
45{
Russell Kinga6dba202007-08-20 10:18:02 +010046 unsigned long rate;
47
48 rate = clk->rate;
49 if (clk->ops->getrate)
50 rate = clk->ops->getrate(clk);
51
52 return rate;
Russell King97d654f2006-03-15 15:54:37 +000053}
54EXPORT_SYMBOL(clk_get_rate);
55
Eric Miao40298132010-11-22 10:49:55 +080056void clk_dummy_enable(struct clk *clk)
Russell King97d654f2006-03-15 15:54:37 +000057{
Russell Kinga6dba202007-08-20 10:18:02 +010058}
59
Eric Miao40298132010-11-22 10:49:55 +080060void clk_dummy_disable(struct clk *clk)
Russell Kinga6dba202007-08-20 10:18:02 +010061{
Russell Kinga6dba202007-08-20 10:18:02 +010062}
63
Eric Miao40298132010-11-22 10:49:55 +080064const struct clkops clk_dummy_ops = {
65 .enable = clk_dummy_enable,
66 .disable = clk_dummy_disable,
67};
68
69struct clk clk_dummy = {
70 .ops = &clk_dummy_ops,
Russell Kinga6dba202007-08-20 10:18:02 +010071};