[ARM] 3340/1: Fix the PCI setup for direct master access to SDRAM
[pv_ops_mirror.git] / arch / arm / plat-omap / clock.c
blob3c2bfc0efdaf6f5bdee3f7abcf0bc0db6f0d4a2a
1 /*
2 * linux/arch/arm/plat-omap/clock.c
4 * Copyright (C) 2004 - 2005 Nokia corporation
5 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
7 * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 #include <linux/version.h>
14 #include <linux/config.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/list.h>
19 #include <linux/errno.h>
20 #include <linux/err.h>
21 #include <linux/string.h>
22 #include <linux/clk.h>
23 #include <linux/mutex.h>
25 #include <asm/io.h>
26 #include <asm/semaphore.h>
28 #include <asm/arch/clock.h>
30 LIST_HEAD(clocks);
31 static DEFINE_MUTEX(clocks_mutex);
32 DEFINE_SPINLOCK(clockfw_lock);
34 static struct clk_functions *arch_clock;
36 /*-------------------------------------------------------------------------
37 * Standard clock functions defined in include/linux/clk.h
38 *-------------------------------------------------------------------------*/
40 struct clk * clk_get(struct device *dev, const char *id)
42 struct clk *p, *clk = ERR_PTR(-ENOENT);
44 mutex_lock(&clocks_mutex);
45 list_for_each_entry(p, &clocks, node) {
46 if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
47 clk = p;
48 break;
51 mutex_unlock(&clocks_mutex);
53 return clk;
55 EXPORT_SYMBOL(clk_get);
57 int clk_enable(struct clk *clk)
59 unsigned long flags;
60 int ret = 0;
62 spin_lock_irqsave(&clockfw_lock, flags);
63 if (arch_clock->clk_enable)
64 ret = arch_clock->clk_enable(clk);
65 spin_unlock_irqrestore(&clockfw_lock, flags);
67 return ret;
69 EXPORT_SYMBOL(clk_enable);
71 void clk_disable(struct clk *clk)
73 unsigned long flags;
75 spin_lock_irqsave(&clockfw_lock, flags);
76 if (arch_clock->clk_disable)
77 arch_clock->clk_disable(clk);
78 spin_unlock_irqrestore(&clockfw_lock, flags);
80 EXPORT_SYMBOL(clk_disable);
82 int clk_get_usecount(struct clk *clk)
84 unsigned long flags;
85 int ret = 0;
87 spin_lock_irqsave(&clockfw_lock, flags);
88 ret = clk->usecount;
89 spin_unlock_irqrestore(&clockfw_lock, flags);
91 return ret;
93 EXPORT_SYMBOL(clk_get_usecount);
95 unsigned long clk_get_rate(struct clk *clk)
97 unsigned long flags;
98 unsigned long ret = 0;
100 spin_lock_irqsave(&clockfw_lock, flags);
101 ret = clk->rate;
102 spin_unlock_irqrestore(&clockfw_lock, flags);
104 return ret;
106 EXPORT_SYMBOL(clk_get_rate);
108 void clk_put(struct clk *clk)
110 if (clk && !IS_ERR(clk))
111 module_put(clk->owner);
113 EXPORT_SYMBOL(clk_put);
115 /*-------------------------------------------------------------------------
116 * Optional clock functions defined in include/linux/clk.h
117 *-------------------------------------------------------------------------*/
119 long clk_round_rate(struct clk *clk, unsigned long rate)
121 unsigned long flags;
122 long ret = 0;
124 spin_lock_irqsave(&clockfw_lock, flags);
125 if (arch_clock->clk_round_rate)
126 ret = arch_clock->clk_round_rate(clk, rate);
127 spin_unlock_irqrestore(&clockfw_lock, flags);
129 return ret;
131 EXPORT_SYMBOL(clk_round_rate);
133 int clk_set_rate(struct clk *clk, unsigned long rate)
135 unsigned long flags;
136 int ret = 0;
138 spin_lock_irqsave(&clockfw_lock, flags);
139 if (arch_clock->clk_set_rate)
140 ret = arch_clock->clk_set_rate(clk, rate);
141 spin_unlock_irqrestore(&clockfw_lock, flags);
143 return ret;
145 EXPORT_SYMBOL(clk_set_rate);
147 int clk_set_parent(struct clk *clk, struct clk *parent)
149 unsigned long flags;
150 int ret = 0;
152 spin_lock_irqsave(&clockfw_lock, flags);
153 if (arch_clock->clk_set_parent)
154 ret = arch_clock->clk_set_parent(clk, parent);
155 spin_unlock_irqrestore(&clockfw_lock, flags);
157 return ret;
159 EXPORT_SYMBOL(clk_set_parent);
161 struct clk *clk_get_parent(struct clk *clk)
163 unsigned long flags;
164 struct clk * ret = NULL;
166 spin_lock_irqsave(&clockfw_lock, flags);
167 if (arch_clock->clk_get_parent)
168 ret = arch_clock->clk_get_parent(clk);
169 spin_unlock_irqrestore(&clockfw_lock, flags);
171 return ret;
173 EXPORT_SYMBOL(clk_get_parent);
175 /*-------------------------------------------------------------------------
176 * OMAP specific clock functions shared between omap1 and omap2
177 *-------------------------------------------------------------------------*/
179 unsigned int __initdata mpurate;
182 * By default we use the rate set by the bootloader.
183 * You can override this with mpurate= cmdline option.
185 static int __init omap_clk_setup(char *str)
187 get_option(&str, &mpurate);
189 if (!mpurate)
190 return 1;
192 if (mpurate < 1000)
193 mpurate *= 1000000;
195 return 1;
197 __setup("mpurate=", omap_clk_setup);
199 /* Used for clocks that always have same value as the parent clock */
200 void followparent_recalc(struct clk *clk)
202 clk->rate = clk->parent->rate;
205 /* Propagate rate to children */
206 void propagate_rate(struct clk * tclk)
208 struct clk *clkp;
210 list_for_each_entry(clkp, &clocks, node) {
211 if (likely(clkp->parent != tclk))
212 continue;
213 if (likely((u32)clkp->recalc))
214 clkp->recalc(clkp);
218 int clk_register(struct clk *clk)
220 mutex_lock(&clocks_mutex);
221 list_add(&clk->node, &clocks);
222 if (clk->init)
223 clk->init(clk);
224 mutex_unlock(&clocks_mutex);
226 return 0;
228 EXPORT_SYMBOL(clk_register);
230 void clk_unregister(struct clk *clk)
232 mutex_lock(&clocks_mutex);
233 list_del(&clk->node);
234 mutex_unlock(&clocks_mutex);
236 EXPORT_SYMBOL(clk_unregister);
238 void clk_deny_idle(struct clk *clk)
240 unsigned long flags;
242 spin_lock_irqsave(&clockfw_lock, flags);
243 if (arch_clock->clk_deny_idle)
244 arch_clock->clk_deny_idle(clk);
245 spin_unlock_irqrestore(&clockfw_lock, flags);
247 EXPORT_SYMBOL(clk_deny_idle);
249 void clk_allow_idle(struct clk *clk)
251 unsigned long flags;
253 spin_lock_irqsave(&clockfw_lock, flags);
254 if (arch_clock->clk_allow_idle)
255 arch_clock->clk_allow_idle(clk);
256 spin_unlock_irqrestore(&clockfw_lock, flags);
258 EXPORT_SYMBOL(clk_allow_idle);
260 /*-------------------------------------------------------------------------*/
262 int __init clk_init(struct clk_functions * custom_clocks)
264 if (!custom_clocks) {
265 printk(KERN_ERR "No custom clock functions registered\n");
266 BUG();
269 arch_clock = custom_clocks;
271 return 0;