Skip to content

Commit e43d319

Browse files
johnkeepingbebarino
authored andcommitted
clk: Allow phase adjustment from debugfs
For testing it may be useful to manually adjust a clock's phase. Add support for writing to the existing clk_phase debugfs file, with the written value clamped to [0, 360) to match the behaviour of the clk_set_phase() function. This is a dangerous feature, so use the existing define CLOCK_ALLOW_WRITE_DEBUGFS to allow it only if the source is modified. Signed-off-by: John Keeping <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent dcce5cc commit e43d319

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

drivers/clk/clk.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3343,6 +3343,21 @@ static int clk_rate_set(void *data, u64 val)
33433343

33443344
#define clk_rate_mode 0644
33453345

3346+
static int clk_phase_set(void *data, u64 val)
3347+
{
3348+
struct clk_core *core = data;
3349+
int degrees = do_div(val, 360);
3350+
int ret;
3351+
3352+
clk_prepare_lock();
3353+
ret = clk_core_set_phase_nolock(core, degrees);
3354+
clk_prepare_unlock();
3355+
3356+
return ret;
3357+
}
3358+
3359+
#define clk_phase_mode 0644
3360+
33463361
static int clk_prepare_enable_set(void *data, u64 val)
33473362
{
33483363
struct clk_core *core = data;
@@ -3370,6 +3385,9 @@ DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get,
33703385
#else
33713386
#define clk_rate_set NULL
33723387
#define clk_rate_mode 0444
3388+
3389+
#define clk_phase_set NULL
3390+
#define clk_phase_mode 0644
33733391
#endif
33743392

33753393
static int clk_rate_get(void *data, u64 *val)
@@ -3385,6 +3403,16 @@ static int clk_rate_get(void *data, u64 *val)
33853403

33863404
DEFINE_DEBUGFS_ATTRIBUTE(clk_rate_fops, clk_rate_get, clk_rate_set, "%llu\n");
33873405

3406+
static int clk_phase_get(void *data, u64 *val)
3407+
{
3408+
struct clk_core *core = data;
3409+
3410+
*val = core->phase;
3411+
return 0;
3412+
}
3413+
3414+
DEFINE_DEBUGFS_ATTRIBUTE(clk_phase_fops, clk_phase_get, clk_phase_set, "%llu\n");
3415+
33883416
static const struct {
33893417
unsigned long flag;
33903418
const char *name;
@@ -3575,7 +3603,8 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
35753603
debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops);
35763604
debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops);
35773605
debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy);
3578-
debugfs_create_u32("clk_phase", 0444, root, &core->phase);
3606+
debugfs_create_file("clk_phase", clk_phase_mode, root, core,
3607+
&clk_phase_fops);
35793608
debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops);
35803609
debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count);
35813610
debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count);

0 commit comments

Comments
 (0)