blob: 677db01042df387863f3c54c0489c7834a6314ef [file] [log] [blame]
Amit Arora728e0c92010-09-14 12:06:09 +05301/*******************************************************************************
Amit Kucheriac0e17fc2011-01-17 09:35:52 +02002 * Copyright (C) 2010, Linaro Limited.
Amit Arora728e0c92010-09-14 12:06:09 +05303 *
4 * This file is part of PowerDebug.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
13 * - initial API and implementation
14 *******************************************************************************/
15
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010016#include <stdio.h>
17#include <mntent.h>
Daniel Lezcanoef323192011-03-26 22:06:20 +010018#include <sys/stat.h>
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010019
Amit Arora728e0c92010-09-14 12:06:09 +053020#include "powerdebug.h"
Amit Aroraed3e5652010-10-27 12:02:53 +053021#include "clocks.h"
Amit Arora24ed7d12010-09-14 12:12:58 +053022
Daniel Lezcanoef323192011-03-26 22:06:20 +010023#define MAX_LINES 120
24
Amit Arora24ed7d12010-09-14 12:12:58 +053025static char clk_dir_path[PATH_MAX];
Amit Aroraac4e8652010-11-09 11:16:53 +053026static int bold[MAX_LINES];
Daniel Lezcanoef323192011-03-26 22:06:20 +010027static char clock_lines[MAX_LINES][128];
28static int clock_line_no;
29static int old_clock_line_no;
Amit Arora24ed7d12010-09-14 12:12:58 +053030
Daniel Lezcanoc45662b2011-06-08 23:30:00 +020031struct clock_info {
32 char name[NAME_MAX];
33 int flags;
34 int rate;
35 int usecount;
36 int num_children;
37 int last_child;
38 int expanded;
39 int level;
40 struct clock_info *parent;
41 struct clock_info **children;
42} *clocks_info;
43
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010044static int locate_debugfs(char *clk_path)
45{
46 const char *mtab = "/proc/mounts";
47 struct mntent *mntent;
48 int ret = -1;
49 FILE *file = NULL;
50
51 file = setmntent(mtab, "r");
52 if (!file)
53 return -1;
54
55 while ((mntent = getmntent(file))) {
56
57 if (strcmp(mntent->mnt_type, "debugfs"))
58 continue;
59
60 strcpy(clk_path, mntent->mnt_dir);
61 ret = 0;
62 break;
63 }
64
65 fclose(file);
66 return ret;
67}
68
Daniel Lezcanof0e06652011-03-26 22:06:19 +010069int clock_init(void)
Amit Arora24ed7d12010-09-14 12:12:58 +053070{
Daniel Lezcanof0e06652011-03-26 22:06:19 +010071 if (locate_debugfs(clk_dir_path))
72 return -1;
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010073
Amit Arora6e774cd2010-10-28 11:31:24 +053074 sprintf(clk_dir_path, "%s/clock", clk_dir_path);
Daniel Lezcanoc5a65bf2011-03-26 22:06:11 +010075
Daniel Lezcanof0e06652011-03-26 22:06:19 +010076 return access(clk_dir_path, F_OK);
Amit Arora24ed7d12010-09-14 12:12:58 +053077}
Amit Arora728e0c92010-09-14 12:06:09 +053078
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010079static int file_read_from_format(char *file, int *value, const char *format)
Amit Arora728e0c92010-09-14 12:06:09 +053080{
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010081 FILE *f;
Amit Arora6e774cd2010-10-28 11:31:24 +053082 int ret;
Amit Arora728e0c92010-09-14 12:06:09 +053083
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010084 f = fopen(file, "r");
85 if (!f)
86 return -1;
87 ret = fscanf(f, format, value);
88 fclose(f);
Amit Arora728e0c92010-09-14 12:06:09 +053089
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010090 return !ret ? -1 : 0;
91}
Amit Arora728e0c92010-09-14 12:06:09 +053092
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010093static inline int file_read_int(char *file, int *value)
94{
95 return file_read_from_format(file, value, "%d");
96}
Amit Arora728e0c92010-09-14 12:06:09 +053097
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010098static inline int file_read_hex(char *file, int *value)
99{
100 return file_read_from_format(file, value, "%x");
Amit Arora728e0c92010-09-14 12:06:09 +0530101}
102
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100103static void dump_parent(struct clock_info *clk, int line, bool dump)
104{
105 char *unit = "Hz";
106 double drate;
107 static char spaces[64];
108 char str[256];
109 static int maxline;
110
111 if (maxline < line)
112 maxline = line;
113
114 if (clk && clk->parent)
115 dump_parent(clk->parent, ++line, dump);
116
117 drate = (double)clk->rate;
118 if (drate > 1000 && drate < 1000000) {
119 unit = "KHz";
120 drate /= 1000;
121 }
122 if (drate > 1000000) {
123 unit = "MHz";
124 drate /= 1000000;
125 }
126 if (clk == clocks_info) {
127 line++;
128 strcpy(spaces, "");
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100129 sprintf(str, "%s%s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100130 spaces, clk->name, clk->flags, clk->usecount, drate,
131 unit);
132 } else {
133 if (!(clk->parent == clocks_info))
134 strcat(spaces, " ");
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100135 sprintf(str, "%s`- %s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100136 spaces, clk->name, clk->flags, clk->usecount, drate,
137 unit);
138 }
139 if (dump)
140 //printf("line=%d:m%d:l%d %s", maxline - line + 2, maxline, line, str);
141 printf("%s", str);
142 else
143 print_one_clock(maxline - line + 2, str, 1, 0);
144}
145
Daniel Lezcanoef323192011-03-26 22:06:20 +0100146static struct clock_info *find_clock(struct clock_info *clk, char *clkarg)
147{
148 int i;
149 struct clock_info *ret = clk;
150
151 if (!strcmp(clk->name, clkarg))
152 return ret;
153
154 if (clk->children) {
155 for (i = 0; i < clk->num_children; i++) {
156 if (!strcmp(clk->children[i]->name, clkarg))
157 return clk->children[i];
158 }
159 for (i = 0; i < clk->num_children; i++) {
160 ret = find_clock(clk->children[i], clkarg);
161 if (ret)
162 return ret;
163 }
164 }
165
166 return NULL;
167}
168
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100169static void dump_all_parents(char *clkarg, bool dump)
170{
171 struct clock_info *clk;
172 char spaces[1024];
173
174 strcpy(spaces, "");
175
176 clk = find_clock(clocks_info, clkarg);
177
178 if (!clk)
179 printf("Clock NOT found!\n");
180 else {
181 /* while(clk && clk != clocks_info) { */
182 /* printf("%s\n", clk->name); */
183 /* strcat(spaces, " "); */
184 /* clk = clk->parent; */
185 /* printf("%s <-- ", spaces); */
186 /* } */
187 /* printf(" /\n"); */
188 dump_parent(clk, 1, dump);
189 }
190}
191
Daniel Lezcano897f7332011-03-26 22:06:06 +0100192void find_parents_for_clock(char *clkname, int complete)
Amit Arora3bd79162010-12-01 13:51:42 +0530193{
194 char name[256];
195
196 name[0] = '\0';
197 if (!complete) {
198 char str[256];
199
200 strcat(name, clkname);
201 sprintf(str, "Enter Clock Name : %s\n", name);
202 print_one_clock(2, str, 1, 0);
203 return;
204 }
205 sprintf(name, "Parents for \"%s\" Clock : \n", clkname);
206 print_one_clock(0, name, 1, 1);
Daniel Lezcano897f7332011-03-26 22:06:06 +0100207 dump_all_parents(clkname, false);
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600208}
Amit Arora3bd79162010-12-01 13:51:42 +0530209
Daniel Lezcanoef323192011-03-26 22:06:20 +0100210static void destroy_clocks_info_recur(struct clock_info *clock)
211{
212 int i;
213
214 if (clock && clock->num_children) {
215 for (i = (clock->num_children - 1); i >= 0; i--) {
216 fflush(stdin);
217 destroy_clocks_info_recur(clock->children[i]);
218 if (!i) {
219 free(clock->children);
220 clock->children = NULL;
221 clock->num_children = 0;
222 }
223 }
224 }
225}
226
227static void destroy_clocks_info(void)
228{
229 int i;
230
231 if (!clocks_info)
232 return;
233
234 if (clocks_info->num_children) {
235 for (i = (clocks_info->num_children - 1); i >= 0 ; i--) {
236 destroy_clocks_info_recur(clocks_info->children[i]);
237 if (!i) {
238 free(clocks_info->children);
239 clocks_info->children = NULL;
240 }
241 }
242 }
243 clocks_info->num_children = 0;
244 free(clocks_info);
245 clocks_info = NULL;
246}
247
248
Amit Arora24ed7d12010-09-14 12:12:58 +0530249int read_and_print_clock_info(int verbose, int hrow, int selected)
250{
Amit Arora3bd79162010-12-01 13:51:42 +0530251 print_one_clock(0, "Reading Clock Tree ...", 1, 1);
Amit Aroraa06a7302010-12-02 15:59:37 +0530252
253 if (!old_clock_line_no || selected == REFRESH_WINDOW) {
254 destroy_clocks_info();
Amit Aroraac4e8652010-11-09 11:16:53 +0530255 read_clock_info(clk_dir_path);
Amit Aroraa06a7302010-12-02 15:59:37 +0530256 }
Amit Arora29cb7572010-10-05 17:40:29 +0530257
Amit Arora031263a2010-11-09 11:12:41 +0530258 if (!clocks_info->num_children) {
259 fprintf(stderr, "powerdebug: No clocks found. Exiting..\n");
260 exit(1);
Amit Arora6e774cd2010-10-28 11:31:24 +0530261 }
Amit Arora728e0c92010-09-14 12:06:09 +0530262
Amit Aroraa06a7302010-12-02 15:59:37 +0530263 if (selected == CLOCK_SELECTED)
264 selected = 1;
265 else
266 selected = 0;
267
Amit Aroraac4e8652010-11-09 11:16:53 +0530268 print_clock_info(verbose, hrow, selected);
Amit Aroraac4e8652010-11-09 11:16:53 +0530269 hrow = (hrow < old_clock_line_no) ? hrow : old_clock_line_no - 1;
270
271 return hrow;
272}
273
Daniel Lezcanoef323192011-03-26 22:06:20 +0100274static int calc_delta_screen_size(int hrow)
Amit Arora3bc8c922010-11-16 11:27:38 +0530275{
Amit Arora51d1b9c2010-11-30 13:55:15 +0530276 if (hrow >= (maxy - 3))
277 return hrow - (maxy - 4);
Amit Arora3bc8c922010-11-16 11:27:38 +0530278
279 return 0;
280}
281
Daniel Lezcanoef323192011-03-26 22:06:20 +0100282static void prepare_name_str(char *namestr, struct clock_info *clock)
Amit Aroraac4e8652010-11-09 11:16:53 +0530283{
284 int i;
285
286 strcpy(namestr, "");
287 if (clock->level > 1)
288 for (i = 0; i < (clock->level - 1); i++)
289 strcat(namestr, " ");
290 strcat(namestr, clock->name);
291}
292
Daniel Lezcanoef323192011-03-26 22:06:20 +0100293static void collapse_all_subclocks(struct clock_info *clock)
294{
295 int i;
296
297 clock->expanded = 0;
298 if (clock->num_children)
299 for (i = 0; i < clock->num_children; i++)
300 collapse_all_subclocks(clock->children[i]);
301}
302
303static void add_clock_details_recur(struct clock_info *clock,
304 int hrow, int selected)
Amit Arora031263a2010-11-09 11:12:41 +0530305{
306 int i;
307 char *unit = " Hz";
308 char rate_str[64];
Amit Aroraac4e8652010-11-09 11:16:53 +0530309 char name_str[256];
Amit Arora031263a2010-11-09 11:12:41 +0530310 double drate = (double)clock->rate;
311
312 if (drate > 1000 && drate < 1000000) {
313 unit = "KHz";
314 drate /= 1000;
315 }
316 if (drate > 1000000) {
317 unit = "MHz";
318 drate /= 1000000;
319 }
320 if (clock->usecount)
321 bold[clock_line_no] = 1;
322 else
323 bold[clock_line_no] = 0;
324
325 sprintf(rate_str, "%.2f %s", drate, unit);
Amit Aroraac4e8652010-11-09 11:16:53 +0530326 prepare_name_str(name_str, clock);
Daniel Lezcano4b669072011-05-24 15:27:49 +0200327 sprintf(clock_lines[clock_line_no++], "%-55s 0x%-4x %-12s %-12d %-12d",
Amit Aroraac4e8652010-11-09 11:16:53 +0530328 name_str, clock->flags, rate_str, clock->usecount,
329 clock->num_children);
330
331 if (selected && (hrow == (clock_line_no - 1))) {
332 if (clock->expanded)
333 collapse_all_subclocks(clock);
334 else
335 clock->expanded = 1;
336 selected = 0;
337 }
Amit Arora031263a2010-11-09 11:12:41 +0530338
339 if (clock->expanded && clock->num_children)
340 for (i = 0; i < clock->num_children; i++)
Amit Aroraac4e8652010-11-09 11:16:53 +0530341 add_clock_details_recur(clock->children[i],
342 hrow, selected);
Amit Arora031263a2010-11-09 11:12:41 +0530343 strcpy(clock_lines[clock_line_no], "");
344}
345
Daniel Lezcanoef323192011-03-26 22:06:20 +0100346void print_clock_info(int verbose, int hrow, int selected)
Amit Aroraac4e8652010-11-09 11:16:53 +0530347{
Daniel Lezcanoef323192011-03-26 22:06:20 +0100348 int i, count = 0, delta;
Amit Aroraac4e8652010-11-09 11:16:53 +0530349
Daniel Lezcanoef323192011-03-26 22:06:20 +0100350 (void)verbose;
Amit Aroraac4e8652010-11-09 11:16:53 +0530351
Daniel Lezcanoef323192011-03-26 22:06:20 +0100352 print_clock_header();
Amit Arora031263a2010-11-09 11:12:41 +0530353
Daniel Lezcanoef323192011-03-26 22:06:20 +0100354 for (i = 0; i < clocks_info->num_children; i++)
355 add_clock_details_recur(clocks_info->children[i],
356 hrow, selected);
Amit Aroraa06a7302010-12-02 15:59:37 +0530357
Daniel Lezcanoef323192011-03-26 22:06:20 +0100358 delta = calc_delta_screen_size(hrow);
359
360 while (clock_lines[count + delta] &&
361 strcmp(clock_lines[count + delta], "")) {
362 if (count < delta) {
363 count++;
364 continue;
Amit Arora031263a2010-11-09 11:12:41 +0530365 }
Daniel Lezcanoef323192011-03-26 22:06:20 +0100366 print_one_clock(count - delta, clock_lines[count + delta],
367 bold[count + delta], (hrow == (count + delta)));
368 count++;
Amit Arora031263a2010-11-09 11:12:41 +0530369 }
Amit Arora031263a2010-11-09 11:12:41 +0530370
Daniel Lezcanoef323192011-03-26 22:06:20 +0100371 old_clock_line_no = clock_line_no;
372 clock_line_no = 0;
Amit Arora728e0c92010-09-14 12:06:09 +0530373}
Amit Arora0e512722010-10-01 12:24:16 +0530374
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200375static void insert_children(struct clock_info **parent, struct clock_info *clk)
Amit Aroraf4fb8102010-11-30 13:55:50 +0530376{
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200377 if (!(*parent)->num_children || (*parent)->children == NULL) {
378 (*parent)->children = (struct clock_info **)
379 malloc(sizeof(struct clock_info *)*2);
380 (*parent)->num_children = 0;
381 } else
382 (*parent)->children = (struct clock_info **)
383 realloc((*parent)->children,
384 sizeof(struct clock_info *) *
385 ((*parent)->num_children + 2));
386 if ((*parent)->num_children > 0)
387 (*parent)->children[(*parent)->num_children - 1]->last_child
388 = 0;
389 clk->last_child = 1;
390 (*parent)->children[(*parent)->num_children] = clk;
391 (*parent)->children[(*parent)->num_children + 1] = NULL;
392 (*parent)->num_children++;
Amit Aroraf4fb8102010-11-30 13:55:50 +0530393}
394
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200395static struct clock_info *read_clock_info_recur(char *clkpath, int level,
396 struct clock_info *parent)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530397{
Amit Arora6e774cd2010-10-28 11:31:24 +0530398 int ret = 0;
399 DIR *dir;
400 char filename[PATH_MAX];
401 struct dirent *item;
402 struct clock_info *cur = NULL;
403 struct stat buf;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530404
Amit Arora6e774cd2010-10-28 11:31:24 +0530405 dir = opendir(clkpath);
406 if (!dir)
407 return NULL;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530408
Amit Arora6e774cd2010-10-28 11:31:24 +0530409 while ((item = readdir(dir))) {
410 struct clock_info *child;
411 /* skip hidden dirs except ".." */
412 if (item->d_name[0] == '.' )
413 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530414
Amit Arora6e774cd2010-10-28 11:31:24 +0530415 sprintf(filename, "%s/%s", clkpath, item->d_name);
Amit Arora0e512722010-10-01 12:24:16 +0530416
Amit Arora6e774cd2010-10-28 11:31:24 +0530417 ret = stat(filename, &buf);
Amit Arora0e512722010-10-01 12:24:16 +0530418
Amit Arora6e774cd2010-10-28 11:31:24 +0530419 if (ret < 0) {
420 printf("Error doing a stat on %s\n", filename);
421 exit(1);
422 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530423
Amit Arora6e774cd2010-10-28 11:31:24 +0530424 if (S_ISREG(buf.st_mode)) {
425 if (!strcmp(item->d_name, "flags"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100426 file_read_hex(filename, &parent->flags);
Amit Arora6e774cd2010-10-28 11:31:24 +0530427 if (!strcmp(item->d_name, "rate"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100428 file_read_int(filename, &parent->rate);
Amit Arora6e774cd2010-10-28 11:31:24 +0530429 if (!strcmp(item->d_name, "usecount"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100430 file_read_int(filename, &parent->usecount);
Amit Arora6e774cd2010-10-28 11:31:24 +0530431 continue;
432 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530433
Amit Arora6e774cd2010-10-28 11:31:24 +0530434 if (!S_ISDIR(buf.st_mode))
435 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530436
Amit Arora6e774cd2010-10-28 11:31:24 +0530437 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
438 memset(cur, 0, sizeof(cur));
439 strcpy(cur->name, item->d_name);
440 cur->children = NULL;
441 cur->parent = NULL;
442 cur->num_children = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530443 cur->expanded = 0;
Amit Aroraac4e8652010-11-09 11:16:53 +0530444 cur->level = level;
Amit Arora6e774cd2010-10-28 11:31:24 +0530445 child = read_clock_info_recur(filename, level + 1, cur);
Amit Arora6e774cd2010-10-28 11:31:24 +0530446 insert_children(&parent, cur);
447 cur->parent = parent;
448 }
449 closedir(dir);
Amit Aroraeb6cba92010-10-25 16:03:21 +0530450
Amit Arora6e774cd2010-10-28 11:31:24 +0530451 return cur;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530452}
453
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200454void read_clock_info(char *clkpath)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530455{
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200456 DIR *dir;
457 struct dirent *item;
458 char filename[NAME_MAX], clockname[NAME_MAX];
459 struct clock_info *child;
460 struct clock_info *cur;
461
462 dir = opendir(clkpath);
463 if (!dir)
464 return;
465
466 clocks_info = (struct clock_info *)malloc(sizeof(struct clock_info));
467 memset(clocks_info, 0, sizeof(clocks_info));
468 strcpy(clocks_info->name, "/");
469 clocks_info->level = 0;
470
471 while ((item = readdir(dir))) {
472 /* skip hidden dirs except ".." */
473 if (item->d_name[0] == '.')
474 continue;
475
476 strcpy(clockname, item->d_name);
477 sprintf(filename, "%s/%s", clkpath, item->d_name);
478 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
479 memset(cur, 0, sizeof(struct clock_info));
480 strcpy(cur->name, clockname);
481 cur->parent = clocks_info;
482 cur->num_children = 0;
483 cur->expanded = 0;
484 cur->level = 1;
485 insert_children(&clocks_info, cur);
486 child = read_clock_info_recur(filename, 2, cur);
487 }
488 closedir(dir);
489}
490
491void read_and_dump_clock_info_one(char *clk, bool dump)
492{
493 printf("\nParents for \"%s\" Clock :\n\n", clk);
494 read_clock_info(clk_dir_path);
495 dump_all_parents(clk, dump);
496 printf("\n\n");
Amit Aroraeb6cba92010-10-25 16:03:21 +0530497}
498
Amit Aroraac4e8652010-11-09 11:16:53 +0530499void dump_clock_info(struct clock_info *clk, int level, int bmp)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530500{
Amit Arora6e774cd2010-10-28 11:31:24 +0530501 int i, j;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530502
Amit Arora6e774cd2010-10-28 11:31:24 +0530503 if (!clk)
504 return;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530505
Amit Arora6e774cd2010-10-28 11:31:24 +0530506 for (i = 1, j = 0; i < level; i++, j = (i - 1)) {
507 if (i == (level - 1)) {
508 if (clk->last_child)
509 printf("`-- ");
510 else
511 printf("|-- ");
512 } else {
513 if ((1<<j) & bmp)
514 printf("| ");
515 else
516 printf(" ");
517 }
518 }
Amit Arora031263a2010-11-09 11:12:41 +0530519
Amit Arora6e774cd2010-10-28 11:31:24 +0530520 if (clk == clocks_info)
521 printf("%s\n", clk->name);
522 else {
523 char *unit = "Hz";
524 double drate = (double)clk->rate;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600525
Amit Arora6e774cd2010-10-28 11:31:24 +0530526 if (drate > 1000 && drate < 1000000) {
527 unit = "KHz";
528 drate /= 1000;
529 }
530 if (drate > 1000000) {
531 unit = "MHz";
532 drate /= 1000000;
533 }
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100534 printf("%s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Amit Arora6e774cd2010-10-28 11:31:24 +0530535 clk->name, clk->flags, clk->usecount, drate, unit);
Amit Arora6e774cd2010-10-28 11:31:24 +0530536 }
537 if (clk->children) {
538 int tbmp = bmp;
539 int xbmp = -1;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530540
Amit Arora6e774cd2010-10-28 11:31:24 +0530541 if (clk->last_child) {
542 xbmp ^= 1 << (level - 2);
543
544 xbmp = tbmp & xbmp;
545 } else
546 xbmp = bmp;
547 for (i = 0; i < clk->num_children; i++) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530548 tbmp = xbmp | (1 << level);
Amit Aroraac4e8652010-11-09 11:16:53 +0530549 dump_clock_info(clk->children[i], level + 1, tbmp);
Amit Arora6e774cd2010-10-28 11:31:24 +0530550 }
551 }
Amit Arora0e512722010-10-01 12:24:16 +0530552}
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200553
554void read_and_dump_clock_info(int verbose)
555{
556 (void)verbose;
557 printf("\nClock Tree :\n");
558 printf("**********\n");
559 read_clock_info(clk_dir_path);
560 dump_clock_info(clocks_info, 1, 1);
561 printf("\n\n");
562}