aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-msm/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-msm/clock.c')
-rw-r--r--arch/arm/mach-msm/clock.c148
1 files changed, 8 insertions, 140 deletions
diff --git a/arch/arm/mach-msm/clock.c b/arch/arm/mach-msm/clock.c
index 2069bfaa3a26..8c2b4dd4a877 100644
--- a/arch/arm/mach-msm/clock.c
+++ b/arch/arm/mach-msm/clock.c
@@ -15,33 +15,19 @@
15 */ 15 */
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/list.h> 18#include <linux/list.h>
21#include <linux/err.h> 19#include <linux/err.h>
22#include <linux/clk.h>
23#include <linux/spinlock.h> 20#include <linux/spinlock.h>
24#include <linux/debugfs.h>
25#include <linux/ctype.h>
26#include <linux/pm_qos_params.h> 21#include <linux/pm_qos_params.h>
27#include <mach/clk.h>
28 22
29#include "clock.h" 23#include "clock.h"
30#include "proc_comm.h" 24#include "proc_comm.h"
31#include "clock-7x30.h" 25#include "clock-7x30.h"
26#include "clock-pcom.h"
32 27
33static DEFINE_MUTEX(clocks_mutex); 28static DEFINE_MUTEX(clocks_mutex);
34static DEFINE_SPINLOCK(clocks_lock); 29static DEFINE_SPINLOCK(clocks_lock);
35static LIST_HEAD(clocks); 30static LIST_HEAD(clocks);
36struct clk *msm_clocks;
37unsigned msm_num_clocks;
38
39/*
40 * Bitmap of enabled clocks, excluding ACPU which is always
41 * enabled
42 */
43static DECLARE_BITMAP(clock_map_enabled, NR_CLKS);
44static DEFINE_SPINLOCK(clock_map_lock);
45 31
46/* 32/*
47 * Standard clock functions defined in include/linux/clk.h 33 * Standard clock functions defined in include/linux/clk.h
@@ -77,12 +63,8 @@ int clk_enable(struct clk *clk)
77 unsigned long flags; 63 unsigned long flags;
78 spin_lock_irqsave(&clocks_lock, flags); 64 spin_lock_irqsave(&clocks_lock, flags);
79 clk->count++; 65 clk->count++;
80 if (clk->count == 1) { 66 if (clk->count == 1)
81 clk->ops->enable(clk->id); 67 clk->ops->enable(clk->id);
82 spin_lock(&clock_map_lock);
83 clock_map_enabled[BIT_WORD(clk->id)] |= BIT_MASK(clk->id);
84 spin_unlock(&clock_map_lock);
85 }
86 spin_unlock_irqrestore(&clocks_lock, flags); 68 spin_unlock_irqrestore(&clocks_lock, flags);
87 return 0; 69 return 0;
88} 70}
@@ -94,12 +76,8 @@ void clk_disable(struct clk *clk)
94 spin_lock_irqsave(&clocks_lock, flags); 76 spin_lock_irqsave(&clocks_lock, flags);
95 BUG_ON(clk->count == 0); 77 BUG_ON(clk->count == 0);
96 clk->count--; 78 clk->count--;
97 if (clk->count == 0) { 79 if (clk->count == 0)
98 clk->ops->disable(clk->id); 80 clk->ops->disable(clk->id);
99 spin_lock(&clock_map_lock);
100 clock_map_enabled[BIT_WORD(clk->id)] &= ~BIT_MASK(clk->id);
101 spin_unlock(&clock_map_lock);
102 }
103 spin_unlock_irqrestore(&clocks_lock, flags); 81 spin_unlock_irqrestore(&clocks_lock, flags);
104} 82}
105EXPORT_SYMBOL(clk_disable); 83EXPORT_SYMBOL(clk_disable);
@@ -196,13 +174,10 @@ void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks)
196{ 174{
197 unsigned n; 175 unsigned n;
198 176
199 spin_lock_init(&clocks_lock);
200 mutex_lock(&clocks_mutex); 177 mutex_lock(&clocks_mutex);
201 msm_clocks = clock_tbl; 178 for (n = 0; n < num_clocks; n++) {
202 msm_num_clocks = num_clocks; 179 set_clock_ops(&clock_tbl[n]);
203 for (n = 0; n < msm_num_clocks; n++) { 180 list_add_tail(&clock_tbl[n].list, &clocks);
204 set_clock_ops(&msm_clocks[n]);
205 list_add_tail(&msm_clocks[n].list, &clocks);
206 } 181 }
207 mutex_unlock(&clocks_mutex); 182 mutex_unlock(&clocks_mutex);
208 183
@@ -211,115 +186,6 @@ void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks)
211 186
212} 187}
213 188
214#if defined(CONFIG_DEBUG_FS)
215static struct clk *msm_clock_get_nth(unsigned index)
216{
217 if (index < msm_num_clocks)
218 return msm_clocks + index;
219 else
220 return 0;
221}
222
223static int clock_debug_rate_set(void *data, u64 val)
224{
225 struct clk *clock = data;
226 int ret;
227
228 /* Only increases to max rate will succeed, but that's actually good
229 * for debugging purposes. So we don't check for error. */
230 if (clock->flags & CLK_MAX)
231 clk_set_max_rate(clock, val);
232 if (clock->flags & CLK_MIN)
233 ret = clk_set_min_rate(clock, val);
234 else
235 ret = clk_set_rate(clock, val);
236 if (ret != 0)
237 printk(KERN_ERR "clk_set%s_rate failed (%d)\n",
238 (clock->flags & CLK_MIN) ? "_min" : "", ret);
239 return ret;
240}
241
242static int clock_debug_rate_get(void *data, u64 *val)
243{
244 struct clk *clock = data;
245 *val = clk_get_rate(clock);
246 return 0;
247}
248
249static int clock_debug_enable_set(void *data, u64 val)
250{
251 struct clk *clock = data;
252 int rc = 0;
253
254 if (val)
255 rc = clock->ops->enable(clock->id);
256 else
257 clock->ops->disable(clock->id);
258
259 return rc;
260}
261
262static int clock_debug_enable_get(void *data, u64 *val)
263{
264 struct clk *clock = data;
265
266 *val = clock->ops->is_enabled(clock->id);
267
268 return 0;
269}
270
271static int clock_debug_local_get(void *data, u64 *val)
272{
273 struct clk *clock = data;
274
275 *val = clock->ops != &clk_ops_pcom;
276
277 return 0;
278}
279
280DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get,
281 clock_debug_rate_set, "%llu\n");
282DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get,
283 clock_debug_enable_set, "%llu\n");
284DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get,
285 NULL, "%llu\n");
286
287static int __init clock_debug_init(void)
288{
289 struct dentry *dent_rate, *dent_enable, *dent_local;
290 struct clk *clock;
291 unsigned n = 0;
292 char temp[50], *ptr;
293
294 dent_rate = debugfs_create_dir("clk_rate", 0);
295 if (IS_ERR(dent_rate))
296 return PTR_ERR(dent_rate);
297
298 dent_enable = debugfs_create_dir("clk_enable", 0);
299 if (IS_ERR(dent_enable))
300 return PTR_ERR(dent_enable);
301
302 dent_local = debugfs_create_dir("clk_local", NULL);
303 if (IS_ERR(dent_local))
304 return PTR_ERR(dent_local);
305
306 while ((clock = msm_clock_get_nth(n++)) != 0) {
307 strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
308 for (ptr = temp; *ptr; ptr++)
309 *ptr = tolower(*ptr);
310 debugfs_create_file(temp, 0644, dent_rate,
311 clock, &clock_rate_fops);
312 debugfs_create_file(temp, 0644, dent_enable,
313 clock, &clock_enable_fops);
314 debugfs_create_file(temp, S_IRUGO, dent_local,
315 clock, &clock_local_fops);
316 }
317 return 0;
318}
319
320device_initcall(clock_debug_init);
321#endif
322
323/* The bootloader and/or AMSS may have left various clocks enabled. 189/* The bootloader and/or AMSS may have left various clocks enabled.
324 * Disable any clocks that belong to us (CLKFLAG_AUTO_OFF) but have 190 * Disable any clocks that belong to us (CLKFLAG_AUTO_OFF) but have
325 * not been explicitly enabled by a clk_enable() call. 191 * not been explicitly enabled by a clk_enable() call.
@@ -330,8 +196,10 @@ static int __init clock_late_init(void)
330 struct clk *clk; 196 struct clk *clk;
331 unsigned count = 0; 197 unsigned count = 0;
332 198
199 clock_debug_init();
333 mutex_lock(&clocks_mutex); 200 mutex_lock(&clocks_mutex);
334 list_for_each_entry(clk, &clocks, list) { 201 list_for_each_entry(clk, &clocks, list) {
202 clock_debug_add(clk);
335 if (clk->flags & CLKFLAG_AUTO_OFF) { 203 if (clk->flags & CLKFLAG_AUTO_OFF) {
336 spin_lock_irqsave(&clocks_lock, flags); 204 spin_lock_irqsave(&clocks_lock, flags);
337 if (!clk->count) { 205 if (!clk->count) {