Signed-off-by: Antony Pavlov <antonynpavlov@xxxxxxxxx> --- 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@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox