Skip to content

Commit 03111b1

Browse files
Mike Tiptonbebarino
authored andcommitted
clk: Add support for enabling/disabling clocks from debugfs
For test and debug purposes, it's simple enough to enable or disable clocks from shell. Add a new debugfs file 'clk_prepare_enable' that calls clk_prepare_enable() when writing "1" and clk_disable_unprepare() when writing "0". This can have security implications, so only support it when the code has been modified to #define CLOCK_ALLOW_WRITE_DEBUGFS. Signed-off-by: Mike Tipton <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Reword commit text and remove comment update] Signed-off-by: Stephen Boyd <[email protected]>
1 parent b3a9e3b commit 03111b1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/clk/clk.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,6 +3039,31 @@ static int clk_rate_set(void *data, u64 val)
30393039
}
30403040

30413041
#define clk_rate_mode 0644
3042+
3043+
static int clk_prepare_enable_set(void *data, u64 val)
3044+
{
3045+
struct clk_core *core = data;
3046+
int ret = 0;
3047+
3048+
if (val)
3049+
ret = clk_prepare_enable(core->hw->clk);
3050+
else
3051+
clk_disable_unprepare(core->hw->clk);
3052+
3053+
return ret;
3054+
}
3055+
3056+
static int clk_prepare_enable_get(void *data, u64 *val)
3057+
{
3058+
struct clk_core *core = data;
3059+
3060+
*val = core->enable_count && core->prepare_count;
3061+
return 0;
3062+
}
3063+
3064+
DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get,
3065+
clk_prepare_enable_set, "%llu\n");
3066+
30423067
#else
30433068
#define clk_rate_set NULL
30443069
#define clk_rate_mode 0444
@@ -3216,6 +3241,10 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
32163241
debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count);
32173242
debugfs_create_file("clk_duty_cycle", 0444, root, core,
32183243
&clk_duty_cycle_fops);
3244+
#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
3245+
debugfs_create_file("clk_prepare_enable", 0644, root, core,
3246+
&clk_prepare_enable_fops);
3247+
#endif
32193248

32203249
if (core->num_parents > 0)
32213250
debugfs_create_file("clk_parent", 0444, root, core,

0 commit comments

Comments
 (0)