All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: Allow phase adjustment from debugfs
@ 2023-04-20 10:38 John Keeping
  2023-10-24  3:22 ` Stephen Boyd
  0 siblings, 1 reply; 2+ messages in thread
From: John Keeping @ 2023-04-20 10:38 UTC (permalink / raw)
  To: linux-clk; +Cc: John Keeping, Michael Turquette, Stephen Boyd, linux-kernel

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>
---
 drivers/clk/clk.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 27c30a533759..2d3b6869f3f6 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3297,6 +3297,21 @@ static int clk_rate_set(void *data, u64 val)
 
 #define clk_rate_mode	0644
 
+static int clk_phase_set(void *data, u64 val)
+{
+	struct clk_core *core = data;
+	int degrees = do_div(val, 360);
+	int ret;
+
+	clk_prepare_lock();
+	ret = clk_core_set_phase_nolock(core, degrees);
+	clk_prepare_unlock();
+
+	return ret;
+}
+
+#define clk_phase_mode	0644
+
 static int clk_prepare_enable_set(void *data, u64 val)
 {
 	struct clk_core *core = data;
@@ -3324,6 +3339,9 @@ DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get,
 #else
 #define clk_rate_set	NULL
 #define clk_rate_mode	0444
+
+#define clk_phase_set	NULL
+#define clk_phase_mode	0644
 #endif
 
 static int clk_rate_get(void *data, u64 *val)
@@ -3339,6 +3357,16 @@ static int clk_rate_get(void *data, u64 *val)
 
 DEFINE_DEBUGFS_ATTRIBUTE(clk_rate_fops, clk_rate_get, clk_rate_set, "%llu\n");
 
+static int clk_phase_get(void *data, u64 *val)
+{
+	struct clk_core *core = data;
+
+	*val = core->phase;
+	return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(clk_phase_fops, clk_phase_get, clk_phase_set, "%llu\n");
+
 static const struct {
 	unsigned long flag;
 	const char *name;
@@ -3529,7 +3557,8 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
 	debugfs_create_file("clk_min_rate", 0444, root, core, &clk_min_rate_fops);
 	debugfs_create_file("clk_max_rate", 0444, root, core, &clk_max_rate_fops);
 	debugfs_create_ulong("clk_accuracy", 0444, root, &core->accuracy);
-	debugfs_create_u32("clk_phase", 0444, root, &core->phase);
+	debugfs_create_file("clk_phase", clk_phase_mode, root, core,
+			    &clk_phase_fops);
 	debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops);
 	debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count);
 	debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count);
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk: Allow phase adjustment from debugfs
  2023-04-20 10:38 [PATCH] clk: Allow phase adjustment from debugfs John Keeping
@ 2023-10-24  3:22 ` Stephen Boyd
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2023-10-24  3:22 UTC (permalink / raw)
  To: John Keeping, linux-clk; +Cc: John Keeping, Michael Turquette, linux-kernel

Quoting John Keeping (2023-04-20 03:38:04)
> 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>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-24  3:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 10:38 [PATCH] clk: Allow phase adjustment from debugfs John Keeping
2023-10-24  3:22 ` Stephen Boyd

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.