blob: c83055f37ceb75ae67b1b4f0b4d78bed6c6b67db [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>
18
Amit Arora728e0c92010-09-14 12:06:09 +053019#include "powerdebug.h"
Amit Aroraed3e5652010-10-27 12:02:53 +053020#include "clocks.h"
Amit Arora24ed7d12010-09-14 12:12:58 +053021
Amit Arora24ed7d12010-09-14 12:12:58 +053022static char clk_dir_path[PATH_MAX];
Amit Aroraac4e8652010-11-09 11:16:53 +053023static int bold[MAX_LINES];
Amit Arora24ed7d12010-09-14 12:12:58 +053024
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010025static int locate_debugfs(char *clk_path)
26{
27 const char *mtab = "/proc/mounts";
28 struct mntent *mntent;
29 int ret = -1;
30 FILE *file = NULL;
31
32 file = setmntent(mtab, "r");
33 if (!file)
34 return -1;
35
36 while ((mntent = getmntent(file))) {
37
38 if (strcmp(mntent->mnt_type, "debugfs"))
39 continue;
40
41 strcpy(clk_path, mntent->mnt_dir);
42 ret = 0;
43 break;
44 }
45
46 fclose(file);
47 return ret;
48}
49
Daniel Lezcanof0e06652011-03-26 22:06:19 +010050int clock_init(void)
Amit Arora24ed7d12010-09-14 12:12:58 +053051{
Daniel Lezcanof0e06652011-03-26 22:06:19 +010052 if (locate_debugfs(clk_dir_path))
53 return -1;
Daniel Lezcano9dc3fb32011-03-26 22:06:08 +010054
Amit Arora6e774cd2010-10-28 11:31:24 +053055 sprintf(clk_dir_path, "%s/clock", clk_dir_path);
Daniel Lezcanoc5a65bf2011-03-26 22:06:11 +010056
Daniel Lezcanof0e06652011-03-26 22:06:19 +010057 return access(clk_dir_path, F_OK);
Amit Arora24ed7d12010-09-14 12:12:58 +053058}
Amit Arora728e0c92010-09-14 12:06:09 +053059
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010060static int file_read_from_format(char *file, int *value, const char *format)
Amit Arora728e0c92010-09-14 12:06:09 +053061{
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010062 FILE *f;
Amit Arora6e774cd2010-10-28 11:31:24 +053063 int ret;
Amit Arora728e0c92010-09-14 12:06:09 +053064
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010065 f = fopen(file, "r");
66 if (!f)
67 return -1;
68 ret = fscanf(f, format, value);
69 fclose(f);
Amit Arora728e0c92010-09-14 12:06:09 +053070
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010071 return !ret ? -1 : 0;
72}
Amit Arora728e0c92010-09-14 12:06:09 +053073
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010074static inline int file_read_int(char *file, int *value)
75{
76 return file_read_from_format(file, value, "%d");
77}
Amit Arora728e0c92010-09-14 12:06:09 +053078
Daniel Lezcano2d19ae82011-03-26 22:06:09 +010079static inline int file_read_hex(char *file, int *value)
80{
81 return file_read_from_format(file, value, "%x");
Amit Arora728e0c92010-09-14 12:06:09 +053082}
83
Daniel Lezcanoc6718332011-03-23 14:37:39 +010084static void dump_parent(struct clock_info *clk, int line, bool dump)
85{
86 char *unit = "Hz";
87 double drate;
88 static char spaces[64];
89 char str[256];
90 static int maxline;
91
92 if (maxline < line)
93 maxline = line;
94
95 if (clk && clk->parent)
96 dump_parent(clk->parent, ++line, dump);
97
98 drate = (double)clk->rate;
99 if (drate > 1000 && drate < 1000000) {
100 unit = "KHz";
101 drate /= 1000;
102 }
103 if (drate > 1000000) {
104 unit = "MHz";
105 drate /= 1000000;
106 }
107 if (clk == clocks_info) {
108 line++;
109 strcpy(spaces, "");
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100110 sprintf(str, "%s%s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100111 spaces, clk->name, clk->flags, clk->usecount, drate,
112 unit);
113 } else {
114 if (!(clk->parent == clocks_info))
115 strcat(spaces, " ");
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100116 sprintf(str, "%s`- %s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100117 spaces, clk->name, clk->flags, clk->usecount, drate,
118 unit);
119 }
120 if (dump)
121 //printf("line=%d:m%d:l%d %s", maxline - line + 2, maxline, line, str);
122 printf("%s", str);
123 else
124 print_one_clock(maxline - line + 2, str, 1, 0);
125}
126
127static void dump_all_parents(char *clkarg, bool dump)
128{
129 struct clock_info *clk;
130 char spaces[1024];
131
132 strcpy(spaces, "");
133
134 clk = find_clock(clocks_info, clkarg);
135
136 if (!clk)
137 printf("Clock NOT found!\n");
138 else {
139 /* while(clk && clk != clocks_info) { */
140 /* printf("%s\n", clk->name); */
141 /* strcat(spaces, " "); */
142 /* clk = clk->parent; */
143 /* printf("%s <-- ", spaces); */
144 /* } */
145 /* printf(" /\n"); */
146 dump_parent(clk, 1, dump);
147 }
148}
149
Daniel Lezcano897f7332011-03-26 22:06:06 +0100150void find_parents_for_clock(char *clkname, int complete)
Amit Arora3bd79162010-12-01 13:51:42 +0530151{
152 char name[256];
153
154 name[0] = '\0';
155 if (!complete) {
156 char str[256];
157
158 strcat(name, clkname);
159 sprintf(str, "Enter Clock Name : %s\n", name);
160 print_one_clock(2, str, 1, 0);
161 return;
162 }
163 sprintf(name, "Parents for \"%s\" Clock : \n", clkname);
164 print_one_clock(0, name, 1, 1);
Daniel Lezcano897f7332011-03-26 22:06:06 +0100165 dump_all_parents(clkname, false);
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600166}
Amit Arora3bd79162010-12-01 13:51:42 +0530167
Amit Arora24ed7d12010-09-14 12:12:58 +0530168int read_and_print_clock_info(int verbose, int hrow, int selected)
169{
Amit Arora3bd79162010-12-01 13:51:42 +0530170 print_one_clock(0, "Reading Clock Tree ...", 1, 1);
Amit Aroraa06a7302010-12-02 15:59:37 +0530171
172 if (!old_clock_line_no || selected == REFRESH_WINDOW) {
173 destroy_clocks_info();
Amit Aroraac4e8652010-11-09 11:16:53 +0530174 read_clock_info(clk_dir_path);
Amit Aroraa06a7302010-12-02 15:59:37 +0530175 }
Amit Arora29cb7572010-10-05 17:40:29 +0530176
Amit Arora031263a2010-11-09 11:12:41 +0530177 if (!clocks_info->num_children) {
178 fprintf(stderr, "powerdebug: No clocks found. Exiting..\n");
179 exit(1);
Amit Arora6e774cd2010-10-28 11:31:24 +0530180 }
Amit Arora728e0c92010-09-14 12:06:09 +0530181
Amit Aroraa06a7302010-12-02 15:59:37 +0530182 if (selected == CLOCK_SELECTED)
183 selected = 1;
184 else
185 selected = 0;
186
Amit Aroraac4e8652010-11-09 11:16:53 +0530187 print_clock_info(verbose, hrow, selected);
Amit Aroraac4e8652010-11-09 11:16:53 +0530188 hrow = (hrow < old_clock_line_no) ? hrow : old_clock_line_no - 1;
189
190 return hrow;
191}
192
Amit Arora3bc8c922010-11-16 11:27:38 +0530193int calc_delta_screen_size(int hrow)
194{
Amit Arora51d1b9c2010-11-30 13:55:15 +0530195 if (hrow >= (maxy - 3))
196 return hrow - (maxy - 4);
Amit Arora3bc8c922010-11-16 11:27:38 +0530197
198 return 0;
199}
200
Amit Aroraac4e8652010-11-09 11:16:53 +0530201void print_clock_info(int verbose, int hrow, int selected)
202{
Amit Arora3bc8c922010-11-16 11:27:38 +0530203 int i, count = 0, delta;
Amit Aroraac4e8652010-11-09 11:16:53 +0530204
205 (void)verbose;
206
207 print_clock_header();
Amit Arora728e0c92010-09-14 12:06:09 +0530208
Amit Arora031263a2010-11-09 11:12:41 +0530209 for (i = 0; i < clocks_info->num_children; i++)
Amit Aroraac4e8652010-11-09 11:16:53 +0530210 add_clock_details_recur(clocks_info->children[i],
211 hrow, selected);
Amit Arora031263a2010-11-09 11:12:41 +0530212
Amit Arora3bc8c922010-11-16 11:27:38 +0530213 delta = calc_delta_screen_size(hrow);
214
215 while (clock_lines[count + delta] &&
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600216 strcmp(clock_lines[count + delta], "")) {
Amit Arora3bc8c922010-11-16 11:27:38 +0530217 if (count < delta) {
218 count++;
219 continue;
220 }
221 print_one_clock(count - delta, clock_lines[count + delta],
222 bold[count + delta], (hrow == (count + delta)));
Amit Arora031263a2010-11-09 11:12:41 +0530223 count++;
224 }
225
Amit Aroraac4e8652010-11-09 11:16:53 +0530226 old_clock_line_no = clock_line_no;
Amit Arora031263a2010-11-09 11:12:41 +0530227 clock_line_no = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530228}
229
Amit Aroraac4e8652010-11-09 11:16:53 +0530230void prepare_name_str(char *namestr, struct clock_info *clock)
231{
232 int i;
233
234 strcpy(namestr, "");
235 if (clock->level > 1)
236 for (i = 0; i < (clock->level - 1); i++)
237 strcat(namestr, " ");
238 strcat(namestr, clock->name);
239}
240
241void add_clock_details_recur(struct clock_info *clock, int hrow, int selected)
Amit Arora031263a2010-11-09 11:12:41 +0530242{
243 int i;
244 char *unit = " Hz";
245 char rate_str[64];
Amit Aroraac4e8652010-11-09 11:16:53 +0530246 char name_str[256];
Amit Arora031263a2010-11-09 11:12:41 +0530247 double drate = (double)clock->rate;
248
249 if (drate > 1000 && drate < 1000000) {
250 unit = "KHz";
251 drate /= 1000;
252 }
253 if (drate > 1000000) {
254 unit = "MHz";
255 drate /= 1000000;
256 }
257 if (clock->usecount)
258 bold[clock_line_no] = 1;
259 else
260 bold[clock_line_no] = 0;
261
262 sprintf(rate_str, "%.2f %s", drate, unit);
Amit Aroraac4e8652010-11-09 11:16:53 +0530263 prepare_name_str(name_str, clock);
264 sprintf(clock_lines[clock_line_no++], "%-55s %-4d %-12s %-12d %-12d",
265 name_str, clock->flags, rate_str, clock->usecount,
266 clock->num_children);
267
268 if (selected && (hrow == (clock_line_no - 1))) {
269 if (clock->expanded)
270 collapse_all_subclocks(clock);
271 else
272 clock->expanded = 1;
273 selected = 0;
274 }
Amit Arora031263a2010-11-09 11:12:41 +0530275
276 if (clock->expanded && clock->num_children)
277 for (i = 0; i < clock->num_children; i++)
Amit Aroraac4e8652010-11-09 11:16:53 +0530278 add_clock_details_recur(clock->children[i],
279 hrow, selected);
Amit Arora031263a2010-11-09 11:12:41 +0530280 strcpy(clock_lines[clock_line_no], "");
281}
282
Amit Aroraac4e8652010-11-09 11:16:53 +0530283void collapse_all_subclocks(struct clock_info *clock)
284{
285 int i;
286
287 clock->expanded = 0;
288 if (clock->num_children)
289 for (i = 0; i < clock->num_children; i++)
290 collapse_all_subclocks(clock->children[i]);
291}
292
Amit Arora031263a2010-11-09 11:12:41 +0530293void destroy_clocks_info(void)
294{
295 int i;
296
Amit Aroraa06a7302010-12-02 15:59:37 +0530297 if (!clocks_info)
298 return;
299
Amit Arora031263a2010-11-09 11:12:41 +0530300 if (clocks_info->num_children) {
301 for (i = (clocks_info->num_children - 1); i >= 0 ; i--) {
302 destroy_clocks_info_recur(clocks_info->children[i]);
303 if (!i) {
304 free(clocks_info->children);
305 clocks_info->children = NULL;
306 }
307 }
308 }
Amit Aroraa06a7302010-12-02 15:59:37 +0530309 clocks_info->num_children = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530310 free(clocks_info);
311 clocks_info = NULL;
312}
313
314void destroy_clocks_info_recur(struct clock_info *clock)
315{
316 int i;
317
318 if (clock && clock->num_children) {
319 for (i = (clock->num_children - 1); i >= 0; i--) {
320 fflush(stdin);
321 destroy_clocks_info_recur(clock->children[i]);
322 if (!i) {
Amit Arora031263a2010-11-09 11:12:41 +0530323 free(clock->children);
324 clock->children = NULL;
325 clock->num_children = 0;
326 }
327 }
328 }
Amit Arora728e0c92010-09-14 12:06:09 +0530329}
Amit Arora0e512722010-10-01 12:24:16 +0530330
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100331void read_and_dump_clock_info_one(char *clk, bool dump)
Amit Aroraf4fb8102010-11-30 13:55:50 +0530332{
Amit Arora3bd79162010-12-01 13:51:42 +0530333 printf("\nParents for \"%s\" Clock :\n\n", clk);
Amit Aroraf4fb8102010-11-30 13:55:50 +0530334 read_clock_info(clk_dir_path);
Daniel Lezcanoc6718332011-03-23 14:37:39 +0100335 dump_all_parents(clk, dump);
Amit Arora422c52f2010-12-02 16:22:29 +0530336 printf("\n\n");
Amit Aroraf4fb8102010-11-30 13:55:50 +0530337}
338
Amit Aroraac4e8652010-11-09 11:16:53 +0530339void read_and_dump_clock_info(int verbose)
Amit Arora0e512722010-10-01 12:24:16 +0530340{
Amit Arora6e774cd2010-10-28 11:31:24 +0530341 (void)verbose;
Amit Arora422c52f2010-12-02 16:22:29 +0530342 printf("\nClock Tree :\n");
Amit Arora6e774cd2010-10-28 11:31:24 +0530343 printf("**********\n");
344 read_clock_info(clk_dir_path);
Amit Aroraac4e8652010-11-09 11:16:53 +0530345 dump_clock_info(clocks_info, 1, 1);
Amit Arora422c52f2010-12-02 16:22:29 +0530346 printf("\n\n");
Amit Arora0e512722010-10-01 12:24:16 +0530347}
348
Amit Aroraeb6cba92010-10-25 16:03:21 +0530349void read_clock_info(char *clkpath)
Amit Arora0e512722010-10-01 12:24:16 +0530350{
Amit Arora6e774cd2010-10-28 11:31:24 +0530351 DIR *dir;
352 struct dirent *item;
353 char filename[NAME_MAX], clockname[NAME_MAX];
354 struct clock_info *child;
355 struct clock_info *cur;
Amit Arora0e512722010-10-01 12:24:16 +0530356
Amit Arora6e774cd2010-10-28 11:31:24 +0530357 dir = opendir(clkpath);
358 if (!dir)
359 return;
Amit Arora0e512722010-10-01 12:24:16 +0530360
Amit Arora6e774cd2010-10-28 11:31:24 +0530361 clocks_info = (struct clock_info *)malloc(sizeof(struct clock_info));
362 memset(clocks_info, 0, sizeof(clocks_info));
363 strcpy(clocks_info->name, "/");
Amit Aroraac4e8652010-11-09 11:16:53 +0530364 clocks_info->level = 0;
Amit Arora0e512722010-10-01 12:24:16 +0530365
Amit Arora6e774cd2010-10-28 11:31:24 +0530366 while ((item = readdir(dir))) {
367 /* skip hidden dirs except ".." */
368 if (item->d_name[0] == '.')
369 continue;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530370
Amit Arora6e774cd2010-10-28 11:31:24 +0530371 strcpy(clockname, item->d_name);
372 sprintf(filename, "%s/%s", clkpath, item->d_name);
373 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
Amit Aroraac4e8652010-11-09 11:16:53 +0530374 memset(cur, 0, sizeof(struct clock_info));
Amit Arora6e774cd2010-10-28 11:31:24 +0530375 strcpy(cur->name, clockname);
376 cur->parent = clocks_info;
Amit Arora031263a2010-11-09 11:12:41 +0530377 cur->num_children = 0;
378 cur->expanded = 0;
Amit Aroraac4e8652010-11-09 11:16:53 +0530379 cur->level = 1;
Amit Arora6e774cd2010-10-28 11:31:24 +0530380 insert_children(&clocks_info, cur);
381 child = read_clock_info_recur(filename, 2, cur);
382 }
383 closedir(dir);
Amit Aroraeb6cba92010-10-25 16:03:21 +0530384}
385
386struct clock_info *read_clock_info_recur(char *clkpath, int level,
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600387 struct clock_info *parent)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530388{
Amit Arora6e774cd2010-10-28 11:31:24 +0530389 int ret = 0;
390 DIR *dir;
391 char filename[PATH_MAX];
392 struct dirent *item;
393 struct clock_info *cur = NULL;
394 struct stat buf;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530395
Amit Arora6e774cd2010-10-28 11:31:24 +0530396 dir = opendir(clkpath);
397 if (!dir)
398 return NULL;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530399
Amit Arora6e774cd2010-10-28 11:31:24 +0530400 while ((item = readdir(dir))) {
401 struct clock_info *child;
402 /* skip hidden dirs except ".." */
403 if (item->d_name[0] == '.' )
404 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530405
Amit Arora6e774cd2010-10-28 11:31:24 +0530406 sprintf(filename, "%s/%s", clkpath, item->d_name);
Amit Arora0e512722010-10-01 12:24:16 +0530407
Amit Arora6e774cd2010-10-28 11:31:24 +0530408 ret = stat(filename, &buf);
Amit Arora0e512722010-10-01 12:24:16 +0530409
Amit Arora6e774cd2010-10-28 11:31:24 +0530410 if (ret < 0) {
411 printf("Error doing a stat on %s\n", filename);
412 exit(1);
413 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530414
Amit Arora6e774cd2010-10-28 11:31:24 +0530415 if (S_ISREG(buf.st_mode)) {
416 if (!strcmp(item->d_name, "flags"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100417 file_read_hex(filename, &parent->flags);
Amit Arora6e774cd2010-10-28 11:31:24 +0530418 if (!strcmp(item->d_name, "rate"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100419 file_read_int(filename, &parent->rate);
Amit Arora6e774cd2010-10-28 11:31:24 +0530420 if (!strcmp(item->d_name, "usecount"))
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100421 file_read_int(filename, &parent->usecount);
Amit Arora6e774cd2010-10-28 11:31:24 +0530422 continue;
423 }
Amit Aroraeb6cba92010-10-25 16:03:21 +0530424
Amit Arora6e774cd2010-10-28 11:31:24 +0530425 if (!S_ISDIR(buf.st_mode))
426 continue;
Amit Arora0e512722010-10-01 12:24:16 +0530427
Amit Arora6e774cd2010-10-28 11:31:24 +0530428 cur = (struct clock_info *)malloc(sizeof(struct clock_info));
429 memset(cur, 0, sizeof(cur));
430 strcpy(cur->name, item->d_name);
431 cur->children = NULL;
432 cur->parent = NULL;
433 cur->num_children = 0;
Amit Arora031263a2010-11-09 11:12:41 +0530434 cur->expanded = 0;
Amit Aroraac4e8652010-11-09 11:16:53 +0530435 cur->level = level;
Amit Arora6e774cd2010-10-28 11:31:24 +0530436 child = read_clock_info_recur(filename, level + 1, cur);
Amit Arora6e774cd2010-10-28 11:31:24 +0530437 insert_children(&parent, cur);
438 cur->parent = parent;
439 }
440 closedir(dir);
Amit Aroraeb6cba92010-10-25 16:03:21 +0530441
Amit Arora6e774cd2010-10-28 11:31:24 +0530442 return cur;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530443}
444
445void insert_children(struct clock_info **parent, struct clock_info *clk)
446{
Amit Arora031263a2010-11-09 11:12:41 +0530447 if (!(*parent)->num_children || (*parent)->children == NULL) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530448 (*parent)->children = (struct clock_info **)
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600449 malloc(sizeof(struct clock_info *)*2);
Amit Arora6e774cd2010-10-28 11:31:24 +0530450 (*parent)->num_children = 0;
451 } else
452 (*parent)->children = (struct clock_info **)
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600453 realloc((*parent)->children,
454 sizeof(struct clock_info *) *
455 ((*parent)->num_children + 2));
Amit Arora6e774cd2010-10-28 11:31:24 +0530456 if ((*parent)->num_children > 0)
457 (*parent)->children[(*parent)->num_children - 1]->last_child
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600458 = 0;
Amit Arora6e774cd2010-10-28 11:31:24 +0530459 clk->last_child = 1;
460 (*parent)->children[(*parent)->num_children] = clk;
461 (*parent)->children[(*parent)->num_children + 1] = NULL;
462 (*parent)->num_children++;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530463}
464
Amit Aroraf4fb8102010-11-30 13:55:50 +0530465struct clock_info *find_clock(struct clock_info *clk, char *clkarg)
466{
467 int i;
468 struct clock_info *ret = clk;
469
470 if (!strcmp(clk->name, clkarg))
471 return ret;
472
473 if (clk->children) {
474 for (i = 0; i < clk->num_children; i++) {
475 if (!strcmp(clk->children[i]->name, clkarg))
476 return clk->children[i];
477 }
478 for (i = 0; i < clk->num_children; i++) {
479 ret = find_clock(clk->children[i], clkarg);
480 if (ret)
481 return ret;
482 }
483 }
484
485 return NULL;
486}
487
Amit Aroraeb6cba92010-10-25 16:03:21 +0530488
Amit Aroraac4e8652010-11-09 11:16:53 +0530489void dump_clock_info(struct clock_info *clk, int level, int bmp)
Amit Aroraeb6cba92010-10-25 16:03:21 +0530490{
Amit Arora6e774cd2010-10-28 11:31:24 +0530491 int i, j;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530492
Amit Arora6e774cd2010-10-28 11:31:24 +0530493 if (!clk)
494 return;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530495
Amit Arora6e774cd2010-10-28 11:31:24 +0530496 for (i = 1, j = 0; i < level; i++, j = (i - 1)) {
497 if (i == (level - 1)) {
498 if (clk->last_child)
499 printf("`-- ");
500 else
501 printf("|-- ");
502 } else {
503 if ((1<<j) & bmp)
504 printf("| ");
505 else
506 printf(" ");
507 }
508 }
Amit Arora031263a2010-11-09 11:12:41 +0530509
Amit Arora6e774cd2010-10-28 11:31:24 +0530510 if (clk == clocks_info)
511 printf("%s\n", clk->name);
512 else {
513 char *unit = "Hz";
514 double drate = (double)clk->rate;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600515
Amit Arora6e774cd2010-10-28 11:31:24 +0530516 if (drate > 1000 && drate < 1000000) {
517 unit = "KHz";
518 drate /= 1000;
519 }
520 if (drate > 1000000) {
521 unit = "MHz";
522 drate /= 1000000;
523 }
Daniel Lezcano2d19ae82011-03-26 22:06:09 +0100524 printf("%s (flags:0x%x,usecount:%d,rate:%5.2f %s)\n",
Amit Arora6e774cd2010-10-28 11:31:24 +0530525 clk->name, clk->flags, clk->usecount, drate, unit);
Amit Arora6e774cd2010-10-28 11:31:24 +0530526 }
527 if (clk->children) {
528 int tbmp = bmp;
529 int xbmp = -1;
Amit Aroraeb6cba92010-10-25 16:03:21 +0530530
Amit Arora6e774cd2010-10-28 11:31:24 +0530531 if (clk->last_child) {
532 xbmp ^= 1 << (level - 2);
533
534 xbmp = tbmp & xbmp;
535 } else
536 xbmp = bmp;
537 for (i = 0; i < clk->num_children; i++) {
Amit Arora6e774cd2010-10-28 11:31:24 +0530538 tbmp = xbmp | (1 << level);
Amit Aroraac4e8652010-11-09 11:16:53 +0530539 dump_clock_info(clk->children[i], level + 1, tbmp);
Amit Arora6e774cd2010-10-28 11:31:24 +0530540 }
541 }
Amit Arora0e512722010-10-01 12:24:16 +0530542}