Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 1 | /******************************************************************************* |
Amit Kucheria | c0e17fc | 2011-01-17 09:35:52 +0200 | [diff] [blame] | 2 | * Copyright (C) 2010, Linaro Limited. |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 3 | * |
| 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 |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 14 | * |
| 15 | * Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 16 | * - Rewrote code and API |
| 17 | * |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 18 | *******************************************************************************/ |
| 19 | |
Daniel Lezcano | 141c048 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 20 | #ifndef _GNU_SOURCE |
| 21 | #define _GNU_SOURCE |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 22 | #include <stdio.h> |
Daniel Lezcano | 141c048 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 23 | #undef _GNU_SOURCE |
| 24 | #endif |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 25 | #include <mntent.h> |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 26 | #include <sys/stat.h> |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 27 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 28 | #include "powerdebug.h" |
Amit Arora | ed3e565 | 2010-10-27 12:02:53 +0530 | [diff] [blame] | 29 | #include "clocks.h" |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 30 | #include "tree.h" |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 31 | |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 32 | struct clock_info { |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 33 | int flags; |
| 34 | int rate; |
| 35 | int usecount; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 36 | bool expanded; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 37 | char *prefix; |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 38 | } *clocks_info; |
| 39 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 40 | static struct tree *clock_tree = NULL; |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 41 | |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 42 | static int locate_debugfs(char *clk_path) |
| 43 | { |
| 44 | const char *mtab = "/proc/mounts"; |
| 45 | struct mntent *mntent; |
| 46 | int ret = -1; |
| 47 | FILE *file = NULL; |
| 48 | |
| 49 | file = setmntent(mtab, "r"); |
| 50 | if (!file) |
| 51 | return -1; |
| 52 | |
| 53 | while ((mntent = getmntent(file))) { |
| 54 | |
| 55 | if (strcmp(mntent->mnt_type, "debugfs")) |
| 56 | continue; |
| 57 | |
| 58 | strcpy(clk_path, mntent->mnt_dir); |
| 59 | ret = 0; |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | fclose(file); |
| 64 | return ret; |
| 65 | } |
| 66 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 67 | static struct clock_info *clock_alloc(void) |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 68 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 69 | struct clock_info *ci; |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 70 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 71 | ci = malloc(sizeof(*ci)); |
| 72 | if (ci) |
| 73 | memset(ci, 0, sizeof(*ci)); |
Daniel Lezcano | c5a65bf | 2011-03-26 22:06:11 +0100 | [diff] [blame] | 74 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 75 | return ci; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 76 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 77 | |
Daniel Lezcano | 141c048 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 78 | /* |
| 79 | * This functions is a helper to read a specific file content and store |
| 80 | * the content inside a variable pointer passed as parameter, the format |
| 81 | * parameter gives the variable type to be read from the file. |
| 82 | * |
| 83 | * @path : directory path containing the file |
| 84 | * @name : name of the file to be read |
| 85 | * @format : the format of the format |
| 86 | * @value : a pointer to a variable to store the content of the file |
| 87 | * Returns 0 on success, -1 otherwise |
| 88 | */ |
| 89 | int file_read_value(const char *path, const char *name, |
| 90 | const char *format, void *value) |
| 91 | { |
| 92 | FILE *file; |
| 93 | char *rpath; |
| 94 | int ret; |
| 95 | |
| 96 | ret = asprintf(&rpath, "%s/%s", path, name); |
| 97 | if (ret < 0) |
| 98 | return ret; |
| 99 | |
| 100 | file = fopen(rpath, "r"); |
| 101 | if (!file) { |
| 102 | ret = -1; |
| 103 | goto out_free; |
| 104 | } |
| 105 | |
| 106 | ret = fscanf(file, format, value) == EOF ? -1 : 0; |
| 107 | |
| 108 | fclose(file); |
| 109 | out_free: |
| 110 | free(rpath); |
| 111 | return ret; |
| 112 | } |
| 113 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 114 | static int file_read_from_format(const char *file, int *value, |
| 115 | const char *format) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 116 | { |
Daniel Lezcano | 2d19ae8 | 2011-03-26 22:06:09 +0100 | [diff] [blame] | 117 | FILE *f; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 118 | int ret; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 119 | |
Daniel Lezcano | 2d19ae8 | 2011-03-26 22:06:09 +0100 | [diff] [blame] | 120 | f = fopen(file, "r"); |
| 121 | if (!f) |
| 122 | return -1; |
| 123 | ret = fscanf(f, format, value); |
| 124 | fclose(f); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 125 | |
Daniel Lezcano | 2d19ae8 | 2011-03-26 22:06:09 +0100 | [diff] [blame] | 126 | return !ret ? -1 : 0; |
| 127 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 128 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 129 | static inline int file_read_int(const char *file, int *value) |
Daniel Lezcano | 2d19ae8 | 2011-03-26 22:06:09 +0100 | [diff] [blame] | 130 | { |
| 131 | return file_read_from_format(file, value, "%d"); |
| 132 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 133 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 134 | static inline int file_read_hex(const char *file, int *value) |
Daniel Lezcano | 2d19ae8 | 2011-03-26 22:06:09 +0100 | [diff] [blame] | 135 | { |
| 136 | return file_read_from_format(file, value, "%x"); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 137 | } |
| 138 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 139 | static inline const char *clock_rate(int *rate) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 140 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 141 | int r; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 142 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 143 | /* GHZ */ |
| 144 | r = *rate >> 30; |
| 145 | if (r) { |
| 146 | *rate = r; |
| 147 | return "GHZ"; |
| 148 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 149 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 150 | /* MHZ */ |
| 151 | r = *rate >> 20; |
| 152 | if (r) { |
| 153 | *rate = r; |
| 154 | return "MHZ"; |
| 155 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 156 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 157 | /* KHZ */ |
| 158 | r = *rate >> 10; |
| 159 | if (r) { |
| 160 | *rate = r; |
| 161 | return "KHZ"; |
| 162 | } |
| 163 | |
| 164 | return ""; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 167 | static int dump_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 168 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 169 | struct clock_info *clk = t->private; |
| 170 | struct clock_info *pclk; |
| 171 | const char *unit; |
| 172 | int ret = 0; |
| 173 | int rate = clk->rate; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 174 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 175 | if (!t->parent) { |
| 176 | printf("/\n"); |
| 177 | clk->prefix = ""; |
| 178 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 181 | pclk = t->parent->private; |
| 182 | |
| 183 | if (!clk->prefix) |
| 184 | ret = asprintf(&clk->prefix, "%s%s%s", pclk->prefix, |
| 185 | t->depth > 1 ? " ": "", t->next ? "|" : " "); |
| 186 | if (ret < 0) |
| 187 | return -1; |
| 188 | |
| 189 | unit = clock_rate(&rate); |
| 190 | |
| 191 | printf("%s%s-- %s (flags:0x%x, usecount:%d, rate: %d %s)\n", |
| 192 | clk->prefix, !t->next ? "`" : "", t->name, clk->flags, |
| 193 | clk->usecount, rate, unit); |
| 194 | |
| 195 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 198 | int dump_clock_info(void) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 199 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 200 | return tree_for_each(clock_tree, dump_clock_cb, NULL); |
| 201 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 202 | |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 203 | static int dump_all_parents(char *clkarg) |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 204 | { |
| 205 | struct tree *tree; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 206 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 207 | tree = tree_find(clock_tree, clkarg); |
| 208 | if (!tree) { |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 209 | printf("Clock NOT found!\n"); |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 210 | return -1; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 211 | } |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 212 | |
| 213 | return tree_for_each_parent(tree, dump_clock_cb, NULL); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Daniel Lezcano | 897f733 | 2011-03-26 22:06:06 +0100 | [diff] [blame] | 216 | void find_parents_for_clock(char *clkname, int complete) |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 217 | { |
| 218 | char name[256]; |
| 219 | |
| 220 | name[0] = '\0'; |
| 221 | if (!complete) { |
| 222 | char str[256]; |
| 223 | |
| 224 | strcat(name, clkname); |
| 225 | sprintf(str, "Enter Clock Name : %s\n", name); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 226 | display_reset_cursor(); |
| 227 | display_print_line(0, str, 1, NULL); |
| 228 | display_refresh_pad(); |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | sprintf(name, "Parents for \"%s\" Clock : \n", clkname); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 232 | display_reset_cursor(); |
| 233 | display_print_line(0, name, 1, NULL); |
| 234 | display_refresh_pad(); |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 235 | dump_all_parents(clkname); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 236 | } |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 237 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 238 | static inline int read_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 239 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 240 | struct clock_info *clk = t->private; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 241 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 242 | file_read_value(t->path, "flags", "%x", &clk->flags); |
| 243 | file_read_value(t->path, "rate", "%d", &clk->rate); |
| 244 | file_read_value(t->path, "usecount", "%d", &clk->usecount); |
Amit Arora | 3bc8c92 | 2010-11-16 11:27:38 +0530 | [diff] [blame] | 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 249 | static int read_clock_info(void) |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 250 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 251 | return tree_for_each(clock_tree, read_clock_cb, NULL); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 254 | static int fill_clock_cb(struct tree *t, void *data) |
| 255 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 256 | struct clock_info *clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 257 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 258 | clk = clock_alloc(); |
| 259 | if (!clk) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 260 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 261 | t->private = clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 262 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 263 | /* we skip the root node but we set it expanded for its children */ |
| 264 | if (!t->parent) { |
| 265 | clk->expanded = true; |
| 266 | return 0; |
| 267 | } |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 268 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 269 | return read_clock_cb(t, data); |
| 270 | } |
| 271 | |
| 272 | static int fill_clock_tree(void) |
| 273 | { |
| 274 | return tree_for_each(clock_tree, fill_clock_cb, NULL); |
| 275 | } |
| 276 | |
| 277 | static int is_collapsed(struct tree *t, void *data) |
| 278 | { |
| 279 | struct clock_info *clk = t->private; |
| 280 | |
| 281 | if (!clk->expanded) |
| 282 | return 1; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 287 | static char *clock_line(struct tree *t) |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 288 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 289 | struct clock_info *clk; |
| 290 | int rate; |
| 291 | const char *clkunit; |
| 292 | char *clkrate, *clkname, *clkline = NULL; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 293 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 294 | clk = t->private; |
| 295 | rate = clk->rate; |
| 296 | clkunit = clock_rate(&rate); |
| 297 | |
| 298 | if (asprintf(&clkname, "%*s%s", (t->depth - 1) * 2, "", t->name) < 0) |
| 299 | return NULL; |
| 300 | |
| 301 | if (asprintf(&clkrate, "%d%s", rate, clkunit) < 0) |
| 302 | goto free_clkname; |
| 303 | |
| 304 | if (asprintf(&clkline, "%-55s 0x%-16x %-12s %-9d %-8d", clkname, |
| 305 | clk->flags, clkrate, clk->usecount, t->nrchild) < 0) |
| 306 | goto free_clkrate; |
| 307 | |
| 308 | free_clkrate: |
| 309 | free(clkrate); |
| 310 | free_clkname: |
| 311 | free(clkname); |
| 312 | |
| 313 | return clkline; |
| 314 | } |
| 315 | |
| 316 | static int clock_print_info_cb(struct tree *t, void *data) |
| 317 | { |
| 318 | struct clock_info *clock = t->private; |
| 319 | int *line = data; |
| 320 | char *buffer; |
| 321 | |
| 322 | /* we skip the root node of the tree */ |
| 323 | if (!t->parent) |
| 324 | return 0; |
| 325 | |
| 326 | /* show the clock when *all* its parent is expanded */ |
| 327 | if (tree_for_each_parent(t->parent, is_collapsed, NULL)) |
| 328 | return 0; |
| 329 | |
| 330 | buffer = clock_line(t); |
| 331 | if (!buffer) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 332 | return -1; |
| 333 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 334 | display_print_line(*line, buffer, clock->usecount, t); |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 335 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 336 | (*line)++; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 337 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 338 | free(buffer); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 339 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 340 | return 0; |
| 341 | } |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 342 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 343 | static int clock_print_info(void) |
| 344 | { |
| 345 | int ret, line = 0; |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 346 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 347 | print_clock_header(); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 348 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 349 | display_reset_cursor(); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 350 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 351 | ret = tree_for_each(clock_tree, clock_print_info_cb, &line); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 352 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 353 | display_refresh_pad(); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 354 | |
| 355 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 356 | } |
| 357 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 358 | int clock_toggle_expanded(void) |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 359 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 360 | struct tree *t = display_get_row_data(); |
| 361 | struct clock_info *clk = t->private; |
| 362 | |
| 363 | clk->expanded = !clk->expanded; |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Initialize the clock framework |
| 370 | */ |
| 371 | int clock_init(void) |
| 372 | { |
| 373 | char clk_dir_path[PATH_MAX]; |
| 374 | |
| 375 | if (locate_debugfs(clk_dir_path)) |
| 376 | return -1; |
| 377 | |
| 378 | sprintf(clk_dir_path, "%s/clock", clk_dir_path); |
| 379 | |
| 380 | if (access(clk_dir_path, F_OK)) |
| 381 | return -1; |
| 382 | |
| 383 | clock_tree = tree_load(clk_dir_path, NULL); |
| 384 | if (!clock_tree) |
| 385 | return -1; |
| 386 | |
| 387 | return fill_clock_tree(); |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Read the clock information and fill the tree with the information |
| 392 | * found in the files. Then print the result to the text based interface |
| 393 | * Return 0 on success, < 0 otherwise |
| 394 | */ |
Daniel Lezcano | 05916f8 | 2011-06-08 23:30:01 +0200 | [diff] [blame^] | 395 | int read_and_print_clock_info(void) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 396 | { |
| 397 | if (read_clock_info()) |
| 398 | return -1; |
| 399 | |
| 400 | return clock_print_info(); |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Read the clock information and fill the tree with the information |
| 405 | * found in the files. Then dump to stdout a formatted result. |
| 406 | * @clk : a name for a specific clock we want to show |
| 407 | * Return 0 on success, < 0 otherwise |
| 408 | */ |
| 409 | int read_and_dump_clock_info(char *clk) |
| 410 | { |
| 411 | int ret; |
| 412 | |
| 413 | if (read_clock_info()) |
| 414 | return -1; |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 415 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 416 | if (clk) { |
| 417 | printf("\nParents for \"%s\" Clock :\n\n", clk); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 418 | ret = dump_all_parents(clk); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 419 | printf("\n\n"); |
| 420 | } else { |
| 421 | printf("\nClock Tree :\n"); |
| 422 | printf("**********\n"); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 423 | ret = dump_clock_info(); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 424 | printf("\n\n"); |
| 425 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 426 | |
| 427 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 428 | } |