mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Add clk_round_rate command
@ 2021-06-15 13:18 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2021-06-15 13:18 UTC (permalink / raw)
  To: Barebox List

clk_round_rate returns the rate a clk rate will result to if called
clk_set_rate on it with that rate. Add a command for it as it comes
in handy sometimes for testing and debugging purposes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/clk.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/commands/clk.c b/commands/clk.c
index 649a0a7cb2..2e21e9df58 100644
--- a/commands/clk.c
+++ b/commands/clk.c
@@ -82,6 +82,38 @@ BAREBOX_CMD_START(clk_set_rate)
 	BAREBOX_CMD_COMPLETE(clk_name_complete)
 BAREBOX_CMD_END
 
+static int do_clk_round_rate(int argc, char *argv[])
+{
+	struct clk *clk;
+	unsigned long rate;
+
+	if (argc != 3)
+		return COMMAND_ERROR_USAGE;
+
+	clk = clk_lookup(argv[1]);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	rate = simple_strtoul(argv[2], NULL, 0);
+
+	printf("%ld\n", clk_round_rate(clk, rate));
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(clk_round_rate)
+BAREBOX_CMD_HELP_TEXT("Set clock CLK to RATE")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(clk_round_rate)
+	.cmd		= do_clk_round_rate,
+	BAREBOX_CMD_DESC("set a clocks rate")
+	BAREBOX_CMD_OPTS("CLK HZ")
+	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+	BAREBOX_CMD_HELP(cmd_clk_round_rate_help)
+	BAREBOX_CMD_COMPLETE(clk_name_complete)
+BAREBOX_CMD_END
+
 static int do_clk_get_rate(int argc, char *argv[])
 {
 	int opt;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-15 19:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 13:18 [PATCH] Add clk_round_rate command Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox