blob: 8a2dc976aae66ed002704620c5963aee17251072 [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"
Daniel Lezcanoc193b602011-06-08 23:30:00 +020022#include "tree.h"
Amit Arora24ed7d12010-09-14 12:12:58 +053023
Daniel Lezcanoef323192011-03-26 22:06:20 +010024#define MAX_LINES 120
25
Amit Arora24ed7d12010-09-14 12:12:58 +053026static char clk_dir_path[PATH_MAX];
Amit Aroraac4e8652010-11-09 11:16:53 +053027static int bold[MAX_LINES];
Daniel Lezcanoef323192011-03-26 22:06:20 +010028static char clock_lines[MAX_LINES][128];
29static int clock_line_no;
30static int old_clock_line_no;
Amit Arora24ed7d12010-09-14 12:12:58 +053031
Daniel Lezcanoc45662b2011-06-08 23:30:00 +020032struct clock_info {
33 char name[NAME_MAX];
34 int flags;
35 int rate;
36 int usecount;
37 int num_children;
38 int last_child;
39 int expanded;
40 int level;
41 struct clock_info *parent;
42 struct clock_info **children;
43} *clocks_info;
44
Daniel Lezcanoc193b602011-06-08 23:30:00 +020045static struct tree *clock_tree;
46
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010047static int locate_debugfs(char *clk_path)
48{
49 const char *mtab = "/proc/mounts";
50 struct mntent *mntent;
51 int ret = -1;
52 FILE *file = NULL;
53
54 file = setmntent(mtab, "r");
55 if (!file)
56 return -1;
57
58 while ((mntent = getmntent(file))) {
59
60 if (strcmp(mntent->mnt_type, "debugfs"))
61 continue;
62
63 strcpy(clk_path, mntent->mnt_dir);
64 ret = 0;
65 break;
66 }
67
68 fclose(file);
69 return ret;
70}
71
Daniel Lezcanof0e06652011-03-26 22:06:19 +010072int clock_init(void)
Amit Arora24ed7d12010-09-14 12:12:58 +053073{
Daniel Lezcanof0e06652011-03-26 22:06:19 +010074 if (locate_debugfs(clk_dir_path))
75 return -1;
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010076
Amit Arora6e774cd2010-10-28 11:31:24 +053077 sprintf(clk_dir_path, "%s/clock", clk_dir_path);
Daniel Lezcanoc5a65bf2011-03-26 22:06:11 +010078
Daniel Lezcanoc193b602011-06-08 23:30:00 +020079 clock_tree = tree_load(clk_dir_path, NULL);
80 if (!clock_tree)
81 return -1;
82
Daniel Lezcanof0e06652011-03-26 22:06:19 +010083 return access(clk_dir_path, F_OK);
Amit Arora24ed7d12010-09-14 12:12:58 +053084}
Amit Arora728e0c92010-09-14 12:06:09 +053085
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010086static int file_read_from_format(char *file, int *value, const char *format)
Amit Arora728e0c92010-09-14 12:06:09 +053087{
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010088 FILE *f;
Amit Arora6e774cd2010-10-28 11:31:24 +053089 int ret;
Amit Arora728e0c92010-09-14 12:06:09 +053090
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010091 f = fopen(file, "r");
92 if (!f)
93 return -1;
94 ret = fscanf(f, format, value);
95 fclose(f);
Amit Arora728e0c92010-09-14 12:06:09 +053096
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010097 return !ret ? -1 : 0;
98}
Amit Arora728e0c92010-09-14 12:06:09 +053099
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100100static inline int file_read_int(char *file, int *value)
101{
102 return file_read_from_format(file, value, "%d");
103}
Amit Arora728e0c92010-09-14 12:06:09 +0530104
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100105static inline int file_read_hex(char *file, int *value)
106{
107 return file_read_from_format(file, value, "%x");
Amit Arora728e0c92010-09-14 12:06:09 +0530108}
109
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100110static void dump_parent(struct clock_info *clk, int line, bool dump)
111{
112 char *unit = "Hz";
113 double drate;
114 static char spaces[64];
115 char str[256];
116 static int maxline;
117
118 if (maxline < line)
119 maxline = line;
120
121 if (clk && clk->parent)
122 dump_parent(clk->parent, ++line, dump);
123
124 drate = (double)clk->rate;
125 if (drate > 1000 && drate < 1000000) {
126 unit = "KHz";
127 drate /= 1000;
128 }
129 if (drate > 1000000) {
130 unit = "MHz";
131 drate /= 1000000;
132 }
133 if (clk == clocks_info) {
134 line++;
135 strcpy(spaces, "");
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100136 sprintf(str, "%s%s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100137 spaces, clk->name, clk->flags, clk->usecount, drate,
138 unit);
139 } else {
140 if (!(clk->parent == clocks_info))
141 strcat(spaces, " ");
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100142 sprintf(str, "%s`- %s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100143 spaces, clk->name, clk->flags, clk->usecount, drate,
144 unit);
145 }
146 if (dump)
147 //printf("line=%d:m%d:l%d %s", maxline - line + 2, maxline, line, str);
148 printf("%s", str);
149 else
150 print_one_clock(maxline - line + 2, str, 1, 0);
151}
152
Daniel Lezcanoef323192011-03-26 22:06:20 +0100153static struct clock_info *find_clock(struct clock_info *clk, char *clkarg)
154{
155 int i;
156 struct clock_info *ret = clk;
157
158 if (!strcmp(clk->name, clkarg))
159 return ret;
160
161 if (clk->children) {
162 for (i = 0; i < clk->num_children; i++) {
163 if (!strcmp(clk->children[i]->name, clkarg))
164 return clk->children[i];
165 }
166 for (i = 0; i < clk->num_children; i++) {
167 ret = find_clock(clk->children[i], clkarg);
168 if (ret)
169 return ret;
170 }
171 }
172
173 return NULL;
174}
175
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100176static void dump_all_parents(char *clkarg, bool dump)
177{
178 struct clock_info *clk;
179 char spaces[1024];
180
181 strcpy(spaces, "");
182
183 clk = find_clock(clocks_info, clkarg);
184
185 if (!clk)
186 printf("Clock NOT found!\n");
187 else {
188 /* while(clk && clk != clocks_info) { */
189 /* printf("%s\n", clk->name); */
190 /* strcat(spaces, " "); */
191 /* clk = clk->parent; */
192 /* printf("%s <-- ", spaces); */
193 /* } */
194 /* printf(" /\n"); */
195 dump_parent(clk, 1, dump);
196 }
197}
198
Daniel Lezcano897f7332011-03-26 22:06:06 +0100199void find_parents_for_clock(char *clkname, int complete)
Amit Arora3bd79162010-12-01 13:51:42 +0530200{
201 char name[256];
202
203 name[0] = '\0';
204 if (!complete) {
205 char str[256];
206
207 strcat(name, clkname);
208 sprintf(str, "Enter Clock Name : %s\n", name);
209 print_one_clock(2, str, 1, 0);
210 return;
211 }
212 sprintf(name, "Parents for \"%s\" Clock : \n", clkname);
213 print_one_clock(0, name, 1, 1);
Daniel Lezcano897f7332011-03-26 22:06:06 +0100214 dump_all_parents(clkname, false);
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600215}
Amit Arora3bd79162010-12-01 13:51:42 +0530216
Daniel Lezcanoef323192011-03-26 22:06:20 +0100217static void destroy_clocks_info_recur(struct clock_info *clock)
218{
219 int i;
220
221 if (clock && clock->num_children) {
222 for (i = (clock->num_children - 1); i >= 0; i--) {
223 fflush(stdin);
224 destroy_clocks_info_recur(clock->children[i]);
225 if (!i) {
226 free(clock->children);
227 clock->children = NULL;
228 clock->num_children = 0;
229 }
230 }
231 }
232}
233
234static void destroy_clocks_info(void)
235{
236 int i;
237
238 if (!clocks_info)
239 return;
240
241 if (clocks_info->num_children) {
242 for (i = (clocks_info->num_children - 1); i >= 0 ; i--) {
243 destroy_clocks_info_recur(clocks_info->children[i]);
244 if (!i) {
245 free(clocks_info->children);
246 clocks_info->children = NULL;
247 }
248 }
249 }
250 clocks_info->num_children = 0;
251 free(clocks_info);
252 clocks_info = NULL;
253}
254
255
Amit Arora24ed7d12010-09-14 12:12:58 +0530256int read_and_print_clock_info(int verbose, int hrow, int selected)
257{
Amit Arora3bd79162010-12-01 13:51:42 +0530258 print_one_clock(0, "Reading Clock Tree ...", 1, 1);
Amit Aroraa06a7302010-12-02 15:59:37 +0530259
260 if (!old_clock_line_no || selected == REFRESH_WINDOW) {
261 destroy_clocks_info();
Amit Aroraac4e8652010-11-09 11:16:53 +0530262 read_clock_info(clk_dir_path);
Amit Aroraa06a7302010-12-02 15:59:37 +0530263 }
Amit Arora29cb7572010-10-05 17:40:29 +0530264
Daniel Lezcano95b0dac2011-06-08 23:30:00 +0200265 if (!clocks_info || !clocks_info->num_children) {
Amit Arora031263a2010-11-09 11:12:41 +0530266 fprintf(stderr, "powerdebug: No clocks found. Exiting..\n");
267 exit(1);
Amit Arora6e774cd2010-10-28 11:31:24 +0530268 }
Amit Arora728e0c92010-09-14 12:06:09 +0530269
Amit Aroraa06a7302010-12-02 15:59:37 +0530270 if (selected == CLOCK_SELECTED)
271 selected = 1;
272 else
273 selected = 0;
274
Amit Aroraac4e8652010-11-09 11:16:53 +0530275 print_clock_info(verbose, hrow, selected);
Amit Aroraac4e8652010-11-09 11:16:53 +0530276 hrow = (hrow < old_clock_line_no) ? hrow : old_clock_line_no - 1;
277
278 return hrow;
279}
280
Daniel Lezcanoef323192011-03-26 22:06:20 +0100281static int calc_delta_screen_size(int hrow)
Amit Arora3bc8c922010-11-16 11:27:38 +0530282{
Amit Arora51d1b9c2010-11-30 13:55:15 +0530283 if (hrow >= (maxy - 3))
284 return hrow - (maxy - 4);
Amit Arora3bc8c922010-11-16 11:27:38 +0530285
286 return 0;
287}
288
Daniel Lezcanoef323192011-03-26 22:06:20 +0100289static void prepare_name_str(char *namestr, struct clock_info *clock)
Amit Aroraac4e8652010-11-09 11:16:53 +0530290{
291 int i;
292
293 strcpy(namestr, "");
294 if (clock->level > 1)
295 for (i = 0; i < (clock->level - 1); i++)
296 strcat(namestr, " ");
297 strcat(namestr, clock->name);
298}
299
Daniel Lezcanoef323192011-03-26 22:06:20 +0100300static void collapse_all_subclocks(struct clock_info *clock)
301{
302 int i;
303
304 clock->expanded = 0;
305 if (clock->num_children)
306 for (i = 0; i < clock->num_children; i++)
307 collapse_all_subclocks(clock->children[i]);
308}
309
310static void add_clock_details_recur(struct clock_info *clock,
311 int hrow, int selected)
Amit Arora031263a2010-11-09 11:12:41 +0530312{
313 int i;
314 char *unit = " Hz";
315 char rate_str[64];
Amit Aroraac4e8652010-11-09 11:16:53 +0530316 char name_str[256];
Amit Arora031263a2010-11-09 11:12:41 +0530317 double drate = (double)clock->rate;
318
319 if (drate > 1000 && drate < 1000000) {
320 unit = "KHz";
321 drate /= 1000;
322 }
323 if (drate > 1000000) {
324 unit = "MHz";
325 drate /= 1000000;
326 }
327 if (clock->usecount)
328 bold[clock_line_no] = 1;
329 else
330 bold[clock_line_no] = 0;
331
332 sprintf(rate_str, "%.2f %s", drate, unit);
Amit Aroraac4e8652010-11-09 11:16:53 +0530333 prepare_name_str(name_str, clock);
Daniel Lezcano4b669072011-05-24 15:27:49 +0200334 sprintf(clock_lines[clock_line_no++], "%-55s 0x%-4x %-12s %-12d %-12d",
Amit Aroraac4e8652010-11-09 11:16:53 +0530335 name_str, clock->flags, rate_str, clock->usecount,
336 clock->num_children);
337
338 if (selected && (hrow == (clock_line_no - 1))) {
339 if (clock->expanded)
340 collapse_all_subclocks(clock);
341 else
342 clock->expanded = 1;
343 selected = 0;
344 }
Amit Arora031263a2010-11-09 11:12:41 +0530345
346 if (clock->expanded && clock->num_children)
347 for (i = 0; i < clock->num_children; i++)
Amit Aroraac4e8652010-11-09 11:16:53 +0530348 add_clock_details_recur(clock->children[i],
349 hrow, selected);
Amit Arora031263a2010-11-09 11:12:41 +0530350 strcpy(clock_lines[clock_line_no], "");
351}
352
Daniel Lezcanoef323192011-03-26 22:06:20 +0100353void print_clock_info(int verbose, int hrow, int selected)
Amit Aroraac4e8652010-11-09 11:16:53 +0530354{
Daniel Lezcanoef323192011-03-26 22:06:20 +0100355 int i, count = 0, delta;
Amit Aroraac4e8652010-11-09 11:16:53 +0530356
Daniel Lezcanoef323192011-03-26 22:06:20 +0100357 (void)verbose;
Amit Aroraac4e8652010-11-09 11:16:53 +0530358
Daniel Lezcanoef323192011-03-26 22:06:20 +0100359 print_clock_header();
Amit Arora031263a2010-11-09 11:12:41 +0530360
Daniel Lezcanoef323192011-03-26 22:06:20 +0100361 for (i = 0; i < clocks_info->num_children; i++)
362 add_clock_details_recur(clocks_info->children[i],
363 hrow, selected);
Amit Aroraa06a7302010-12-02 15:59:37 +0530364
Daniel Lezcanoef323192011-03-26 22:06:20 +0100365 delta = calc_delta_screen_size(hrow);
366
367 while (clock_lines[count + delta] &&
368 strcmp(clock_lines[count + delta], "")) {
369 if (count < delta) {
370 count++;
371 continue;
Amit Arora031263a2010-11-09 11:12:41 +0530372 }
Daniel Lezcanoef323192011-03-26 22:06:20 +0100373 print_one_clock(count - delta, clock_lines[count + delta],
374 bold[count + delta], (hrow == (count + delta)));
375 count++;
Amit Arora031263a2010-11-09 11:12:41 +0530376 }
Amit Arora031263a2010-11-09 11:12:41 +0530377
Daniel Lezcanoef323192011-03-26 22:06:20 +0100378 old_clock_line_no = clock_line_no;
379 clock_line_no = 0;
Amit Arora728e0c92010-09-14 12:06:09 +0530380}
Amit Arora0e512722010-10-01 12:24:16 +0530381
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200382static void insert_children(struct clock_info **parent, struct clock_info *clk)
Amit Aroraf4fb8102010-11-30 13:55:50 +0530383{
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200384 if (!(*parent)->num_children || (*parent)->children == NULL) {
385 (*parent)->children = (struct clock_info **)
386 malloc(sizeof(struct clock_info *)*2);
387 (*parent)->num_children = 0;
388 } else
389 (*parent)->children = (struct clock_info **)
390 realloc((*parent)->children,
391 sizeof(struct clock_info *) *
392 ((*parent)->num_children + 2));
393 if ((*parent)->num_children > 0)
394 (*parent)->children[(*parent)->num_children - 1]->last_child
395 = 0;
396 clk->last_child = 1;
397 (*parent)->children[(*parent)->num_children] = clk;
398 (*parent)->children[(*parent)->num_children + 1] = NULL;
399 (*parent)->num_children++;
Amit Aroraf4fb8102010-11-30 13:55:50 +0530400}
401
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200402static struct clock_info *read_clock_info_recur(char *clkpath, int level,
403 struct clock_info *parent)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530404{
Amit Arora6e774cd2010-10-28 11:31:24 +0530405 int ret = 0;
406 DIR *dir;
407 char filename[PATH_MAX];
408 struct dirent *item;
409 struct clock_info *cur = NULL;
410 struct stat buf;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530411
Amit Arora6e774cd2010-10-28 11:31:24 +0530412 dir = opendir(clkpath);
413 if (!dir)
414 return NULL;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530415
Amit Arora6e774cd2010-10-28 11:31:24 +0530416 while ((item = readdir(dir))) {
417 struct clock_info *child;
418 /* skip hidden dirs except ".." */
419 if (item->d_name[0] == '.' )
420 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530421
Amit Arora6e774cd2010-10-28 11:31:24 +0530422 sprintf(filename, "%s/%s", clkpath, item->d_name);
Amit Arora0e512722010-10-01 12:24:16 +0530423
Amit Arora6e774cd2010-10-28 11:31:24 +0530424 ret = stat(filename, &buf);
Amit Arora0e512722010-10-01 12:24:16 +0530425
Amit Arora6e774cd2010-10-28 11:31:24 +0530426 if (ret < 0) {
427 printf("Error doing a stat on %s\n", filename);
428 exit(1);
429 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530430
Amit Arora6e774cd2010-10-28 11:31:24 +0530431 if (S_ISREG(buf.st_mode)) {
432 if (!strcmp(item->d_name, "flags"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100433 file_read_hex(filename, &parent->flags);
Amit Arora6e774cd2010-10-28 11:31:24 +0530434 if (!strcmp(item->d_name, "rate"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100435 file_read_int(filename, &parent->rate);
Amit Arora6e774cd2010-10-28 11:31:24 +0530436 if (!strcmp(item->d_name, "usecount"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100437 file_read_int(filename, &parent->usecount);
Amit Arora6e774cd2010-10-28 11:31:24 +0530438 continue;
439 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530440
Amit Arora6e774cd2010-10-28 11:31:24 +0530441 if (!S_ISDIR(buf.st_mode))
442 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530443
Amit Arora6e774cd2010-10-28 11:31:24 +0530444 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
445 memset(cur, 0, sizeof(cur));
446 strcpy(cur->name, item->d_name);
447 cur->children = NULL;
448 cur->parent = NULL;
449 cur->num_children = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530450 cur->expanded = 0;
Amit Aroraac4e8652010-11-09 11:16:53 +0530451 cur->level = level;
Amit Arora6e774cd2010-10-28 11:31:24 +0530452 child = read_clock_info_recur(filename, level + 1, cur);
Amit Arora6e774cd2010-10-28 11:31:24 +0530453 insert_children(&parent, cur);
454 cur->parent = parent;
455 }
456 closedir(dir);
Amit Aroraeb6cba92010-10-25 16:03:21 +0530457
Amit Arora6e774cd2010-10-28 11:31:24 +0530458 return cur;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530459}
460
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200461static struct clock_info *clock_alloc(const char *name)
462{
463 struct clock_info *ci;
464
465 ci = malloc(sizeof(*ci));
466 if (ci) {
467 memset(ci, 0, sizeof(*ci));
468 strcpy(ci->name, name);
469 }
470
471 return ci;
472}
473
474int read_clock_info(char *clkpath)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530475{
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200476 DIR *dir;
477 struct dirent *item;
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200478 char filename[NAME_MAX];
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200479 struct clock_info *child;
480 struct clock_info *cur;
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200481 int ret = -1;
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200482
483 dir = opendir(clkpath);
484 if (!dir)
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200485 return -1;
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200486
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200487 clocks_info = clock_alloc("/");
488 if (!clocks_info)
489 return -1;
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200490
491 while ((item = readdir(dir))) {
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200492
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200493 /* skip hidden dirs except ".." */
494 if (item->d_name[0] == '.')
495 continue;
496
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200497 sprintf(filename, "%s/%s", clkpath, item->d_name);
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200498
499 cur = clock_alloc(item->d_name);
500 if (!cur)
501 goto out;
502
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200503 cur->parent = clocks_info;
504 cur->num_children = 0;
505 cur->expanded = 0;
506 cur->level = 1;
507 insert_children(&clocks_info, cur);
508 child = read_clock_info_recur(filename, 2, cur);
509 }
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200510
511 ret = 0;
512
513out:
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200514 closedir(dir);
Daniel Lezcanob2565a82011-06-08 23:30:00 +0200515
516 return ret;
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200517}
518
519void read_and_dump_clock_info_one(char *clk, bool dump)
520{
521 printf("\nParents for \"%s\" Clock :\n\n", clk);
522 read_clock_info(clk_dir_path);
523 dump_all_parents(clk, dump);
524 printf("\n\n");
Amit Aroraeb6cba92010-10-25 16:03:21 +0530525}
526
Amit Aroraac4e8652010-11-09 11:16:53 +0530527void dump_clock_info(struct clock_info *clk, int level, int bmp)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530528{
Amit Arora6e774cd2010-10-28 11:31:24 +0530529 int i, j;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530530
Amit Arora6e774cd2010-10-28 11:31:24 +0530531 if (!clk)
532 return;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530533
Amit Arora6e774cd2010-10-28 11:31:24 +0530534 for (i = 1, j = 0; i < level; i++, j = (i - 1)) {
535 if (i == (level - 1)) {
536 if (clk->last_child)
537 printf("`-- ");
538 else
539 printf("|-- ");
540 } else {
541 if ((1<<j) & bmp)
542 printf("| ");
543 else
544 printf(" ");
545 }
546 }
Amit Arora031263a2010-11-09 11:12:41 +0530547
Amit Arora6e774cd2010-10-28 11:31:24 +0530548 if (clk == clocks_info)
549 printf("%s\n", clk->name);
550 else {
551 char *unit = "Hz";
552 double drate = (double)clk->rate;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600553
Amit Arora6e774cd2010-10-28 11:31:24 +0530554 if (drate > 1000 && drate < 1000000) {
555 unit = "KHz";
556 drate /= 1000;
557 }
558 if (drate > 1000000) {
559 unit = "MHz";
560 drate /= 1000000;
561 }
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100562 printf("%s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Amit Arora6e774cd2010-10-28 11:31:24 +0530563 clk->name, clk->flags, clk->usecount, drate, unit);
Amit Arora6e774cd2010-10-28 11:31:24 +0530564 }
565 if (clk->children) {
566 int tbmp = bmp;
567 int xbmp = -1;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530568
Amit Arora6e774cd2010-10-28 11:31:24 +0530569 if (clk->last_child) {
570 xbmp ^= 1 << (level - 2);
571
572 xbmp = tbmp & xbmp;
573 } else
574 xbmp = bmp;
575 for (i = 0; i < clk->num_children; i++) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530576 tbmp = xbmp | (1 << level);
Amit Aroraac4e8652010-11-09 11:16:53 +0530577 dump_clock_info(clk->children[i], level + 1, tbmp);
Amit Arora6e774cd2010-10-28 11:31:24 +0530578 }
579 }
Amit Arora0e512722010-10-01 12:24:16 +0530580}
Daniel Lezcano28b53cd2011-06-08 23:30:00 +0200581
582void read_and_dump_clock_info(int verbose)
583{
584 (void)verbose;
585 printf("\nClock Tree :\n");
586 printf("**********\n");
587 read_clock_info(clk_dir_path);
588 dump_clock_info(clocks_info, 1, 1);
589 printf("\n\n");
590}