blob: 49ae38292310c2b1058c433f7e2a16fbe378756f [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>
6#include <linux/list.h>
7#include <linux/errno.h>
8#include <linux/err.h>
9#include <linux/string.h>
10#include <linux/clk.h>
11#include <linux/spinlock.h>
Russell Kinga6dba202007-08-20 10:18:02 +010012#include <linux/platform_device.h>
13#include <linux/delay.h>
Russell King97d654f2006-03-15 15:54:37 +000014
Russell King8c3abc72008-11-08 20:25:21 +000015#include <asm/clkdev.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010016#include <mach/pxa2xx-regs.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010017#include <mach/hardware.h>
Russell King97d654f2006-03-15 15:54:37 +000018
Russell Kinga6dba202007-08-20 10:18:02 +010019#include "devices.h"
20#include "generic.h"
21#include "clock.h"
Russell King97d654f2006-03-15 15:54:37 +000022
Russell King97d654f2006-03-15 15:54:37 +000023static DEFINE_SPINLOCK(clocks_lock);
24
Russell King97d654f2006-03-15 15:54:37 +000025int clk_enable(struct clk *clk)
26{
27 unsigned long flags;
28
29 spin_lock_irqsave(&clocks_lock, flags);
30 if (clk->enabled++ == 0)
Russell Kinga6dba202007-08-20 10:18:02 +010031 clk->ops->enable(clk);
Russell King97d654f2006-03-15 15:54:37 +000032 spin_unlock_irqrestore(&clocks_lock, flags);
Russell Kinga6dba202007-08-20 10:18:02 +010033
34 if (clk->delay)
35 udelay(clk->delay);
36
Russell King97d654f2006-03-15 15:54:37 +000037 return 0;
38}
39EXPORT_SYMBOL(clk_enable);
40
41void clk_disable(struct clk *clk)
42{
43 unsigned long flags;
44
45 WARN_ON(clk->enabled == 0);
46
47 spin_lock_irqsave(&clocks_lock, flags);
48 if (--clk->enabled == 0)
Russell Kinga6dba202007-08-20 10:18:02 +010049 clk->ops->disable(clk);
Russell King97d654f2006-03-15 15:54:37 +000050 spin_unlock_irqrestore(&clocks_lock, flags);
51}
52EXPORT_SYMBOL(clk_disable);
53
54unsigned long clk_get_rate(struct clk *clk)
55{
Russell Kinga6dba202007-08-20 10:18:02 +010056 unsigned long rate;
57
58 rate = clk->rate;
59 if (clk->ops->getrate)
60 rate = clk->ops->getrate(clk);
61
62 return rate;
Russell King97d654f2006-03-15 15:54:37 +000063}
64EXPORT_SYMBOL(clk_get_rate);
65
66
Russell Kinga6dba202007-08-20 10:18:02 +010067void clk_cken_enable(struct clk *clk)
Russell King97d654f2006-03-15 15:54:37 +000068{
Russell Kinga6dba202007-08-20 10:18:02 +010069 CKEN |= 1 << clk->cken;
70}
71
72void clk_cken_disable(struct clk *clk)
73{
74 CKEN &= ~(1 << clk->cken);
75}
76
77const struct clkops clk_cken_ops = {
78 .enable = clk_cken_enable,
79 .disable = clk_cken_disable,
80};
81
Russell King8c3abc72008-11-08 20:25:21 +000082void clks_register(struct clk_lookup *clks, size_t num)
Russell Kinga6dba202007-08-20 10:18:02 +010083{
84 int i;
85
Russell Kinga6dba202007-08-20 10:18:02 +010086 for (i = 0; i < num; i++)
Russell King8c3abc72008-11-08 20:25:21 +000087 clkdev_add(&clks[i]);
Russell King97d654f2006-03-15 15:54:37 +000088}