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" |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 29 | #include "display.h" |
Amit Arora | ed3e565 | 2010-10-27 12:02:53 +0530 | [diff] [blame] | 30 | #include "clocks.h" |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 31 | #include "tree.h" |
Daniel Lezcano | 88b38e3 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 32 | #include "utils.h" |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 33 | |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 34 | struct clock_info { |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 35 | int flags; |
| 36 | int rate; |
| 37 | int usecount; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 38 | bool expanded; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 39 | char *prefix; |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 40 | } *clocks_info; |
| 41 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 42 | static struct tree *clock_tree = NULL; |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 43 | |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 44 | static 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 Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 69 | static struct clock_info *clock_alloc(void) |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 70 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 71 | struct clock_info *ci; |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 72 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 73 | ci = malloc(sizeof(*ci)); |
| 74 | if (ci) |
| 75 | memset(ci, 0, sizeof(*ci)); |
Daniel Lezcano | c5a65bf | 2011-03-26 22:06:11 +0100 | [diff] [blame] | 76 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 77 | return ci; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 78 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 79 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 80 | static inline const char *clock_rate(int *rate) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 81 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 82 | int r; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 83 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 84 | /* GHZ */ |
| 85 | r = *rate >> 30; |
| 86 | if (r) { |
| 87 | *rate = r; |
| 88 | return "GHZ"; |
| 89 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 90 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 91 | /* MHZ */ |
| 92 | r = *rate >> 20; |
| 93 | if (r) { |
| 94 | *rate = r; |
| 95 | return "MHZ"; |
| 96 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 97 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 98 | /* KHZ */ |
| 99 | r = *rate >> 10; |
| 100 | if (r) { |
| 101 | *rate = r; |
| 102 | return "KHZ"; |
| 103 | } |
| 104 | |
| 105 | return ""; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 108 | static int dump_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 109 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 110 | struct clock_info *clk = t->private; |
| 111 | struct clock_info *pclk; |
| 112 | const char *unit; |
| 113 | int ret = 0; |
| 114 | int rate = clk->rate; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 115 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 116 | if (!t->parent) { |
| 117 | printf("/\n"); |
| 118 | clk->prefix = ""; |
| 119 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 122 | pclk = t->parent->private; |
| 123 | |
| 124 | if (!clk->prefix) |
| 125 | ret = asprintf(&clk->prefix, "%s%s%s", pclk->prefix, |
| 126 | t->depth > 1 ? " ": "", t->next ? "|" : " "); |
| 127 | if (ret < 0) |
| 128 | return -1; |
| 129 | |
| 130 | unit = clock_rate(&rate); |
| 131 | |
| 132 | printf("%s%s-- %s (flags:0x%x, usecount:%d, rate: %d %s)\n", |
| 133 | clk->prefix, !t->next ? "`" : "", t->name, clk->flags, |
| 134 | clk->usecount, rate, unit); |
| 135 | |
| 136 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 139 | int dump_clock_info(void) |
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 | return tree_for_each(clock_tree, dump_clock_cb, NULL); |
| 142 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 143 | |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 144 | static int dump_all_parents(char *clkarg) |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 145 | { |
| 146 | struct tree *tree; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 147 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 148 | tree = tree_find(clock_tree, clkarg); |
| 149 | if (!tree) { |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 150 | printf("Clock NOT found!\n"); |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 151 | return -1; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 152 | } |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 153 | |
| 154 | return tree_for_each_parent(tree, dump_clock_cb, NULL); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Daniel Lezcano | 897f733 | 2011-03-26 22:06:06 +0100 | [diff] [blame] | 157 | void find_parents_for_clock(char *clkname, int complete) |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 158 | { |
| 159 | char name[256]; |
| 160 | |
| 161 | name[0] = '\0'; |
| 162 | if (!complete) { |
| 163 | char str[256]; |
| 164 | |
| 165 | strcat(name, clkname); |
| 166 | sprintf(str, "Enter Clock Name : %s\n", name); |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 167 | display_reset_cursor(CLOCK); |
| 168 | display_print_line(CLOCK, 0, str, 1, NULL); |
| 169 | display_refresh_pad(CLOCK); |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 170 | return; |
| 171 | } |
| 172 | sprintf(name, "Parents for \"%s\" Clock : \n", clkname); |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 173 | display_reset_cursor(CLOCK); |
| 174 | display_print_line(CLOCK, 0, name, 1, NULL); |
| 175 | display_refresh_pad(CLOCK); |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 176 | dump_all_parents(clkname); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 177 | } |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 178 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 179 | static inline int read_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 180 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 181 | struct clock_info *clk = t->private; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 182 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 183 | file_read_value(t->path, "flags", "%x", &clk->flags); |
| 184 | file_read_value(t->path, "rate", "%d", &clk->rate); |
| 185 | file_read_value(t->path, "usecount", "%d", &clk->usecount); |
Amit Arora | 3bc8c92 | 2010-11-16 11:27:38 +0530 | [diff] [blame] | 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 190 | static int read_clock_info(void) |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 191 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 192 | return tree_for_each(clock_tree, read_clock_cb, NULL); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 195 | static int fill_clock_cb(struct tree *t, void *data) |
| 196 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 197 | struct clock_info *clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 198 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 199 | clk = clock_alloc(); |
| 200 | if (!clk) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 201 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 202 | t->private = clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 203 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 204 | /* we skip the root node but we set it expanded for its children */ |
| 205 | if (!t->parent) { |
| 206 | clk->expanded = true; |
| 207 | return 0; |
| 208 | } |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 209 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 210 | return read_clock_cb(t, data); |
| 211 | } |
| 212 | |
| 213 | static int fill_clock_tree(void) |
| 214 | { |
| 215 | return tree_for_each(clock_tree, fill_clock_cb, NULL); |
| 216 | } |
| 217 | |
| 218 | static int is_collapsed(struct tree *t, void *data) |
| 219 | { |
| 220 | struct clock_info *clk = t->private; |
| 221 | |
| 222 | if (!clk->expanded) |
| 223 | return 1; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 228 | static char *clock_line(struct tree *t) |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 229 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 230 | struct clock_info *clk; |
| 231 | int rate; |
| 232 | const char *clkunit; |
| 233 | char *clkrate, *clkname, *clkline = NULL; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 234 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 235 | clk = t->private; |
| 236 | rate = clk->rate; |
| 237 | clkunit = clock_rate(&rate); |
| 238 | |
| 239 | if (asprintf(&clkname, "%*s%s", (t->depth - 1) * 2, "", t->name) < 0) |
| 240 | return NULL; |
| 241 | |
| 242 | if (asprintf(&clkrate, "%d%s", rate, clkunit) < 0) |
| 243 | goto free_clkname; |
| 244 | |
| 245 | if (asprintf(&clkline, "%-55s 0x%-16x %-12s %-9d %-8d", clkname, |
| 246 | clk->flags, clkrate, clk->usecount, t->nrchild) < 0) |
| 247 | goto free_clkrate; |
| 248 | |
| 249 | free_clkrate: |
| 250 | free(clkrate); |
| 251 | free_clkname: |
| 252 | free(clkname); |
| 253 | |
| 254 | return clkline; |
| 255 | } |
| 256 | |
| 257 | static int clock_print_info_cb(struct tree *t, void *data) |
| 258 | { |
| 259 | struct clock_info *clock = t->private; |
| 260 | int *line = data; |
| 261 | char *buffer; |
| 262 | |
| 263 | /* we skip the root node of the tree */ |
| 264 | if (!t->parent) |
| 265 | return 0; |
| 266 | |
| 267 | /* show the clock when *all* its parent is expanded */ |
| 268 | if (tree_for_each_parent(t->parent, is_collapsed, NULL)) |
| 269 | return 0; |
| 270 | |
| 271 | buffer = clock_line(t); |
| 272 | if (!buffer) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 273 | return -1; |
| 274 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 275 | display_print_line(CLOCK, *line, buffer, clock->usecount, t); |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 276 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 277 | (*line)++; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 278 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 279 | free(buffer); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 280 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 281 | return 0; |
| 282 | } |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 283 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 284 | static int clock_print_info(void) |
| 285 | { |
| 286 | int ret, line = 0; |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 287 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 288 | print_clock_header(); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 289 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 290 | display_reset_cursor(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 291 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 292 | ret = tree_for_each(clock_tree, clock_print_info_cb, &line); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 293 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 294 | display_refresh_pad(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 295 | |
| 296 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 299 | int clock_toggle_expanded(void) |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 300 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 301 | struct tree *t = display_get_row_data(CLOCK); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 302 | struct clock_info *clk = t->private; |
| 303 | |
| 304 | clk->expanded = !clk->expanded; |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | /* |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 310 | * Read the clock information and fill the tree with the information |
| 311 | * found in the files. Then print the result to the text based interface |
| 312 | * Return 0 on success, < 0 otherwise |
| 313 | */ |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 314 | int clock_display(void) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 315 | { |
| 316 | if (read_clock_info()) |
| 317 | return -1; |
| 318 | |
| 319 | return clock_print_info(); |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Read the clock information and fill the tree with the information |
| 324 | * found in the files. Then dump to stdout a formatted result. |
| 325 | * @clk : a name for a specific clock we want to show |
| 326 | * Return 0 on success, < 0 otherwise |
| 327 | */ |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 328 | int clock_dump(char *clk) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 329 | { |
| 330 | int ret; |
| 331 | |
| 332 | if (read_clock_info()) |
| 333 | return -1; |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 334 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 335 | if (clk) { |
| 336 | printf("\nParents for \"%s\" Clock :\n\n", clk); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 337 | ret = dump_all_parents(clk); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 338 | printf("\n\n"); |
| 339 | } else { |
| 340 | printf("\nClock Tree :\n"); |
| 341 | printf("**********\n"); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 342 | ret = dump_clock_info(); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 343 | printf("\n\n"); |
| 344 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 345 | |
| 346 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 347 | } |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 348 | |
| 349 | static struct display_ops clock_ops = { |
| 350 | .display = clock_display, |
| 351 | .select = clock_toggle_expanded, |
| 352 | }; |
| 353 | |
| 354 | /* |
| 355 | * Initialize the clock framework |
| 356 | */ |
| 357 | int clock_init(void) |
| 358 | { |
| 359 | char clk_dir_path[PATH_MAX]; |
| 360 | |
| 361 | if (display_register(CLOCK, &clock_ops)) |
| 362 | return -1; |
| 363 | |
| 364 | if (locate_debugfs(clk_dir_path)) |
| 365 | return -1; |
| 366 | |
| 367 | sprintf(clk_dir_path, "%s/clock", clk_dir_path); |
| 368 | |
| 369 | if (access(clk_dir_path, F_OK)) |
| 370 | return -1; |
| 371 | |
| 372 | clock_tree = tree_load(clk_dir_path, NULL); |
| 373 | if (!clock_tree) |
| 374 | return -1; |
| 375 | |
| 376 | return fill_clock_tree(); |
| 377 | } |