blob: 81da6c3ea88533598fedb87d9f6bb55d1c62a6c0 [file] [log] [blame]
Amit Arora728e0c92010-09-14 12:06:09 +05301/*******************************************************************************
2 * Copyright (C) 2010, Linaro
3 * Copyright (C) 2010, IBM Corporation
4 *
5 * This file is part of PowerDebug.
6 *
7 * All rights reserved. This program and the accompanying materials
8 * are made available under the terms of the Eclipse Public License v1.0
9 * which accompanies this distribution, and is available at
10 * http://www.eclipse.org/legal/epl-v10.html
11 *
12 * Contributors:
13 * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
14 * - initial API and implementation
15 *******************************************************************************/
16
17#include "powerdebug.h"
Amit Aroraed3e5652010-10-27 12:02:53 +053018#include "clocks.h"
Amit Arora24ed7d12010-09-14 12:12:58 +053019
Amit Arora24ed7d12010-09-14 12:12:58 +053020static char clk_dir_path[PATH_MAX];
Amit Arora24ed7d12010-09-14 12:12:58 +053021static char clk_name[NAME_MAX];
Amit Aroraac4e8652010-11-09 11:16:53 +053022static int bold[MAX_LINES];
Amit Arora24ed7d12010-09-14 12:12:58 +053023
Amit Arora04f97742010-11-16 11:28:57 +053024int init_clock_details(void)
Amit Arora24ed7d12010-09-14 12:12:58 +053025{
Amit Arora6e774cd2010-10-28 11:31:24 +053026 char *path = debugfs_locate_mpoint();
27 struct stat buf;
Amit Aroraed3e5652010-10-27 12:02:53 +053028
Amit Arora6e774cd2010-10-28 11:31:24 +053029 if (path)
30 strcpy(clk_dir_path, path);
31 else {
Amit Arora81350772010-11-16 14:56:26 +053032 if (!dump) {
33 create_selectedwindow();
34 sprintf(clock_lines[0], "Unable to locate debugfs "
35 "mount point. Mount debugfs "
36 "and try again..\n");
37 print_one_clock(0, clock_lines[0], 1, 0);
38 old_clock_line_no = 1;
39 return(1);
40 } else {
41 fprintf(stderr, "powerdebug: Unable to locate debugfs "
42 "mount point. Mount debugfs and try "
43 "again..\n");
44 exit(1);
45 }
Amit Arora6e774cd2010-10-28 11:31:24 +053046 }
47 sprintf(clk_dir_path, "%s/clock", clk_dir_path);
Amit Arora59429a42010-11-16 11:30:20 +053048 //strcpy(clk_dir_path, "/debug/clock"); // Hardcoded for testing..
Amit Arora6e774cd2010-10-28 11:31:24 +053049 if (stat(clk_dir_path, &buf)) {
Amit Arora81350772010-11-16 14:56:26 +053050 if (!dump) {
51 create_selectedwindow();
52 sprintf(clock_lines[0], "Unable to find clock tree"
53 " information at %s.\n", clk_dir_path);
54 print_one_clock(0, clock_lines[0], 1, 0);
55 old_clock_line_no = 1;
56 return(1);
57 } else {
58 fprintf(stderr, "powerdebug: Unable to find clock tree"
59 " information at %s.\n", clk_dir_path);
60 exit(1);
61 }
Amit Arora6e774cd2010-10-28 11:31:24 +053062 }
63 strcpy(clk_name, "");
Amit Arora04f97742010-11-16 11:28:57 +053064 return(0);
Amit Arora24ed7d12010-09-14 12:12:58 +053065}
Amit Arora728e0c92010-09-14 12:06:09 +053066
67int get_int_from(char *file)
68{
Amit Arora6e774cd2010-10-28 11:31:24 +053069 FILE *filep;
70 char result[NAME_MAX];
71 int ret;
Amit Arora728e0c92010-09-14 12:06:09 +053072
Amit Arora6e774cd2010-10-28 11:31:24 +053073 filep = fopen(file, "r");
Amit Arora728e0c92010-09-14 12:06:09 +053074
Amit Arora6e774cd2010-10-28 11:31:24 +053075 if (!filep)
76 return -1; //TBD : What should we return on failure, here ?
Amit Arora728e0c92010-09-14 12:06:09 +053077
Amit Arora6e774cd2010-10-28 11:31:24 +053078 ret = fscanf(filep, "%s", result);
79 fclose(filep);
Amit Arora728e0c92010-09-14 12:06:09 +053080
Amit Arora6e774cd2010-10-28 11:31:24 +053081 return atoi(result);
Amit Arora728e0c92010-09-14 12:06:09 +053082}
83
Amit Arora3bd79162010-12-01 13:51:42 +053084void find_parents_for_clock(char *clkname, int complete)
85{
86 char name[256];
87
88 name[0] = '\0';
89 if (!complete) {
90 char str[256];
91
92 strcat(name, clkname);
93 sprintf(str, "Enter Clock Name : %s\n", name);
94 print_one_clock(2, str, 1, 0);
95 return;
96 }
97 sprintf(name, "Parents for \"%s\" Clock : \n", clkname);
98 print_one_clock(0, name, 1, 1);
99 dump_all_parents(clkname);
100}
101
Amit Arora24ed7d12010-09-14 12:12:58 +0530102int read_and_print_clock_info(int verbose, int hrow, int selected)
103{
Amit Arora3bd79162010-12-01 13:51:42 +0530104 print_one_clock(0, "Reading Clock Tree ...", 1, 1);
Amit Aroraac4e8652010-11-09 11:16:53 +0530105 if (!old_clock_line_no)
106 read_clock_info(clk_dir_path);
Amit Arora29cb7572010-10-05 17:40:29 +0530107
Amit Arora031263a2010-11-09 11:12:41 +0530108 if (!clocks_info->num_children) {
109 fprintf(stderr, "powerdebug: No clocks found. Exiting..\n");
110 exit(1);
Amit Arora6e774cd2010-10-28 11:31:24 +0530111 }
Amit Arora728e0c92010-09-14 12:06:09 +0530112
Amit Aroraac4e8652010-11-09 11:16:53 +0530113 print_clock_info(verbose, hrow, selected);
114 //destroy_clocks_info();
115 hrow = (hrow < old_clock_line_no) ? hrow : old_clock_line_no - 1;
116
117 return hrow;
118}
119
Amit Arora3bc8c922010-11-16 11:27:38 +0530120int calc_delta_screen_size(int hrow)
121{
Amit Arora51d1b9c2010-11-30 13:55:15 +0530122 if (hrow >= (maxy - 3))
123 return hrow - (maxy - 4);
Amit Arora3bc8c922010-11-16 11:27:38 +0530124
125 return 0;
126}
127
Amit Aroraac4e8652010-11-09 11:16:53 +0530128void print_clock_info(int verbose, int hrow, int selected)
129{
Amit Arora3bc8c922010-11-16 11:27:38 +0530130 int i, count = 0, delta;
Amit Aroraac4e8652010-11-09 11:16:53 +0530131
132 (void)verbose;
133
134 print_clock_header();
Amit Arora728e0c92010-09-14 12:06:09 +0530135
Amit Arora031263a2010-11-09 11:12:41 +0530136 for (i = 0; i < clocks_info->num_children; i++)
Amit Aroraac4e8652010-11-09 11:16:53 +0530137 add_clock_details_recur(clocks_info->children[i],
138 hrow, selected);
Amit Arora031263a2010-11-09 11:12:41 +0530139
Amit Arora3bc8c922010-11-16 11:27:38 +0530140 delta = calc_delta_screen_size(hrow);
141
142 while (clock_lines[count + delta] &&
143 strcmp(clock_lines[count + delta], "")) {
144 if (count < delta) {
145 count++;
146 continue;
147 }
148 print_one_clock(count - delta, clock_lines[count + delta],
149 bold[count + delta], (hrow == (count + delta)));
Amit Arora031263a2010-11-09 11:12:41 +0530150 count++;
151 }
152
Amit Aroraac4e8652010-11-09 11:16:53 +0530153 old_clock_line_no = clock_line_no;
Amit Arora031263a2010-11-09 11:12:41 +0530154 clock_line_no = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530155}
156
Amit Aroraac4e8652010-11-09 11:16:53 +0530157void prepare_name_str(char *namestr, struct clock_info *clock)
158{
159 int i;
160
161 strcpy(namestr, "");
162 if (clock->level > 1)
163 for (i = 0; i < (clock->level - 1); i++)
164 strcat(namestr, " ");
165 strcat(namestr, clock->name);
166}
167
168void add_clock_details_recur(struct clock_info *clock, int hrow, int selected)
Amit Arora031263a2010-11-09 11:12:41 +0530169{
170 int i;
171 char *unit = " Hz";
172 char rate_str[64];
Amit Aroraac4e8652010-11-09 11:16:53 +0530173 char name_str[256];
Amit Arora031263a2010-11-09 11:12:41 +0530174 double drate = (double)clock->rate;
175
176 if (drate > 1000 && drate < 1000000) {
177 unit = "KHz";
178 drate /= 1000;
179 }
180 if (drate > 1000000) {
181 unit = "MHz";
182 drate /= 1000000;
183 }
184 if (clock->usecount)
185 bold[clock_line_no] = 1;
186 else
187 bold[clock_line_no] = 0;
188
189 sprintf(rate_str, "%.2f %s", drate, unit);
Amit Aroraac4e8652010-11-09 11:16:53 +0530190 prepare_name_str(name_str, clock);
191 sprintf(clock_lines[clock_line_no++], "%-55s %-4d %-12s %-12d %-12d",
192 name_str, clock->flags, rate_str, clock->usecount,
193 clock->num_children);
194
195 if (selected && (hrow == (clock_line_no - 1))) {
196 if (clock->expanded)
197 collapse_all_subclocks(clock);
198 else
199 clock->expanded = 1;
200 selected = 0;
201 }
Amit Arora031263a2010-11-09 11:12:41 +0530202
203 if (clock->expanded && clock->num_children)
204 for (i = 0; i < clock->num_children; i++)
Amit Aroraac4e8652010-11-09 11:16:53 +0530205 add_clock_details_recur(clock->children[i],
206 hrow, selected);
Amit Arora031263a2010-11-09 11:12:41 +0530207 strcpy(clock_lines[clock_line_no], "");
208}
209
Amit Aroraac4e8652010-11-09 11:16:53 +0530210void collapse_all_subclocks(struct clock_info *clock)
211{
212 int i;
213
214 clock->expanded = 0;
215 if (clock->num_children)
216 for (i = 0; i < clock->num_children; i++)
217 collapse_all_subclocks(clock->children[i]);
218}
219
Amit Arora031263a2010-11-09 11:12:41 +0530220void destroy_clocks_info(void)
221{
222 int i;
223
224 if (clocks_info->num_children) {
225 for (i = (clocks_info->num_children - 1); i >= 0 ; i--) {
226 destroy_clocks_info_recur(clocks_info->children[i]);
227 if (!i) {
228 free(clocks_info->children);
229 clocks_info->children = NULL;
230 }
231 }
232 }
233 free(clocks_info);
234 clocks_info = NULL;
235}
236
237void destroy_clocks_info_recur(struct clock_info *clock)
238{
239 int i;
240
241 if (clock && clock->num_children) {
242 for (i = (clock->num_children - 1); i >= 0; i--) {
243 fflush(stdin);
244 destroy_clocks_info_recur(clock->children[i]);
245 if (!i) {
Amit Arora031263a2010-11-09 11:12:41 +0530246 free(clock->children);
247 clock->children = NULL;
248 clock->num_children = 0;
249 }
250 }
251 }
Amit Arora728e0c92010-09-14 12:06:09 +0530252}
Amit Arora0e512722010-10-01 12:24:16 +0530253
Amit Aroraf4fb8102010-11-30 13:55:50 +0530254void read_and_dump_clock_info_one(char *clk)
255{
Amit Arora3bd79162010-12-01 13:51:42 +0530256 printf("\nParents for \"%s\" Clock :\n\n", clk);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530257 read_clock_info(clk_dir_path);
258 dump_all_parents(clk);
259}
260
Amit Aroraac4e8652010-11-09 11:16:53 +0530261void read_and_dump_clock_info(int verbose)
Amit Arora0e512722010-10-01 12:24:16 +0530262{
Amit Arora6e774cd2010-10-28 11:31:24 +0530263 (void)verbose;
264 printf("Clock Tree :\n");
265 printf("**********\n");
266 read_clock_info(clk_dir_path);
Amit Aroraac4e8652010-11-09 11:16:53 +0530267 dump_clock_info(clocks_info, 1, 1);
Amit Arora0e512722010-10-01 12:24:16 +0530268}
269
Amit Aroraeb6cba92010-10-25 16:03:21 +0530270void read_clock_info(char *clkpath)
Amit Arora0e512722010-10-01 12:24:16 +0530271{
Amit Arora6e774cd2010-10-28 11:31:24 +0530272 DIR *dir;
273 struct dirent *item;
274 char filename[NAME_MAX], clockname[NAME_MAX];
275 struct clock_info *child;
276 struct clock_info *cur;
Amit Arora0e512722010-10-01 12:24:16 +0530277
Amit Arora6e774cd2010-10-28 11:31:24 +0530278 dir = opendir(clkpath);
279 if (!dir)
280 return;
Amit Arora0e512722010-10-01 12:24:16 +0530281
Amit Arora6e774cd2010-10-28 11:31:24 +0530282 clocks_info = (struct clock_info *)malloc(sizeof(struct clock_info));
283 memset(clocks_info, 0, sizeof(clocks_info));
284 strcpy(clocks_info->name, "/");
Amit Aroraac4e8652010-11-09 11:16:53 +0530285 clocks_info->level = 0;
Amit Arora0e512722010-10-01 12:24:16 +0530286
Amit Arora6e774cd2010-10-28 11:31:24 +0530287 while ((item = readdir(dir))) {
288 /* skip hidden dirs except ".." */
289 if (item->d_name[0] == '.')
290 continue;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530291
Amit Arora6e774cd2010-10-28 11:31:24 +0530292 strcpy(clockname, item->d_name);
293 sprintf(filename, "%s/%s", clkpath, item->d_name);
294 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
Amit Aroraac4e8652010-11-09 11:16:53 +0530295 memset(cur, 0, sizeof(struct clock_info));
Amit Arora6e774cd2010-10-28 11:31:24 +0530296 strcpy(cur->name, clockname);
297 cur->parent = clocks_info;
Amit Arora031263a2010-11-09 11:12:41 +0530298 cur->num_children = 0;
299 cur->expanded = 0;
Amit Aroraac4e8652010-11-09 11:16:53 +0530300 cur->level = 1;
Amit Arora6e774cd2010-10-28 11:31:24 +0530301 insert_children(&clocks_info, cur);
302 child = read_clock_info_recur(filename, 2, cur);
303 }
304 closedir(dir);
Amit Aroraeb6cba92010-10-25 16:03:21 +0530305}
306
307struct clock_info *read_clock_info_recur(char *clkpath, int level,
Amit Arora6e774cd2010-10-28 11:31:24 +0530308 struct clock_info *parent)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530309{
Amit Arora6e774cd2010-10-28 11:31:24 +0530310 int ret = 0;
311 DIR *dir;
312 char filename[PATH_MAX];
313 struct dirent *item;
314 struct clock_info *cur = NULL;
315 struct stat buf;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530316
Amit Arora6e774cd2010-10-28 11:31:24 +0530317 dir = opendir(clkpath);
318 if (!dir)
319 return NULL;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530320
Amit Arora6e774cd2010-10-28 11:31:24 +0530321 while ((item = readdir(dir))) {
322 struct clock_info *child;
323 /* skip hidden dirs except ".." */
324 if (item->d_name[0] == '.' )
325 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530326
Amit Arora6e774cd2010-10-28 11:31:24 +0530327 sprintf(filename, "%s/%s", clkpath, item->d_name);
Amit Arora0e512722010-10-01 12:24:16 +0530328
Amit Arora6e774cd2010-10-28 11:31:24 +0530329 ret = stat(filename, &buf);
Amit Arora0e512722010-10-01 12:24:16 +0530330
Amit Arora6e774cd2010-10-28 11:31:24 +0530331 if (ret < 0) {
332 printf("Error doing a stat on %s\n", filename);
333 exit(1);
334 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530335
Amit Arora6e774cd2010-10-28 11:31:24 +0530336 if (S_ISREG(buf.st_mode)) {
337 if (!strcmp(item->d_name, "flags"))
338 parent->flags = get_int_from(filename);
339 if (!strcmp(item->d_name, "rate"))
340 parent->rate = get_int_from(filename);
341 if (!strcmp(item->d_name, "usecount"))
342 parent->usecount = get_int_from(filename);
343 continue;
344 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530345
Amit Arora6e774cd2010-10-28 11:31:24 +0530346 if (!S_ISDIR(buf.st_mode))
347 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530348
Amit Arora6e774cd2010-10-28 11:31:24 +0530349 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
350 memset(cur, 0, sizeof(cur));
351 strcpy(cur->name, item->d_name);
352 cur->children = NULL;
353 cur->parent = NULL;
354 cur->num_children = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530355 cur->expanded = 0;
Amit Aroraac4e8652010-11-09 11:16:53 +0530356 cur->level = level;
Amit Arora6e774cd2010-10-28 11:31:24 +0530357 child = read_clock_info_recur(filename, level + 1, cur);
Amit Arora6e774cd2010-10-28 11:31:24 +0530358 insert_children(&parent, cur);
359 cur->parent = parent;
360 }
361 closedir(dir);
Amit Aroraeb6cba92010-10-25 16:03:21 +0530362
Amit Arora6e774cd2010-10-28 11:31:24 +0530363 return cur;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530364}
365
366void insert_children(struct clock_info **parent, struct clock_info *clk)
367{
Amit Arora031263a2010-11-09 11:12:41 +0530368 if (!(*parent)->num_children || (*parent)->children == NULL) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530369 (*parent)->children = (struct clock_info **)
370 malloc(sizeof(struct clock_info *)*2);
371 (*parent)->num_children = 0;
372 } else
373 (*parent)->children = (struct clock_info **)
374 realloc((*parent)->children,
375 sizeof(struct clock_info *) *
376 ((*parent)->num_children + 2));
377 if ((*parent)->num_children > 0)
378 (*parent)->children[(*parent)->num_children - 1]->last_child
379 = 0;
380 clk->last_child = 1;
381 (*parent)->children[(*parent)->num_children] = clk;
382 (*parent)->children[(*parent)->num_children + 1] = NULL;
383 (*parent)->num_children++;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530384}
385
Amit Arora3bd79162010-12-01 13:51:42 +0530386void dump_parent(struct clock_info *clk, int line)
Amit Aroraf4fb8102010-11-30 13:55:50 +0530387{
388 char *unit = "Hz";
389 double drate;
Amit Arora3bd79162010-12-01 13:51:42 +0530390 static char spaces[64];
391 char str[256];
392 static int maxline;
393
394 if (maxline < line)
395 maxline = line;
Amit Aroraf4fb8102010-11-30 13:55:50 +0530396
397 if (clk && clk->parent)
Amit Arora3bd79162010-12-01 13:51:42 +0530398 dump_parent(clk->parent, ++line);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530399
400 drate = (double)clk->rate;
401 if (drate > 1000 && drate < 1000000) {
402 unit = "KHz";
403 drate /= 1000;
404 }
405 if (drate > 1000000) {
406 unit = "MHz";
407 drate /= 1000000;
408 }
409 if (clk == clocks_info) {
Amit Arora3bd79162010-12-01 13:51:42 +0530410 line++;
Amit Aroraf4fb8102010-11-30 13:55:50 +0530411 strcpy(spaces, "");
Amit Arora3bd79162010-12-01 13:51:42 +0530412 sprintf(str, "%s%s (flags:%d,usecount:%d,rate:%5.2f %s)\n",
413 spaces, clk->name, clk->flags, clk->usecount, drate,
414 unit);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530415 } else {
416 if (!(clk->parent == clocks_info))
417 strcat(spaces, " ");
Amit Arora3bd79162010-12-01 13:51:42 +0530418 sprintf(str, "%s`- %s (flags:%d,usecount:%d,rate:%5.2f %s)\n",
419 spaces, clk->name, clk->flags, clk->usecount, drate,
420 unit);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530421 }
Amit Arora3bd79162010-12-01 13:51:42 +0530422 if (dump)
423 //printf("line=%d:m%d:l%d %s", maxline - line + 2, maxline, line, str);
424 printf("%s", str);
425 else
426 print_one_clock(maxline - line + 2, str, 1, 0);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530427}
428
429void dump_all_parents(char *clkarg)
430{
431 struct clock_info *clk;
432 char spaces[1024];
433
434 strcpy(spaces, "");
435
436 clk = find_clock(clocks_info, clkarg);
437
438 if (!clk)
439 printf("Clock NOT found!\n");
440 else {
441// while(clk && clk != clocks_info) {
442// printf("%s\n", clk->name);
443// strcat(spaces, " ");
444// clk = clk->parent;
445// printf("%s <-- ", spaces);
446// }
447// printf(" /\n");
Amit Arora3bd79162010-12-01 13:51:42 +0530448 dump_parent(clk, 1);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530449 }
450}
451
452struct clock_info *find_clock(struct clock_info *clk, char *clkarg)
453{
454 int i;
455 struct clock_info *ret = clk;
456
457 if (!strcmp(clk->name, clkarg))
458 return ret;
459
460 if (clk->children) {
461 for (i = 0; i < clk->num_children; i++) {
462 if (!strcmp(clk->children[i]->name, clkarg))
463 return clk->children[i];
464 }
465 for (i = 0; i < clk->num_children; i++) {
466 ret = find_clock(clk->children[i], clkarg);
467 if (ret)
468 return ret;
469 }
470 }
471
472 return NULL;
473}
474
Amit Aroraeb6cba92010-10-25 16:03:21 +0530475
Amit Aroraac4e8652010-11-09 11:16:53 +0530476void dump_clock_info(struct clock_info *clk, int level, int bmp)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530477{
Amit Arora6e774cd2010-10-28 11:31:24 +0530478 int i, j;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530479
Amit Arora6e774cd2010-10-28 11:31:24 +0530480 if (!clk)
481 return;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530482
Amit Arora6e774cd2010-10-28 11:31:24 +0530483 for (i = 1, j = 0; i < level; i++, j = (i - 1)) {
484 if (i == (level - 1)) {
485 if (clk->last_child)
486 printf("`-- ");
487 else
488 printf("|-- ");
489 } else {
490 if ((1<<j) & bmp)
491 printf("| ");
492 else
493 printf(" ");
494 }
495 }
Amit Arora031263a2010-11-09 11:12:41 +0530496
Amit Arora6e774cd2010-10-28 11:31:24 +0530497 if (clk == clocks_info)
498 printf("%s\n", clk->name);
499 else {
500 char *unit = "Hz";
501 double drate = (double)clk->rate;
502
503 if (drate > 1000 && drate < 1000000) {
504 unit = "KHz";
505 drate /= 1000;
506 }
507 if (drate > 1000000) {
508 unit = "MHz";
509 drate /= 1000000;
510 }
511 printf("%s (flags:%d,usecount:%d,rate:%5.2f %s)\n",
512 clk->name, clk->flags, clk->usecount, drate, unit);
Amit Arora6e774cd2010-10-28 11:31:24 +0530513 }
514 if (clk->children) {
515 int tbmp = bmp;
516 int xbmp = -1;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530517
Amit Arora6e774cd2010-10-28 11:31:24 +0530518 if (clk->last_child) {
519 xbmp ^= 1 << (level - 2);
520
521 xbmp = tbmp & xbmp;
522 } else
523 xbmp = bmp;
524 for (i = 0; i < clk->num_children; i++) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530525 tbmp = xbmp | (1 << level);
Amit Aroraac4e8652010-11-09 11:16:53 +0530526 dump_clock_info(clk->children[i], level + 1, tbmp);
Amit Arora6e774cd2010-10-28 11:31:24 +0530527 }
528 }
Amit Arora0e512722010-10-01 12:24:16 +0530529}
Amit Aroraed3e5652010-10-27 12:02:53 +0530530
531char *debugfs_locate_mpoint(void)
532{
533 int ret;
534 FILE *filep;
535 char **path;
536 char fsname[64];
537 struct statfs sfs;
538
539 path = likely_mpoints;
540 while (*path) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530541 ret = statfs(*path, &sfs);
542 if (ret >= 0 && sfs.f_type == (long)DEBUGFS_MAGIC)
Amit Aroraed3e5652010-10-27 12:02:53 +0530543 return *path;
544 path++;
545 }
546
547 filep = fopen("/proc/mounts", "r");
548 if (filep == NULL) {
549 fprintf(stderr, "powerdebug: Error opening /proc/mounts.");
Amit Arora6e774cd2010-10-28 11:31:24 +0530550 exit(1);
551 }
Amit Aroraed3e5652010-10-27 12:02:53 +0530552
553 while (fscanf(filep, "%*s %s %s %*s %*d %*d\n",
554 debugfs_mntpoint, fsname) == 2)
555 if (!strcmp(fsname, "debugfs"))
556 break;
557 fclose(filep);
558
559 if (strcmp(fsname, "debugfs"))
560 return NULL;
561
562 return debugfs_mntpoint;
563}