blob: 7a839666ffdadd0d8020a611ab4ea20e1a79a026 [file] [log] [blame]
Shashank Mittal4f73a8f2012-01-25 16:05:36 -08001/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Shashank Mittal4f73a8f2012-01-25 16:05:36 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
Duy Truongf3ac7b32013-02-13 01:07:28 -080011 * * Neither the name of The Linux Foundation nor
Shashank Mittal4f73a8f2012-01-25 16:05:36 -080012 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <debug.h>
31#include <string.h>
32#include <app.h>
33#include <platform.h>
34#include <kernel/thread.h>
35#include <err.h>
36
37#if defined(WITH_LIB_CONSOLE) && defined(DEBUG_CLOCK)
38#include <lib/console.h>
39#include <clock.h>
40
41static void print_clock_list()
42{
43 unsigned i;
44 struct clk_lookup *cl;
45 unsigned num;
46 struct clk_list *clock_list = clk_get_list();
47
48 if(!clock_list)
49 return;
50
51 cl = clock_list->clist;
52 num = clock_list->num;
53
54 if(!cl || !num)
55 return;
56
57 printf("Clock list:\n");
58 for(i=0; i < num; i++, cl++)
59 {
60 printf("%s\n", cl->con_id);
61 }
62}
63
64static int clock_measure(const char *id)
65{
66 int ret = NO_ERROR;
67 struct clk *cp, *mcp;
68 unsigned long rate;
69
70 /* Get clk */
71 cp = clk_get(id);
72 if(!cp)
73 {
74 ret = ERR_NOT_VALID;
75 goto measure_error;
76 }
77
78 /* Get measure clk */
79 mcp = clk_get("measure");
80 if(!mcp)
81 {
82 ret = ERR_NOT_VALID;
83 goto measure_error;
84 }
85
86 /* Set parent clk */
87 clk_set_parent(mcp, cp);
88
89 rate = clk_get_rate(mcp);
90
91 printf("Clock %s is running at: %lu Hz.\n", id, rate);
92
93measure_error:
94 return ret;
95}
96
97static int clock_tests(int argc, cmd_args *argv)
98{
99 if (argc < 2) {
100 printf("not enough arguments:\n");
101 printf("%s <clock-name>\n", argv[0].str);
102 printf("%s ?\n", argv[0].str);
103 goto out;
104 }
105 if(argv[1].str[0] == '?')
106 print_clock_list();
107 else
108 clock_measure(argv[1].str);
109out:
110 return 0;
111}
112
113STATIC_COMMAND_START
114{ "test_clock", "Test Clock", &clock_tests },
115STATIC_COMMAND_END(clocktests);
116
117#endif
118
119APP_START(clocktests)
120APP_END
121