Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-sa1100/clock.c |
| 3 | */ |
| 4 | #include <linux/module.h> |
| 5 | #include <linux/kernel.h> |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 6 | #include <linux/clk.h> |
| 7 | #include <linux/spinlock.h> |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 8 | #include <linux/delay.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 9 | #include <linux/clkdev.h> |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 10 | |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 11 | #include "clock.h" |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 12 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 13 | static DEFINE_SPINLOCK(clocks_lock); |
| 14 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 15 | int clk_enable(struct clk *clk) |
| 16 | { |
| 17 | unsigned long flags; |
| 18 | |
| 19 | spin_lock_irqsave(&clocks_lock, flags); |
| 20 | if (clk->enabled++ == 0) |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 21 | clk->ops->enable(clk); |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 22 | spin_unlock_irqrestore(&clocks_lock, flags); |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 23 | |
| 24 | if (clk->delay) |
| 25 | udelay(clk->delay); |
| 26 | |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 27 | return 0; |
| 28 | } |
| 29 | EXPORT_SYMBOL(clk_enable); |
| 30 | |
| 31 | void 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 King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 39 | clk->ops->disable(clk); |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 40 | spin_unlock_irqrestore(&clocks_lock, flags); |
| 41 | } |
| 42 | EXPORT_SYMBOL(clk_disable); |
| 43 | |
| 44 | unsigned long clk_get_rate(struct clk *clk) |
| 45 | { |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 46 | unsigned long rate; |
| 47 | |
| 48 | rate = clk->rate; |
| 49 | if (clk->ops->getrate) |
| 50 | rate = clk->ops->getrate(clk); |
| 51 | |
| 52 | return rate; |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 53 | } |
| 54 | EXPORT_SYMBOL(clk_get_rate); |
| 55 | |
Eric Miao | 4029813 | 2010-11-22 10:49:55 +0800 | [diff] [blame] | 56 | void clk_dummy_enable(struct clk *clk) |
Russell King | 97d654f | 2006-03-15 15:54:37 +0000 | [diff] [blame] | 57 | { |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Eric Miao | 4029813 | 2010-11-22 10:49:55 +0800 | [diff] [blame] | 60 | void clk_dummy_disable(struct clk *clk) |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 61 | { |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Eric Miao | 4029813 | 2010-11-22 10:49:55 +0800 | [diff] [blame] | 64 | const struct clkops clk_dummy_ops = { |
| 65 | .enable = clk_dummy_enable, |
| 66 | .disable = clk_dummy_disable, |
| 67 | }; |
| 68 | |
| 69 | struct clk clk_dummy = { |
| 70 | .ops = &clk_dummy_ops, |
Russell King | a6dba20 | 2007-08-20 10:18:02 +0100 | [diff] [blame] | 71 | }; |