From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] commands: add clk_get_rate command
Date: Thu, 22 Oct 2015 08:45:25 +0300 [thread overview]
Message-ID: <1445492727-905-2-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1445492727-905-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/clk.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/commands/clk.c b/commands/clk.c
index 4e7ca60..469d9b3 100644
--- a/commands/clk.c
+++ b/commands/clk.c
@@ -3,6 +3,8 @@
#include <getopt.h>
#include <linux/clk.h>
#include <linux/err.h>
+#include <environment.h>
+#include <malloc.h>
static int do_clk_enable(int argc, char *argv[])
{
@@ -77,6 +79,59 @@ BAREBOX_CMD_START(clk_set_rate)
BAREBOX_CMD_HELP(cmd_clk_set_rate_help)
BAREBOX_CMD_END
+static int do_clk_get_rate(int argc, char *argv[])
+{
+ int opt;
+ struct clk *clk;
+ unsigned long rate;
+ const char *variable_name = NULL;
+
+ while ((opt = getopt(argc, argv, "s:")) > 0) {
+ switch (opt) {
+ case 's':
+ variable_name = optarg;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (optind == argc) {
+ fprintf(stderr, "No clock name given\n");
+ return COMMAND_ERROR_USAGE;
+ }
+
+ clk = clk_lookup(argv[optind]);
+ if (IS_ERR(clk))
+ return PTR_ERR(clk);
+
+ rate = clk_get_rate(clk);
+
+ if (variable_name) {
+ char *t;
+
+ t = asprintf("%lu", rate);
+ setenv(variable_name, t);
+ free(t);
+ } else
+ printf("%lu\n", rate);
+
+ return COMMAND_SUCCESS;
+}
+
+BAREBOX_CMD_HELP_START(clk_get_rate)
+BAREBOX_CMD_HELP_TEXT("Show clock CLK rate")
+BAREBOX_CMD_HELP_OPT("-s VARNAME", "set variable VARNAME instead of showing information")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(clk_get_rate)
+ .cmd = do_clk_get_rate,
+ BAREBOX_CMD_DESC("get a clocks rate")
+ BAREBOX_CMD_OPTS("[-s VARNAME] CLK")
+ BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+ BAREBOX_CMD_HELP(cmd_clk_get_rate_help)
+BAREBOX_CMD_END
+
static int do_clk_dump(int argc, char *argv[])
{
int opt, verbose = 0;
--
2.6.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-10-22 5:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 5:45 [PATCH 0/3] misc clk-related changes Antony Pavlov
2015-10-22 5:45 ` Antony Pavlov [this message]
2015-10-22 5:45 ` [PATCH 2/3] clock.h: include <types.h> under guard macro Antony Pavlov
2015-10-22 5:45 ` [PATCH 3/3] commands: clk_dump: use COMMAND_SUCCESS instead of 0 return code Antony Pavlov
2015-10-22 7:34 ` [PATCH 0/3] misc clk-related changes Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1445492727-905-2-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox