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; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 45 | int preparecount; |
| 46 | int enablecount; |
| 47 | int notifiercount; |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 48 | } *clocks_info; |
| 49 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 50 | enum clock_fw_type{ |
| 51 | CCF, /* common clock framework */ |
| 52 | OCF, /* old clock framework */ |
| 53 | MAX, |
| 54 | }; |
| 55 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 56 | static struct tree *clock_tree = NULL; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 57 | static int clock_fw; |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 58 | |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 59 | static int locate_debugfs(char *clk_path) |
| 60 | { |
Nishanth Menon | a14971b | 2011-09-20 11:31:17 +0200 | [diff] [blame] | 61 | strcpy(clk_path, "/sys/kernel/debug"); |
| 62 | return 0; |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 65 | static struct clock_info *clock_alloc(void) |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 66 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 67 | struct clock_info *ci; |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 68 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 69 | ci = malloc(sizeof(*ci)); |
| 70 | if (ci) |
| 71 | memset(ci, 0, sizeof(*ci)); |
Daniel Lezcano | c5a65bf | 2011-03-26 22:06:11 +0100 | [diff] [blame] | 72 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 73 | return ci; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 74 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 75 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 76 | static inline const char *clock_rate(int *rate) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 77 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 78 | int r; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 79 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 80 | /* GHZ */ |
| 81 | r = *rate >> 30; |
| 82 | if (r) { |
| 83 | *rate = r; |
| 84 | return "GHZ"; |
| 85 | } |
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 | /* MHZ */ |
| 88 | r = *rate >> 20; |
| 89 | if (r) { |
| 90 | *rate = r; |
| 91 | return "MHZ"; |
| 92 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 93 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 94 | /* KHZ */ |
| 95 | r = *rate >> 10; |
| 96 | if (r) { |
| 97 | *rate = r; |
| 98 | return "KHZ"; |
| 99 | } |
| 100 | |
| 101 | return ""; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 104 | static int dump_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 105 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 106 | struct clock_info *clk = t->private; |
| 107 | struct clock_info *pclk; |
| 108 | const char *unit; |
| 109 | int ret = 0; |
| 110 | int rate = clk->rate; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 111 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 112 | if (!t->parent) { |
| 113 | printf("/\n"); |
| 114 | clk->prefix = ""; |
| 115 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 118 | pclk = t->parent->private; |
| 119 | |
| 120 | if (!clk->prefix) |
| 121 | ret = asprintf(&clk->prefix, "%s%s%s", pclk->prefix, |
| 122 | t->depth > 1 ? " ": "", t->next ? "|" : " "); |
| 123 | if (ret < 0) |
| 124 | return -1; |
| 125 | |
| 126 | unit = clock_rate(&rate); |
| 127 | |
| 128 | printf("%s%s-- %s (flags:0x%x, usecount:%d, rate: %d %s)\n", |
| 129 | clk->prefix, !t->next ? "`" : "", t->name, clk->flags, |
| 130 | clk->usecount, rate, unit); |
| 131 | |
| 132 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 135 | int dump_clock_info(void) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 136 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 137 | return tree_for_each(clock_tree, dump_clock_cb, NULL); |
| 138 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 139 | |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 140 | static int dump_all_parents(char *clkarg) |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 141 | { |
| 142 | struct tree *tree; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 143 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 144 | tree = tree_find(clock_tree, clkarg); |
| 145 | if (!tree) { |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 146 | printf("Clock NOT found!\n"); |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 147 | return -1; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 148 | } |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 149 | |
| 150 | return tree_for_each_parent(tree, dump_clock_cb, NULL); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 153 | static inline int read_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 154 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 155 | struct clock_info *clk = t->private; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 156 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 157 | if(clock_fw == CCF) { |
| 158 | file_read_value(t->path, "clk_flags", "%x", &clk->flags); |
| 159 | file_read_value(t->path, "clk_rate", "%d", &clk->rate); |
| 160 | file_read_value(t->path, "clk_prepare_count", "%d", &clk->preparecount); |
| 161 | file_read_value(t->path, "clk_enable_count", "%d", &clk->enablecount); |
| 162 | file_read_value(t->path, "clk_notifier_count", "%d", &clk->notifiercount); |
| 163 | } |
| 164 | else { |
| 165 | file_read_value(t->path, "flags", "%x", &clk->flags); |
| 166 | file_read_value(t->path, "rate", "%d", &clk->rate); |
| 167 | file_read_value(t->path, "usecount", "%d", &clk->usecount); |
| 168 | } |
Amit Arora | 3bc8c92 | 2010-11-16 11:27:38 +0530 | [diff] [blame] | 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 173 | static int read_clock_info(struct tree *tree) |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 174 | { |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 175 | return tree_for_each(tree, read_clock_cb, NULL); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 178 | static int fill_clock_cb(struct tree *t, void *data) |
| 179 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 180 | struct clock_info *clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 181 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 182 | clk = clock_alloc(); |
| 183 | if (!clk) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 184 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 185 | t->private = clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 186 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 187 | /* we skip the root node but we set it expanded for its children */ |
| 188 | if (!t->parent) { |
| 189 | clk->expanded = true; |
| 190 | return 0; |
| 191 | } |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 192 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 193 | return read_clock_cb(t, data); |
| 194 | } |
| 195 | |
| 196 | static int fill_clock_tree(void) |
| 197 | { |
| 198 | return tree_for_each(clock_tree, fill_clock_cb, NULL); |
| 199 | } |
| 200 | |
| 201 | static int is_collapsed(struct tree *t, void *data) |
| 202 | { |
| 203 | struct clock_info *clk = t->private; |
| 204 | |
| 205 | if (!clk->expanded) |
| 206 | return 1; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 211 | static char *clock_line(struct tree *t) |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 212 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 213 | struct clock_info *clk; |
| 214 | int rate; |
| 215 | const char *clkunit; |
| 216 | char *clkrate, *clkname, *clkline = NULL; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 217 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 218 | clk = t->private; |
| 219 | rate = clk->rate; |
| 220 | clkunit = clock_rate(&rate); |
| 221 | |
| 222 | if (asprintf(&clkname, "%*s%s", (t->depth - 1) * 2, "", t->name) < 0) |
| 223 | return NULL; |
| 224 | |
| 225 | if (asprintf(&clkrate, "%d%s", rate, clkunit) < 0) |
| 226 | goto free_clkname; |
| 227 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 228 | if(clock_fw == CCF) { |
| 229 | if (asprintf(&clkline, "%-35s 0x%-8x %-12s %-10d %-11d %-15d %-14d %-10d", |
| 230 | clkname, clk->flags, clkrate, clk->usecount, t->nrchild, |
| 231 | clk->preparecount, clk->enablecount, clk->notifiercount) < 0) |
| 232 | goto free_clkrate; |
| 233 | } |
| 234 | else { |
| 235 | if (asprintf(&clkline, "%-55s 0x%-16x %-12s %-9d %-8d", |
| 236 | clkname, clk->flags, clkrate, clk->usecount, t->nrchild) < 0) |
| 237 | goto free_clkrate; |
| 238 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 239 | |
| 240 | free_clkrate: |
| 241 | free(clkrate); |
| 242 | free_clkname: |
| 243 | free(clkname); |
| 244 | |
| 245 | return clkline; |
| 246 | } |
| 247 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 248 | static int _clock_print_info_cb(struct tree *t, void *data) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 249 | { |
| 250 | struct clock_info *clock = t->private; |
| 251 | int *line = data; |
| 252 | char *buffer; |
| 253 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 254 | /* we skip the root node of the tree */ |
| 255 | if (!t->parent) |
| 256 | return 0; |
| 257 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 258 | buffer = clock_line(t); |
| 259 | if (!buffer) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 260 | return -1; |
| 261 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 262 | display_print_line(CLOCK, *line, buffer, clock->usecount, t); |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 263 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 264 | (*line)++; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 265 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 266 | free(buffer); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 267 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 268 | return 0; |
| 269 | } |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 270 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 271 | static int clock_print_info_cb(struct tree *t, void *data) |
| 272 | { |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 273 | /* we skip the root node of the tree */ |
| 274 | if (!t->parent) |
| 275 | return 0; |
| 276 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 277 | /* show the clock when *all* its parent is expanded */ |
| 278 | if (tree_for_each_parent(t->parent, is_collapsed, NULL)) |
| 279 | return 0; |
| 280 | |
| 281 | return _clock_print_info_cb(t, data); |
| 282 | } |
| 283 | |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 284 | static int clock_print_header(void) |
| 285 | { |
| 286 | char *buf; |
| 287 | int ret; |
| 288 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 289 | if(clock_fw == CCF) { |
| 290 | if (asprintf(&buf, "%-35s %-10s %-12s %-10s %-11s %-15s %-14s %-14s", |
| 291 | "Name", "Flags", "Rate", "Usecount", "Children", "Prepare_Count", |
| 292 | "Enable_Count", "Notifier_Count") < 0) |
| 293 | return -1; |
| 294 | } |
| 295 | else { |
| 296 | if (asprintf(&buf, "%-55s %-16s %-12s %-9s %-8s", |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 297 | "Name", "Flags", "Rate", "Usecount", "Children") < 0) |
| 298 | return -1; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 299 | } |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 300 | |
Daniel Lezcano | 372ffba | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 301 | ret = display_column_name(buf); |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 302 | |
| 303 | free(buf); |
| 304 | |
| 305 | return ret; |
| 306 | } |
| 307 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 308 | static int clock_print_info(struct tree *tree) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 309 | { |
| 310 | int ret, line = 0; |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 311 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 312 | display_reset_cursor(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 313 | |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 314 | clock_print_header(); |
| 315 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 316 | ret = tree_for_each(tree, clock_print_info_cb, &line); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 317 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 318 | display_refresh_pad(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 319 | |
| 320 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 323 | static int clock_select(void) |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 324 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 325 | struct tree *t = display_get_row_data(CLOCK); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 326 | struct clock_info *clk = t->private; |
| 327 | |
| 328 | clk->expanded = !clk->expanded; |
| 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 334 | * Read the clock information and fill the tree with the information |
| 335 | * found in the files. Then print the result to the text based interface |
| 336 | * Return 0 on success, < 0 otherwise |
| 337 | */ |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 338 | static int clock_display(bool refresh) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 339 | { |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 340 | if (refresh && read_clock_info(clock_tree)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 341 | return -1; |
| 342 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 343 | return clock_print_info(clock_tree); |
| 344 | } |
| 345 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 346 | static int clock_find(const char *name) |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 347 | { |
| 348 | struct tree **ptree = NULL; |
| 349 | int i, nr, line = 0, ret = 0; |
| 350 | |
| 351 | nr = tree_finds(clock_tree, name, &ptree); |
| 352 | |
| 353 | display_reset_cursor(CLOCK); |
| 354 | |
| 355 | for (i = 0; i < nr; i++) { |
| 356 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 357 | ret = _clock_print_info_cb(ptree[i], &line); |
| 358 | if (ret) |
| 359 | break; |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 360 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | display_refresh_pad(CLOCK); |
| 364 | |
| 365 | free(ptree); |
| 366 | |
| 367 | return ret; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 370 | static int clock_selectf(void) |
| 371 | { |
| 372 | struct tree *t = display_get_row_data(CLOCK); |
| 373 | int line = 0; |
| 374 | |
| 375 | display_reset_cursor(CLOCK); |
| 376 | |
| 377 | if (tree_for_each_parent(t, _clock_print_info_cb, &line)) |
| 378 | return -1; |
| 379 | |
| 380 | return display_refresh_pad(CLOCK); |
| 381 | } |
| 382 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 383 | /* |
| 384 | * Read the clock information and fill the tree with the information |
| 385 | * found in the files. Then dump to stdout a formatted result. |
| 386 | * @clk : a name for a specific clock we want to show |
| 387 | * Return 0 on success, < 0 otherwise |
| 388 | */ |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 389 | int clock_dump(char *clk) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 390 | { |
| 391 | int ret; |
| 392 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 393 | if (read_clock_info(clock_tree)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 394 | return -1; |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 395 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 396 | if (clk) { |
| 397 | printf("\nParents for \"%s\" Clock :\n\n", clk); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 398 | ret = dump_all_parents(clk); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 399 | printf("\n\n"); |
| 400 | } else { |
| 401 | printf("\nClock Tree :\n"); |
| 402 | printf("**********\n"); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 403 | ret = dump_clock_info(); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 404 | printf("\n\n"); |
| 405 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 406 | |
| 407 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 408 | } |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 409 | |
| 410 | static struct display_ops clock_ops = { |
| 411 | .display = clock_display, |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 412 | .select = clock_select, |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 413 | .find = clock_find, |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 414 | .selectf = clock_selectf, |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | /* |
| 418 | * Initialize the clock framework |
| 419 | */ |
| 420 | int clock_init(void) |
| 421 | { |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 422 | char clk_dir_path[MAX+1][PATH_MAX]; |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 423 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 424 | if (locate_debugfs(clk_dir_path[CCF]) || locate_debugfs(clk_dir_path[OCF])) |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 425 | return -1; |
| 426 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 427 | sprintf(clk_dir_path[CCF], "%s/clk", clk_dir_path[CCF]); |
| 428 | sprintf(clk_dir_path[OCF], "%s/clock", clk_dir_path[OCF]); |
| 429 | if (!access(clk_dir_path[CCF], F_OK)) { |
| 430 | clock_fw = CCF; |
| 431 | strcpy(clk_dir_path[MAX],clk_dir_path[CCF]); |
| 432 | } |
| 433 | else if(!access(clk_dir_path[OCF], F_OK)) { |
| 434 | clock_fw = OCF; |
| 435 | strcpy(clk_dir_path[MAX],clk_dir_path[OCF]); |
| 436 | } |
| 437 | else |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 438 | return -1; |
| 439 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 440 | clock_tree = tree_load(clk_dir_path[MAX], NULL, false); |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 441 | if (!clock_tree) |
| 442 | return -1; |
| 443 | |
Daniel Lezcano | caafece | 2011-06-27 22:59:17 +0200 | [diff] [blame] | 444 | if (fill_clock_tree()) |
| 445 | return -1; |
| 446 | |
| 447 | return display_register(CLOCK, &clock_ops); |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 448 | } |