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