Skip to content

Commit a331659

Browse files
Sam Protsenkobebarino
authored andcommitted
clk: Add write operation for clk_parent debugfs node
Useful for testing mux clocks. One can write the index of the parent to be set into clk_parent node, starting from 0. Example # cd /sys/kernel/debug/clk/mout_peri_bus # cat clk_possible_parents dout_shared0_div4 dout_shared1_div4 # cat clk_parent dout_shared0_div4 # echo 1 > clk_parent # cat clk_parent dout_shared1_div4 CLOCK_ALLOW_WRITE_DEBUGFS has to be defined in drivers/clk/clk.c in order to use this feature. Signed-off-by: Sam Protsenko <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Fabio Estevam <[email protected]> Acked-by: Michael Turquette <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Collapse ifdefs] Signed-off-by: Stephen Boyd <[email protected]>
1 parent fa55b7d commit a331659

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

drivers/clk/clk.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,42 @@ static int current_parent_show(struct seq_file *s, void *data)
32173217
}
32183218
DEFINE_SHOW_ATTRIBUTE(current_parent);
32193219

3220+
#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
3221+
static ssize_t current_parent_write(struct file *file, const char __user *ubuf,
3222+
size_t count, loff_t *ppos)
3223+
{
3224+
struct seq_file *s = file->private_data;
3225+
struct clk_core *core = s->private;
3226+
struct clk_core *parent;
3227+
u8 idx;
3228+
int err;
3229+
3230+
err = kstrtou8_from_user(ubuf, count, 0, &idx);
3231+
if (err < 0)
3232+
return err;
3233+
3234+
parent = clk_core_get_parent_by_index(core, idx);
3235+
if (!parent)
3236+
return -ENOENT;
3237+
3238+
clk_prepare_lock();
3239+
err = clk_core_set_parent_nolock(core, parent);
3240+
clk_prepare_unlock();
3241+
if (err)
3242+
return err;
3243+
3244+
return count;
3245+
}
3246+
3247+
static const struct file_operations current_parent_rw_fops = {
3248+
.open = current_parent_open,
3249+
.write = current_parent_write,
3250+
.read = seq_read,
3251+
.llseek = seq_lseek,
3252+
.release = single_release,
3253+
};
3254+
#endif
3255+
32203256
static int clk_duty_cycle_show(struct seq_file *s, void *data)
32213257
{
32223258
struct clk_core *core = s->private;
@@ -3282,8 +3318,12 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
32823318
#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
32833319
debugfs_create_file("clk_prepare_enable", 0644, root, core,
32843320
&clk_prepare_enable_fops);
3285-
#endif
32863321

3322+
if (core->num_parents > 1)
3323+
debugfs_create_file("clk_parent", 0644, root, core,
3324+
&current_parent_rw_fops);
3325+
else
3326+
#endif
32873327
if (core->num_parents > 0)
32883328
debugfs_create_file("clk_parent", 0444, root, core,
32893329
&current_parent_fops);

0 commit comments

Comments
 (0)