Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <john@metanate.com>
Link: https://lore.kernel.org/r/20230420103805.125246-1-john@metanate.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

John Keeping and committed by
Stephen Boyd
e43d3191 dcce5cc7

+30 -1
+30 -1
drivers/clk/clk.c
··· 3343 3343 3344 3344 #define clk_rate_mode 0644 3345 3345 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 + 3346 3361 static int clk_prepare_enable_set(void *data, u64 val) 3347 3362 { 3348 3363 struct clk_core *core = data; ··· 3385 3370 #else 3386 3371 #define clk_rate_set NULL 3387 3372 #define clk_rate_mode 0444 3373 + 3374 + #define clk_phase_set NULL 3375 + #define clk_phase_mode 0644 3388 3376 #endif 3389 3377 3390 3378 static int clk_rate_get(void *data, u64 *val) ··· 3402 3384 } 3403 3385 3404 3386 DEFINE_DEBUGFS_ATTRIBUTE(clk_rate_fops, clk_rate_get, clk_rate_set, "%llu\n"); 3387 + 3388 + static int clk_phase_get(void *data, u64 *val) 3389 + { 3390 + struct clk_core *core = data; 3391 + 3392 + *val = core->phase; 3393 + return 0; 3394 + } 3395 + 3396 + DEFINE_DEBUGFS_ATTRIBUTE(clk_phase_fops, clk_phase_get, clk_phase_set, "%llu\n"); 3405 3397 3406 3398 static const struct { 3407 3399 unsigned long flag; ··· 3603 3575 debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops); 3604 3576 debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops); 3605 3577 debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy); 3606 - debugfs_create_u32("clk_phase", 0444, root, &core->phase); 3578 + debugfs_create_file("clk_phase", clk_phase_mode, root, core, 3579 + &clk_phase_fops); 3607 3580 debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops); 3608 3581 debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count); 3609 3582 debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count);