2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/ctype.h>
19 #include <linux/debugfs.h>
20 #include <linux/clk.h>
23 static int clock_debug_rate_set(void *data, u64 val)
25 struct clk *clock = data;
28 /* Only increases to max rate will succeed, but that's actually good
29 * for debugging purposes so we don't check for error. */
30 if (clock->flags & CLK_MAX)
31 clk_set_max_rate(clock, val);
32 if (clock->flags & CLK_MIN)
33 ret = clk_set_min_rate(clock, val);
35 ret = clk_set_rate(clock, val);
37 printk(KERN_ERR "clk_set%s_rate failed (%d)\n",
38 (clock->flags & CLK_MIN) ? "_min" : "", ret);
42 static int clock_debug_rate_get(void *data, u64 *val)
44 struct clk *clock = data;
45 *val = clk_get_rate(clock);
49 DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get,
50 clock_debug_rate_set, "%llu\n");
52 static int clock_debug_enable_set(void *data, u64 val)
54 struct clk *clock = data;
58 rc = clock->ops->enable(clock->id);
60 clock->ops->disable(clock->id);
65 static int clock_debug_enable_get(void *data, u64 *val)
67 struct clk *clock = data;
69 *val = clock->ops->is_enabled(clock->id);
74 DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get,
75 clock_debug_enable_set, "%llu\n");
77 static int clock_debug_local_get(void *data, u64 *val)
79 struct clk *clock = data;
81 *val = clock->ops->is_local(clock->id);
86 DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get,
89 static struct dentry *debugfs_base;
91 int __init clock_debug_init(void)
93 debugfs_base = debugfs_create_dir("clk", NULL);
99 int __init clock_debug_add(struct clk *clock)
102 struct dentry *clk_dir;
107 strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
108 for (ptr = temp; *ptr; ptr++)
109 *ptr = tolower(*ptr);
111 clk_dir = debugfs_create_dir(temp, debugfs_base);
115 if (!debugfs_create_file("rate", S_IRUGO | S_IWUSR, clk_dir,
116 clock, &clock_rate_fops))
119 if (!debugfs_create_file("enable", S_IRUGO | S_IWUSR, clk_dir,
120 clock, &clock_enable_fops))
123 if (!debugfs_create_file("is_local", S_IRUGO, clk_dir, clock,
128 debugfs_remove_recursive(clk_dir);