clk: add/modify debugfs support for clocks
Update clock debugfs to support the below functionalities. - Allow enable/disable a clock. - Allow set_rate on a clock. - Display the list of enabled_clocks along with prepare_count, enable_count and rate. - Display the register contents of all the clocks which support this clock operation. Change-Id: Ib67b3a3409c9e7d8adb710bb524f54f543abf712 Signed-off-by: Taniya Das <tdas@codeaurora.org>
This commit is contained in:
parent
1e17007652
commit
770f204fbd
2 changed files with 209 additions and 4 deletions
|
@ -2409,6 +2409,190 @@ static const struct file_operations clk_dump_fops = {
|
|||
.release = single_release,
|
||||
};
|
||||
|
||||
static int clock_debug_rate_set(void *data, u64 val)
|
||||
{
|
||||
struct clk_core *core = data;
|
||||
int ret;
|
||||
|
||||
ret = clk_set_rate(core->hw->clk, val);
|
||||
if (ret)
|
||||
pr_err("clk_set_rate(%lu) failed (%d)\n",
|
||||
(unsigned long)val, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int clock_debug_rate_get(void *data, u64 *val)
|
||||
{
|
||||
struct clk_core *core = data;
|
||||
|
||||
*val = core->hw->core->rate;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get,
|
||||
clock_debug_rate_set, "%llu\n");
|
||||
|
||||
static ssize_t clock_parent_read(struct file *filp, char __user *ubuf,
|
||||
size_t cnt, loff_t *ppos)
|
||||
{
|
||||
char name[256] = {0};
|
||||
struct clk_core *core = filp->private_data;
|
||||
struct clk_core *p = core->hw->core->parent;
|
||||
|
||||
snprintf(name, sizeof(name), "%s\n", p ? p->name : "None\n");
|
||||
|
||||
return simple_read_from_buffer(ubuf, cnt, ppos, name, strlen(name));
|
||||
}
|
||||
|
||||
static const struct file_operations clock_parent_fops = {
|
||||
.open = simple_open,
|
||||
.read = clock_parent_read,
|
||||
};
|
||||
|
||||
static int clock_debug_enable_set(void *data, u64 val)
|
||||
{
|
||||
struct clk_core *core = data;
|
||||
int rc = 0;
|
||||
|
||||
if (val)
|
||||
rc = clk_prepare_enable(core->hw->clk);
|
||||
else
|
||||
clk_disable_unprepare(core->hw->clk);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int clock_debug_enable_get(void *data, u64 *val)
|
||||
{
|
||||
struct clk_core *core = data;
|
||||
int enabled = 0;
|
||||
|
||||
enabled = core->enable_count;
|
||||
|
||||
*val = enabled;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get,
|
||||
clock_debug_enable_set, "%lld\n");
|
||||
|
||||
#define clock_debug_output(m, c, fmt, ...) \
|
||||
do { \
|
||||
if (m) \
|
||||
seq_printf(m, fmt, ##__VA_ARGS__); \
|
||||
else if (c) \
|
||||
pr_cont(fmt, ##__VA_ARGS__); \
|
||||
else \
|
||||
pr_info(fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
int clock_debug_print_clock(struct clk_core *c, struct seq_file *s)
|
||||
{
|
||||
char *start = "";
|
||||
struct clk *clk;
|
||||
|
||||
if (!c || !c->prepare_count)
|
||||
return 0;
|
||||
|
||||
clk = c->hw->clk;
|
||||
|
||||
clock_debug_output(s, 0, "\t");
|
||||
|
||||
do {
|
||||
clock_debug_output(s, 1, "%s%s:%u:%u [%ld]", start,
|
||||
clk->core->name,
|
||||
clk->core->prepare_count,
|
||||
clk->core->enable_count,
|
||||
clk->core->rate);
|
||||
start = " -> ";
|
||||
} while ((clk = clk_get_parent(clk)));
|
||||
|
||||
clock_debug_output(s, 1, "\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* clock_debug_print_enabled_clocks() - Print names of enabled clocks
|
||||
*/
|
||||
static void clock_debug_print_enabled_clocks(struct seq_file *s)
|
||||
{
|
||||
struct clk_core *core;
|
||||
int cnt = 0;
|
||||
|
||||
clock_debug_output(s, 0, "Enabled clocks:\n");
|
||||
|
||||
mutex_lock(&clk_debug_lock);
|
||||
|
||||
hlist_for_each_entry(core, &clk_debug_list, debug_node)
|
||||
cnt += clock_debug_print_clock(core, s);
|
||||
|
||||
mutex_unlock(&clk_debug_lock);
|
||||
|
||||
if (cnt)
|
||||
clock_debug_output(s, 0, "Enabled clock count: %d\n", cnt);
|
||||
else
|
||||
clock_debug_output(s, 0, "No clocks enabled.\n");
|
||||
}
|
||||
|
||||
static int enabled_clocks_show(struct seq_file *s, void *unused)
|
||||
{
|
||||
clock_debug_print_enabled_clocks(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int enabled_clocks_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, enabled_clocks_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations clk_enabled_list_fops = {
|
||||
.open = enabled_clocks_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = seq_release,
|
||||
};
|
||||
|
||||
static void clk_debug_print_hw(struct clk_core *clk, struct seq_file *f)
|
||||
{
|
||||
if (IS_ERR_OR_NULL(clk))
|
||||
return;
|
||||
|
||||
clk_debug_print_hw(clk->parent, f);
|
||||
|
||||
clock_debug_output(f, false, "%s\n", clk->name);
|
||||
|
||||
if (!clk->ops->list_registers)
|
||||
return;
|
||||
|
||||
clk->ops->list_registers(f, clk->hw);
|
||||
}
|
||||
|
||||
static int print_hw_show(struct seq_file *m, void *unused)
|
||||
{
|
||||
struct clk_core *c = m->private;
|
||||
|
||||
clk_debug_print_hw(c, m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_hw_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, print_hw_show, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations clock_print_hw_fops = {
|
||||
.open = print_hw_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = seq_release,
|
||||
};
|
||||
|
||||
static int clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
|
||||
{
|
||||
struct dentry *d;
|
||||
|
@ -2425,8 +2609,8 @@ static int clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
|
|||
|
||||
core->dentry = d;
|
||||
|
||||
d = debugfs_create_u32("clk_rate", S_IRUGO, core->dentry,
|
||||
(u32 *)&core->rate);
|
||||
d = debugfs_create_file("clk_rate", S_IRUGO, core->dentry, core,
|
||||
&clock_rate_fops);
|
||||
if (!d)
|
||||
goto err_out;
|
||||
|
||||
|
@ -2450,8 +2634,8 @@ static int clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
|
|||
if (!d)
|
||||
goto err_out;
|
||||
|
||||
d = debugfs_create_u32("clk_enable_count", S_IRUGO, core->dentry,
|
||||
(u32 *)&core->enable_count);
|
||||
d = debugfs_create_file("clk_enable_count", S_IRUGO, core->dentry,
|
||||
core, &clock_enable_fops);
|
||||
if (!d)
|
||||
goto err_out;
|
||||
|
||||
|
@ -2460,6 +2644,16 @@ static int clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
|
|||
if (!d)
|
||||
goto err_out;
|
||||
|
||||
d = debugfs_create_file("clk_parent", S_IRUGO, core->dentry, core,
|
||||
&clock_parent_fops);
|
||||
if (!d)
|
||||
goto err_out;
|
||||
|
||||
d = debugfs_create_file("clk_print_regs", S_IRUGO, core->dentry,
|
||||
core, &clock_print_hw_fops);
|
||||
if (!d)
|
||||
goto err_out;
|
||||
|
||||
if (core->ops->debug_init) {
|
||||
ret = core->ops->debug_init(core->hw, core->dentry);
|
||||
if (ret)
|
||||
|
@ -2570,6 +2764,11 @@ static int __init clk_debug_init(void)
|
|||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
d = debugfs_create_file("clk_enabled_list", S_IRUGO, rootdir,
|
||||
&clk_debug_list, &clk_enabled_list_fops);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
mutex_lock(&clk_debug_lock);
|
||||
hlist_for_each_entry(core, &clk_debug_list, debug_node)
|
||||
clk_debug_create_one(core, rootdir);
|
||||
|
|
|
@ -177,6 +177,10 @@ struct clk_rate_request {
|
|||
* @set_flags: Set custom flags which deals with hardware specifics. Returns 0
|
||||
* on success, -EEROR otherwise.
|
||||
*
|
||||
* @list_registers: Queries the hardware to get the current register contents.
|
||||
* This callback is optional and required clocks could
|
||||
* add this callback.
|
||||
*
|
||||
* The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow
|
||||
* implementations to split any work between atomic (enable) and sleepable
|
||||
* (prepare) contexts. If enabling a clock requires code that might sleep,
|
||||
|
@ -217,6 +221,8 @@ struct clk_ops {
|
|||
void (*init)(struct clk_hw *hw);
|
||||
int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
|
||||
int (*set_flags)(struct clk_hw *hw, unsigned flags);
|
||||
void (*list_registers)(struct seq_file *f,
|
||||
struct clk_hw *hw);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue